← all tools

free tool · no signup · runs in your browser

Context Window Calculator: KV Cache & VRAM by Context Length

Pick a model, a quantization, and a context length — see exactly how much VRAM the weights and the KV cache will eat. The KV cache grows linearly with every token you keep in context, and at long contexts it can dwarf the model itself. This calculator shows the full growth curve and tells you which GPUs hold the result.

/// configuration

Context window — model max 128K
KV cache precision

FP16 (2 bytes/element) is the default. Switch to Q8_0 to halve the KV cache via --cache-type-k q8_0 --cache-type-v q8_0 in llama.cpp.

Each concurrent slot allocates its own KV cache — memory scales with slot count.

/// vram required

Gemma 4 E2B · Q4_K_M · 8K · KV FP16

3.7GB

fits on RTX 3070 (8GB)

smallest single card that holds it

Weights

2.9 GB

78% of total

KV cache

63 MB

2% of total

Overhead

0.8 GB

CUDA/Metal context

Note: 29 of 35 layers use sliding-window attention (window 512), capping their cache below the full context.

/// memory at every context size

Gemma 4 E2B · Q4_K_M · KV FP16 — weights stay fixed, the KV cache grows.

ContextKV cacheTotal VRAM
2K27 MB3.7 GB
4K39 MB3.7 GB
8K63 MB3.7 GB← selected
16K0.1 GB3.8 GB
32K0.2 GB3.9 GB
64K0.4 GB4.0 GB
128K0.8 GB4.4 GB

/// what fits

Discrete single-GPU capacity vs the 3.7 GB total above. CPU, iGPU, and unified-memory system rows are not treated as single cards.

Holds it (38)

RTX 5090 (32GB) · 32GBRTX 5080 (16GB) · 16GBRTX 5070 Ti (16GB) · 16GBRTX 5070 (12GB) · 12GBRTX 5060 Ti (16GB) · 16GBRTX 4090 (24GB) · 24GBRTX 4080 (16GB) · 16GBRTX 4070 Ti Super (16GB) · 16GBRTX 4070 (12GB) · 12GBRTX 4060 Ti (16GB) · 16GBRTX 3090 (24GB) · 24GBRTX 3080 (10GB) · 10GBRTX 3070 (8GB) · 8GBRTX 3060 (12GB) · 12GBRTX 2080 Ti (11GB) · 11GBRTX 2070 Super (8GB) · 8GBGTX 1080 Ti (11GB) · 11GBGTX 1070 Ti (8GB) · 8GBRTX 6000 Ada (48GB) · 48GBNVIDIA L4 (24GB) · 24GBNVIDIA L40S (48GB) · 48GBNVIDIA A100 (40GB) · 40GBNVIDIA A100 (80GB) · 80GBNVIDIA H100 SXM (80GB) · 80GBNVIDIA H200 (141GB) · 141GBNVIDIA B200 (192GB) · 192GBAMD RX 9070 XT (16GB) · 16GBAMD RX 7900 XTX (24GB) · 24GBAMD RX 7900 XT (20GB) · 20GBAMD RX 7800 XT (16GB) · 16GBAMD RX 7600 XT (16GB) · 16GBAMD RX 6900 XT (16GB) · 16GBAMD RX 6800 XT (16GB) · 16GBAMD MI300X (192GB) · 192GBIntel Arc B580 (12GB) · 12GBIntel Arc B570 (10GB) · 10GBIntel Arc A770 (16GB) · 16GBIntel Arc A750 (8GB) · 8GB

Context window and KV cache reference

Native maximum context and FP16 KV cache size for one request slot at common context lengths, alongside the size of the weights at Q4_K_M. Add roughly 0.75 GB of runtime overhead for the total. Use the calculator above for other quantizations, Q8_0 KV cache, or multiple parallel slots.

ModelMax contextAttentionKV @ 8KKV @ 32KKV @ 128KWeights (Q4_K_M)
Llama 3.1 8B128KGQA1.0 GB4.0 GB16.0 GB4.6 GB
Llama 3.3 70B128KGQA2.5 GB10.0 GB40.0 GB40.1 GB
Llama 4 Scout (109B, 17B active)10MGQA + sliding window1.5 GB2.6 GB7.1 GB61.7 GB
Qwen3 8B40KGQA1.1 GB4.5 GBbeyond max4.7 GB
Qwen3 32B40KGQA2.0 GB8.0 GBbeyond max18.6 GB
Qwen3 30B-A3B (MoE)40KGQA0.8 GB3.0 GBbeyond max17.3 GB
Qwen3 Coder 30B-A3B256KGQA0.8 GB3.0 GB12.0 GB17.3 GB
Qwen3 Coder Next (80B-A3B)256KGQA0.8 GB3.0 GB12.0 GB45.3 GB
Gemma 3 27B128KGQA + sliding window1.0 GB2.9 GB10.4 GB15.6 GB
Gemma 4 12B256KGQA + sliding window0.8 GB2.3 GB8.3 GB6.9 GB
Gemma 4 31B256KGQA + sliding window2.0 GB5.8 GB20.8 GB18.6 GB
Mistral Small 3.2 24B128KGQA1.3 GB5.0 GB20.0 GB13.6 GB
Devstral Small 2 24B384KGQA1.3 GB5.0 GB20.0 GB13.6 GB
GPT-OSS 20B (3.6B active)128KGQA + sliding window0.2 GB0.8 GB3.0 GB12.2 GB
GPT-OSS 120B (5.1B active)128KGQA + sliding window0.3 GB1.1 GB4.5 GB68.4 GB
Phi-4 14B16KGQA1.6 GBbeyond maxbeyond max8.3 GB
GLM-4.5 Air (106B, 12B active)128KGQA1.4 GB5.8 GB23.0 GB62.8 GB
DeepSeek R1 Distill Qwen 32B128KGQA2.0 GB8.0 GB32.0 GB18.6 GB
DeepSeek V3.2 (671B, 37B active)160KMLA0.5 GB2.1 GB8.6 GB389.4 GB
Kimi K2 (1T, 32B active)256KMLA0.5 GB2.1 GB8.6 GB583.1 GB

