Context Window Guide 2026: 4K vs 32K vs 128K Tokens

Written by Jakub Rusinowski · Last updated July 10, 2026

Last Updated: May 2026 — Context window is one of the most misunderstood specs in local AI. This guide explains what it means, how it affects VRAM, and which context size you actually need for differe

In This Guide

Last Updated: May 2026 — Context window is one of the most misunderstood specs in local AI. This guide explains what it means, how it affects VRAM, and which context size you actually need for different tasks.

What Is a Context Window?

The context window is the maximum amount of text a model can "see" at once — including your entire conversation history, system prompts, documents you've pasted in, and the model's own responses.

Think of it as short-term memory: everything outside the context window is forgotten.

Token conversion guide:

Context SizeApprox. WordsWhat Fits
4,096 tokens~3,000 wordsShort conversation, simple Q&A
8,192 tokens~6,000 wordsMedium conversation, short article
32,768 tokens~24,000 wordsLong document, book chapter
128,000 tokens~96,000 wordsFull book, large codebase
1,000,000 tokens~750,000 wordsMultiple books (Gemini Ultra only)

Context Window by Popular Local Models (2026)

ModelContext WindowVRAM (Q4)
Phi-3.5 Mini128k3 GB
Llama 3.1 8B128k6 GB
Qwen 2.5 14B128k9.5 GB
Gemma 3 27B128k16.5 GB
DeepSeek R1 32B64k20 GB
Llama 3.3 70B128k40 GB
Llama 4 Scout128k10.5 GB
Llama 4 Maverick128k24 GB
Mistral NeMo 12B128k8 GB

Most modern models support 128k context — but using all of that context costs VRAM and slows inference.

How Context Length Affects VRAM

The KV cache (key-value cache) stores context information and grows with context length. This is in addition to the base model VRAM:

For Llama 3.1 8B (Q4_K_M, 6GB base):
- 4k context:   +0.3 GB → ~6.3 GB total
- 8k context:   +0.6 GB → ~6.6 GB total
- 32k context:  +2.5 GB → ~8.5 GB total
- 128k context: +10 GB  → ~16 GB total (!)

Running a 7B model at 128k context requires as much VRAM as a 13B model at 8k context.

Practical implication: Don't set context to 128k "just in case" — set it to what you actually need. Ollama's default (2k–4k) is fine for most chat use cases.

Setting Context Length in Ollama

# Set context length for a session
ollama run llama3.1 --context-length 32768

# Or in a Modelfile for permanent configuration
FROM llama3.1:8b
PARAMETER num_ctx 32768

# Build and use
ollama create my-llama -f Modelfile
ollama run my-llama

Context Window Use Cases

When 4k–8k Is Enough

When You Need 32k

When You Need 128k

Context Length and RAG: An Important Nuance

Many users assume: "more context = less need for RAG." This is partially true, but:

For most practical applications, 8k–32k context + good retrieval beats 128k context alone.

Context Window vs Model Quality: The Tradeoff

Longer context typically comes with slower responses:

Time to first token (Llama 3.1 8B, RTX 4090):
- Prompt length 500 tokens:  0.3 seconds
- Prompt length 4,000 tokens: 2.1 seconds
- Prompt length 32,000 tokens: 18 seconds
- Prompt length 128,000 tokens: 70+ seconds

For interactive use, keep prompts under 8k tokens. For batch processing (summarization, analysis), longer contexts are acceptable.

Practical Configuration by Task

TaskRecommended ContextReasoning
Daily chat assistant4k–8kEfficient, most conversations fit
Code assistant (file-level)16k–32kOne or a few files
Document summarizer32k–64kMost documents fit
Full codebase assistant64k–128kMultiple files, project context
Book analysis128kFull book chapters
Research paper review32kTypical paper ≈ 8,000–15,000 tokens

Frequently Asked Questions

What happens when context is exceeded? The model truncates the oldest content (typically the beginning of the conversation). You'll notice the AI "forgetting" early parts of the conversation.

Does context window affect model quality? Not directly — but models fine-tuned for longer contexts tend to handle long-range dependencies better. A model claiming 128k context may still perform poorly at 100k if not specifically trained for it.

Can I extend context window beyond what the model supports? Not reliably. Some techniques (RoPE scaling, YaRN) can extend context somewhat, but with quality degradation. It's better to choose a model designed for your needed context length.

Why do small models support 128k context? The model weights and the context window are separate. A 4B model can have 128k context — it just means you'll need extra VRAM for the KV cache. The model quality at 128k is determined by its training, not just parameter count.

Related Guides

← All Guides | Check GPU Compatibility