beginner
Context windows
The total amount of text the model can hold in its head at once. Measured in tokens.
What's actually happening
Two non-obvious points the diagram doesn't make:
- Both your input and the model's reply share the same budget. A 200k window with 199k of input leaves 1k for the reply.
- The model has no memory between requests. Anything you want it to "remember" must be re-sent every turn — that's why long chats get expensive (every turn re-sends the full history) and why "memory" features in chat products are scaffolding around the model, not part of it.
| Model | Window | Roughly… |
|---|---|---|
| GPT-3.5 (2022) | 4k tokens | a short article |
| GPT-4 base (2023) | 8k | a longer article |
| GPT-4o / Claude 3 (2024) | 128k | ~150 pages |
| Claude Sonnet 4.6 / Opus 4.7 (2026) | 200k–1M | ~250 pages → ~1,000 pages |
| Gemini 2.5 Pro | 2M | a small library |
GPT-3.5 (2022)
49% used
4,096 tokensGPT-4 base (2023)
24% used
8,192 tokensGPT-4o / Claude 3 (2024)
2% used
128,000 tokensClaude Sonnet 4.6 (2026)
1% used
200,000 tokensClaude 1M context (2026)
0% used
1,000,000 tokensGemini 2.5 Pro
0% used
2,000,000 tokensBars longer than 100% (red) means the input doesn't fit. Even when it does fit, models tend to use middle-context information less reliably than information near the start or end — the "lost in the middle" effect.
Where it bites in real life
Under the hood (optional)
Guard before sending: add up tokens, refuse if overflow. ~5 lines of TypeScript. Skip if you don't code — the idea is "check the total before hitting send."
›Show the example code (TypeScript, ~5 lines)click to expand
import { encode } from "gpt-tokenizer";
const MAX_INPUT = 180_000; // leave room for the reply
function fitsInContext(messages: { role: string; content: string }[]) {
const total = messages.reduce((n, m) => n + encode(m.content).length, 0);
return total <= MAX_INPUT;
}Try it yourself (no coding, ~5 minutes)
- Open claude.ai (200k context).
- Find a public document of ~5,000+ words (Wikipedia article, long blog post). Copy it.
- Test 1: paste, ask "What's the main argument?" — note the answer.
- Test 2: paste again, ask "What does paragraph 7 say verbatim?" — note the answer.
Test 1 plays to the model's strength (holistic compression). Test 2 tests precise recall — you'll often see drift, paraphrase, or wrong details. "Lost in the middle" in action.
Check your understanding
- 1. 128k context window, conversation has used 100k tokens. How much for the reply?
- 2. Where should the most important instruction go?
- 3. Why is dumping a whole codebase into the prompt usually a bad idea even if it fits?
Found this useful? Share it with someone learning AI.
Further reading
- Lost in the Middle — Liu et al. 2023 — landmark paper.
- Anthropic — Long context prompting tips — production tactics.
- Needle in a Haystack benchmarks — open methodology for measuring long-context recall.