AI Learning Hub
beginner

Context windows

The total amount of text the model can hold in its head at once. Measured in tokens.

context window — fixed size (e.g. 200,000 tokens)Themeetingagendawedis-cussedlastold↓ pushed off the edgegone forevernew tokens added →
The context window: a counter of fixed capacity. Anything that doesn't fit falls off and is gone.

What's actually happening

Everything in one conversation has to fit under a single token cap — input and reply share the same budget.

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.
ModelWindowRoughly…
GPT-3.5 (2022)4k tokensa short article
GPT-4 base (2023)8ka 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 Pro2Ma small library
GPT-3.5 (2022)
49% used
4,096 tokens
GPT-4 base (2023)
24% used
8,192 tokens
GPT-4o / Claude 3 (2024)
2% used
128,000 tokens
Claude Sonnet 4.6 (2026)
1% used
200,000 tokens
Claude 1M context (2026)
0% used
1,000,000 tokens
Gemini 2.5 Pro
0% used
2,000,000 tokens

Bars 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)

  1. Open claude.ai (200k context).
  2. Find a public document of ~5,000+ words (Wikipedia article, long blog post). Copy it.
  3. Test 1: paste, ask "What's the main argument?" — note the answer.
  4. 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. 1. 128k context window, conversation has used 100k tokens. How much for the reply?
  2. 2. Where should the most important instruction go?
  3. 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

Related lessons in this track