LLM Context Windows Explained: Why 1 Million Tokens Changes Everything
Context windows have grown from 4,096 tokens in 2022 to over 1 million in 2026. This isn't an incremental improvement — it fundamentally changes what AI can do with a single prompt.
In 2022, the context window of GPT-3 was 4,096 tokens — roughly 3,000 words. You could paste in a short article, ask a question, and get an answer. That was it. Anything longer had to be chunked, summarized, or thrown away.
In 2026, flagship models routinely offer 128K, 512K, or even 1 million+ token context windows. That's the equivalent of several full-length novels — or an entire codebase — processed in a single pass.
This isn't just a bigger number. It's a different kind of capability. Understanding what a context window actually is, why it was limited for so long, and what becomes possible when it's large is essential knowledge for anyone building with or relying on AI systems today.
What Is a Context Window, Exactly?
Every large language model operates within a fixed memory boundary called the context window. It represents the total number of tokens — fragments of text, roughly 3/4 of a word each — that the model can "see" at any one time when generating a response.
Think of it as the model's working memory. When you send a message, the entire conversation history, any system instructions, any documents you've attached, and your new message all have to fit inside this window. Anything outside the window doesn't exist to the model. It can't reference it, reason about it, or be influenced by it.
Tokens aren't exactly words. The tokenizer — the preprocessing layer that converts raw text into numbers the model processes — breaks text into subword units. As a rough guide:
- 1,000 tokens ≈ 750 words
- 4,096 tokens ≈ 3,000 words ≈ a short article
- 32,000 tokens ≈ a short novella
- 128,000 tokens ≈ a full-length novel
- 1,000,000 tokens ≈ 5–7 full novels, or a large codebase
Code tokenizes differently than prose. Python code with long variable names and comments might tokenize at 1 token per 4–5 characters, meaning a 50,000-line codebase can easily exceed 200,000 tokens. This matters enormously for developer use cases.
Why Context Windows Were Small for So Long
The limitation wasn't arbitrary. It was architectural and computational.
The dominant architecture in large language models is the Transformer, introduced by Google in 2017. Transformers process text through a mechanism called self-attention, where every token attends to every other token in the sequence to determine contextual relationships. This is what allows the model to understand that "it" in "the bank collapsed and it disappeared" refers to the bank, not some other noun.
The problem: self-attention scales quadratically with sequence length. If you double the context window, you quadruple the memory and compute requirements. Going from 4K to 128K tokens isn't a 32× increase in cost — it's 1,024× under naive implementations.
For several years, this quadratic scaling was the hard ceiling. You could increase context size, but the GPU memory and compute requirements became prohibitive at training time and inference time.
The 2023–2025 period saw a series of algorithmic breakthroughs that changed this equation:
Sliding window attention (Mistral's contribution): Rather than every token attending to every other token, attention is restricted to a local window that slides across the sequence. This reduces complexity dramatically while preserving most of the useful signal for the majority of natural language tasks. Ring attention and flash attention: These memory-efficient attention implementations reduce the memory footprint of attention computation by up to 10× without changing the mathematical output, allowing much larger sequences to fit in GPU VRAM. Rotary Positional Embeddings (RoPE) with extension techniques: Traditional positional encoding schemes degraded in quality when extrapolated beyond training length. RoPE, combined with YaRN (Yet Another RoPE extensioN) or dynamic NTK scaling, allows models to be trained at one context length and reliably extended at inference time.The combination of these techniques brought 128K context to consumer-grade hardware by late 2024, and 1M+ context to server-grade hardware by mid-2025.
The Context Window Arms Race: Where We Are in 2026
| Model | Context Window | Runs Locally? | VRAM Required |
|---|---|---|---|
| GPT-4o | 128K tokens | No | — |
| Claude Opus 4 | 512K tokens | No | — |
| Gemini 2.0 Ultra | 1M tokens | No | — |
| Qwen 3.5 72B | 128K tokens | Yes | 42 GB |
| Qwen 3.5 32B | 128K tokens | Yes | 19 GB |
| Llama 4 Scout | 512K tokens | Yes (M4 Max+) | 48 GB |
| DeepSeek V4 | 256K tokens | Server-grade | 80+ GB |
| Mistral Large 3 | 128K tokens | Yes (dual GPU) | 45 GB |
| GLM-5.1 72B | 128K tokens | Yes (workstation) | 42 GB |
The local LLM landscape has caught up faster than most expected. Qwen 3.5 32B with 128K context runs on a single RTX 4090 with 24 GB VRAM, and Llama 4 Scout with 512K context needs ~67 GB of weights resident, so it wants a 96 GB+ unified-memory machine rather than a 64 GB one. What required a data center two years ago now runs on workstation hardware you can buy at Best Buy.
What Actually Changes at Different Context Sizes
The difference between 4K and 128K context isn't just quantitative. It unlocks qualitatively different use cases.
4K–16K: The Old Baseline (2022–2023)
At this range, you could handle:
- Single documents up to ~10,000 words
- Short conversation histories
- Individual source code files
What you couldn't do: analyze an entire legal contract, reason about a full codebase, maintain coherent memory across a long project session, or ingest a book chapter by chapter in one pass.
32K–128K: The Productivity Inflection Point (2024–2025)
At 128K tokens, a qualitative shift happens. You can now:
Full-book summarization and Q&A: Ingest a 200-page technical manual (roughly 75,000 words) and ask targeted questions without chunking. The model can identify relationships between concepts in chapter 2 and chapter 14 without losing the thread. Complete codebase analysis: A 20,000-line Python codebase fits in 128K context. You can ask "why does the payment flow fail when the user has an expired card?" and the model can trace the actual execution path through every relevant file simultaneously — not guess based on fragments. Multi-document legal and financial analysis: Paste in a merger agreement (40 pages), due diligence reports (60 pages), and a competitor's 10-K filing (80 pages) and ask the model to identify risk factors specific to this deal. This is genuinely useful legal and financial work that previously required expensive human review cycles. Long-form generation: A single prompt can request a 30,000-word technical specification, a business plan with appendices, or a detailed research report, and the model can maintain internal consistency throughout because it sees the entire output in its context.512K–1M+: The Architectural Change
At 1 million tokens, the nature of the tool changes.
Entire repositories, not files: The entire Linux kernel (roughly 25 million lines) won't fit in 1M tokens. But the entire source of a mid-sized startup's production codebase — 200,000 lines across 500 files — usually does. An AI assistant with this context can answer questions like "what are all the places we handle currency conversion, and are they consistent?" across the full production codebase. Real-time document archives: 1 million tokens holds roughly 2 years of a company's internal Slack messages, or 5 years of support tickets. Querying this in real time against an exact archive — rather than a lossy vector database retrieval — produces dramatically more reliable answers. No hallucinated citations. The document is either there or it isn't. Few-shot learning at scale: You can include hundreds of examples of the behavior you want in a single prompt. Instead of fine-tuning a model on 10,000 examples and waiting for training to complete, you can include 500 carefully chosen examples directly in the context. For many specialized tasks, this in-context learning at scale approaches the quality of fine-tuning. Multi-agent coordination state: Complex AI agent workflows generate large amounts of intermediate reasoning, tool results, and partial outputs. With 1M context, a coordinating agent can hold the full state of a multi-hour automated task without summarizing or truncating, preserving the complete audit trail for inspection.The Catch: Not All Context Is Equal
Here's what the marketing doesn't always make clear: having a large context window doesn't mean the model uses all of it equally well.
The phenomenon known as lost in the middle was documented by researchers at Stanford in 2023 and remains relevant in 2026, though improved training has reduced it significantly. The core finding: models tend to pay more attention to information at the beginning and end of the context window, and can miss or misweight information buried in the middle.
Practical implications:
- Put your most important instructions at the beginning and end of the prompt, not the middle
- For document retrieval tasks, placing the most relevant document closest to the question tends to improve accuracy
- Very long contexts have higher latency: A 1M token context window doesn't process instantly. On consumer hardware, time-to-first-token for a 500K context can be 30–60 seconds depending on GPU
There's also the question of effective context vs. nominal context. Some models advertise a context size they were technically trained to handle but perform poorly at. Benchmark models on your actual use case — not just the headline number.
Practical Guide: Matching Context Size to Your Task
< 32K tokens — Most conversational tasks: Chat, writing assistance, code review for single files, document summarization under 25,000 words. Almost any current local LLM handles this. 32K–128K tokens — Professional workflows: Full contract review, codebase debugging across multiple files, long-document Q&A, multi-session project continuity. Target: Qwen 3.5 32B (24 GB VRAM) or Mistral Small 3.1 on Apple Silicon. 128K–512K tokens — Power user and developer use cases: Full repo analysis, book-length content generation, multi-document synthesis, extended agentic workflows. Target: Qwen 3.5 72B (42 GB VRAM) or Llama 4 Scout on M4 Max. 512K–1M+ tokens — Enterprise and infrastructure: Archive querying, whole-company codebase analysis, large-scale data extraction. Target: Server-grade hardware, or cloud APIs for now (local hardware catching up).# Example: loading a full Python project into context
import os
import anthropic
def load_project(path: str) -> str:
"""Concatenate all .py files in a project for context injection."""
files = []
for root, _, filenames in os.walk(path):
for fname in filenames:
if fname.endswith('.py'):
fpath = os.path.join(root, fname)
with open(fpath) as f:
files.append(f"### {fpath}\n{f.read()}")
return "\n\n".join(files)
client = anthropic.Anthropic()
project_code = load_project("./my_project")
response = client.messages.create(
model="claude-opus-4-7",
max_tokens=4096,
messages=[{
"role": "user",
"content": f"{project_code}\n\nFind all places where user input is passed to SQL queries without parameterization."
}]
)
print(response.content[0].text)
Context Windows and Local LLMs: The Hardware Reality
Running models with large context windows locally requires more than just VRAM for model weights. The key variables:
KV cache: During inference, transformers store key-value pairs for every token in the context window (the KV cache). This grows linearly with context size and can dwarf the model weights themselves for very long contexts.For a Qwen 3.5 32B model at Q4 quantization:
- Model weights: ~19 GB
- KV cache at 4K context: ~0.5 GB
- KV cache at 32K context: ~4 GB
- KV cache at 128K context: ~16 GB
This means running Qwen 3.5 32B at full 128K context requires approximately 35 GB total VRAM — pushing beyond a single RTX 4090 and into dual-GPU territory, or an RTX 6000 Ada. Apple Silicon with unified memory handles this better since the memory pool is shared.
# Check available VRAM before loading long context
nvidia-smi --query-gpu=memory.free,memory.total --format=csv
# Load with Ollama, specifying context size explicitly
ollama run qwen3.5:32b --num-ctx 65536 # 64K context
ollama run qwen3.5:32b --num-ctx 131072 # 128K context (needs ~35GB)
The Near Future: What 10M Context Enables
Research models in 2025 demonstrated 10M token context windows in controlled settings. The engineering challenges are being solved. What would 10M tokens unlock?
Real-time genomics and clinical data: An entire patient's longitudinal medical record across 20 years of hospital visits, lab results, and imaging reports fits in 10M tokens. AI-assisted diagnosis with true whole-history context, not probabilistic retrieval. Full organizational memory: Everything a company has written — emails, Slack, documents, code — for a team of 50 people over 3 years fits in ~10M tokens. True institutional memory available for query, synthesis, and analysis. Scientific literature synthesis: A subfield of biology has roughly 100,000 papers published since 2000. Selective loading of the most relevant 5,000 papers at an average of 2,000 tokens each = 10M tokens. A model with this context could answer "what is the current state of evidence on X mechanism?" with genuine comprehension, not retrieval-augmented guessing.The trajectory is clear. Context windows will continue to grow until "the entire relevant information environment" fits in a single pass. The question for practitioners isn't whether this is coming — it's whether your infrastructure and workflows are designed to take advantage of it when it arrives.
Check which models support large context windows → Model Library See if your hardware can handle 128K context inference → Hardware Analyzer