LLM Context Windows Explained: Limits, Costs and Long-Context Tricks
What a context window is, how input and output share it, why long contexts cost more and degrade attention, and techniques to work within limits.
Published December 1, 2026
The context window is the maximum number of tokens a model can consider in one request: your instructions, the conversation, any documents, tool definitions, and the output it generates. Windows have grown from a few thousand tokens to hundreds of thousands and beyond, but how you use that space still determines cost, speed and answer quality.
The concept
Input and output share the window. If a model has a 200,000-token window and you send 190,000 tokens of input, there is room for at most 10,000 tokens of output (and the API may have a separate, smaller max output limit). When conversations grow, applications must trim, summarise or drop older content to stay within limits.
Long contexts have costs beyond the limit itself. You pay for every input token on every request, latency grows with input size, and models can be less reliable at using details buried in the middle of very long inputs. Prompt caching helps with repeated prefixes (like a long system prompt or a document you ask many questions about) by billing cached tokens at a discount and reducing latency.
Budgeting the window
Working within limits
| Technique | What it does | Trade-off |
|---|---|---|
| Retrieval (RAG) | Load only relevant passages | Needs a good index |
| Summarisation / compaction | Replace old turns with summaries | Some detail lost |
| Prompt caching | Reuse a cached prefix cheaply | Prefix must stay identical |
| Map-reduce | Process chunks separately, then combine | More calls, cross-chunk links lost |
| Sub-agents | Isolate subtasks in fresh contexts | Coordination overhead |
Map-reduce for huge inputs
Practical examples
Trim history to a token budget
Keep the system prompt and the most recent turns that fit.
def fit_history(system, turns, budget, count):
kept, used = [], count(system)
for turn in reversed(turns):
t = count(turn["content"])
if used + t > budget: break
kept.append(turn); used += t
return [system] + list(reversed(kept))Cache-friendly prompt layout
Put stable content first so it can be cached; variable content last.
[system instructions] ← stable
[tool definitions] ← stable
[reference document] ← stable for this session
[conversation so far] ← grows
[new user question] ← changes every callReserve room for the answer
Always leave headroom for output.
MAX_CONTEXT = 200_000
RESERVED_OUTPUT = 8_000
input_budget = MAX_CONTEXT - RESERVED_OUTPUTCommon mistakes
- Filling the window "because it fits" and paying for irrelevant tokens on every call.
- Forgetting output needs room, causing truncated answers.
- Putting variable content before stable content, defeating prompt caching.
- Assuming the model reads every token with equal attention.
Key takeaways
- The window holds input and output together.
- Long contexts cost more and can reduce precision.
- Use retrieval, compaction, caching and map-reduce.
- Budget tokens explicitly and reserve space for output.
FAQ
Does a bigger window make a model smarter?
No. It lets the model see more at once; reasoning quality depends on the model itself and on how relevant the context is.
What happens if I exceed the window?
The API usually returns an error; some frameworks truncate silently, which can drop important instructions.
Is prompt caching automatic?
It depends on the provider. Some cache automatically, others require explicit cache markers in the request.