See what hosted models cost per token in the model directory, or put two side by side with the model comparison tool.

Tokens, words, and pages

Context windows are measured in tokens, not words. A token is a chunk of text from the model's tokenizer — often a whole common word, sometimes a fragment. For English prose, one token averages about three quarters of a word, so a 32K window holds roughly 24,000 words (about 50 pages) and a 128K window roughly 95,000 words (about 190 pages). Source code, JSON, and non-English text tokenize less efficiently, so budget more tokens for them. Every tokenizer is different; treat these as planning figures.

How much context does your workload need?

Chat and support assistants usually sit comfortably in 8K–16K: a system prompt and a few turns of history. RAG over company documents needs room for the retrieved passages on top of the question — 16K–32K is typical, and retrieving more chunks is only useful if the window can hold them. Coding agents read files, diffs, tool output, and their own plan, so 32K is a practical floor and many tools work better at 64K or more. See running Claude Code against a local model for a real example. Long-document analysis — contracts, transcripts, codebases — is where 128K windows earn their memory cost.

Allocating more context than you use still reserves the memory. Size for the workload, then confirm the whole footprint — weights, cache, and overhead — with the VRAM calculator.

What is the KV cache?

When a transformer generates text, every token it has already seen produces a set of attention keys and values at every layer. Rather than recompute those for the whole sequence on each new token, the model caches them — this is the KV cache. It is the working memory that lets the model "remember" your prompt and its own output as it streams a response.

The weights of the model are fixed: a 7B model at Q4_K_M is roughly the same size whether your context is 2K or 200K. The KV cache is the part that scales with the conversation. That is why a model that loads fine at 4K can run out of memory the moment a coding agent asks for a 32K context.

Why does it grow linearly with context?

For standard grouped-query attention (GQA), the cache stores one key vector and one value vector per token, per layer, per KV head. Hold the architecture fixed and the only variable is the number of tokens — so memory is directly proportional to context length. The rough formula is:

kv_bytes = 2 (K and V) × layers × kv_heads × head_dim × context × bytes_per_element

Double the context, double the cache. Go from 8K to 128K and the cache is 16× bigger. This tool computes it per-model using each model's real layer count, KV-head count, and head dimension, and accounts for sliding-window layers that cap their cache at the window size.

GQA vs MLA: some models compress the cache

Not every architecture pays the full GQA price. DeepSeek-style models use multi-head latent attention (MLA), which stores a single compressed latent vector per token per layer instead of a full key/value pair for every head. The result is a dramatically smaller KV cache at the same context length — sometimes an order of magnitude less. The calculator uses each model's declared attention type, so an MLA model will show a much flatter growth curve than a comparable GQA model.

The --parallel gotcha

llama.cpp's --parallel flag splits the context window across concurrent request slots. If you set a 32K context with --parallel 4, each slot only gets 8K — but the server still allocates KV cache for all four slots at once. The memory cost multiplies by the number of slots. Set the parallel-slots field above to see this: serving four users at 8K each costs the same KV memory as one user at 32K.

How does this relate to Wide Area Intelligence?

Every node you add to Wide Area Intelligence has its own context window setting(default 4096). Coding agents and long-document workflows typically need 32K, which is exactly where the KV cache starts to matter. Use this calculator to confirm a node's GPU has the headroom before you raise the context window, then route requests to it. The gateway speaks the OpenAI API at https://wideareaai.com/api/v1, and the X-WAI-Node header pins a request to the node you sized here.

Add a node and set its context window →

Frequently asked questions

What is a context window?
The context window is the maximum number of tokens a model can consider at once — your system prompt, the conversation or documents you send, and the response it generates all count against it. Anything beyond the window is truncated or must be summarized.
How many words fit in a 128K context window?
As a rough rule for English prose, one token is about three quarters of a word, so 128K tokens is roughly 95,000 words — around 190 pages at 500 words per page. Source code, non-English text, and data such as JSON tokenize less efficiently, so fewer words fit.
Does a bigger context window need more VRAM?
Yes. The model weights stay the same size, but the KV cache grows linearly with the number of tokens in context. At long contexts the cache can rival or exceed the weights, which is why a model that loads at 4K can run out of memory at 32K or 128K.
How can I run a long context on a smaller GPU?
Quantize the KV cache to Q8_0 (roughly halves it), reduce --parallel so fewer slots each reserve their own cache, pick a model with sliding-window or MLA attention, or use a smaller weight quantization to free room for the cache.
Is the model's advertised maximum context the one I should use?
Not necessarily. Allocate the context your workload actually needs. Chat rarely needs more than 8K–16K, coding agents typically want 32K or more, and long-document work may justify 128K. Every extra token of allocated context costs memory whether you use it or not.

related tools

Related reading: How much VRAM do you need?. Ready to use that hardware? Turn your GPU into an OpenAI-compatible endpoint — free for 2 nodes.

/// wide area ai

These numbers are theory. Your GPU is real — put it on the network.

Wide Area Intelligence turns any machine with a GPU into an OpenAI-compatible endpoint — routed, cached, and failed over automatically. Free for 2 nodes.

Start routing — free →