What is the KV cache in an LLM?
The KV cache is an LLM's short-term notes: it stores each past token's keys and values so the model does not redo that work for every new word.
Rung 1 Explain like I'm 6
Imagine reading a long story out loud and adding one new word at a time. Before each new word you have to remember what happened so far. You could read the whole story again from the start every time. That would take forever!
So instead you keep a notebook. After each word, you jot down a short note about it. For the next word you just glance at your notes and add one more line.
An AI writing an answer does the same thing. Its notebook is called the KV cache. It makes writing much faster. The catch is that the notebook gets thicker with every word, and it fills up the computer's memory.
Rung 2 High-school level
A large language model writes one token (a word or piece of a word) at a time. To choose each new token it uses attention: it looks back at every earlier token to decide which ones matter.
For each token, attention computes two lists of numbers: a key (what this token offers to be matched against) and a value (the information it passes on). These depend only on the token and the ones before it, so once computed they never change.
The KV cache stores those keys and values. When the next token comes, the model computes keys and values only for the new token, adds them to the cache, and reads the rest from it. Without the cache, writing the 1,000th token would mean redoing the work for all 999 before it.
This trades memory for speed. The cache grows with every token in the conversation, and with every user being served at the same time. That is why KV cache memory, not just the model's size, decides how many people one GPU can serve and how long a conversation it can hold.
Check yourself: Why can a model reuse old keys and values instead of recomputing them?
In a model that only looks backwards, a token's keys and values depend only on earlier tokens, so they never change once computed.
Rung 3 Undergraduate level
KV cache in a transformer. In each attention layer, token t produces a query q_t, key k_t and value v_t. Its output is softmax(q_t · Kᵀ / √d) · V, where K and V stack the keys and values of tokens 1..t. Because generation is causal, k_1..k_{t−1} and v_1..v_{t−1} are unchanged from the previous step. So at step t the model computes only q_t, k_t, v_t, appends k_t and v_t, and attends over the stored rest.
This splits inference into two phases:
- Prefill: process the whole prompt in one parallel pass and fill the cache.
- Decode: generate one token per step, each step reading the entire cache.
Size per token = 2 (K and V) × layers × KV heads × head size × bytes per number.
Worked example, Llama 3 8B: 32 layers and 8 KV heads of size 128 [3], stored in 16 bits (2 bytes):
2 × 32 × 8 × 128 × 2 = 131,072 bytes = 128 KiB per token.
At a 128K-token context (131,072 tokens) that is 16 GiB, about as much as the model's 16 GB of 16-bit weights. For an older model like OPT-13B, which gives every head its own keys and values, the PagedAttention paper puts it at 800 KB per token [1].
Without a cache, step t would redo work for all t tokens, so generating n tokens costs work that grows like n² instead of n.
Check yourself: Using the formula, why does the cache of Llama 3 8B double when the context goes from 64K to 128K tokens?
The cache stores a fixed amount per token, so its size grows in direct proportion to the number of tokens.
Rung 4 Graduate level
In serving, the KV cache competes with the weights for GPU memory. For a 13B model on a 40 GB A100, the PagedAttention paper measured about 65% of memory for weights and close to 30% for request state, mostly KV cache [1].
Fragmentation. Early systems reserved one contiguous block per request sized for the longest possible output. Only 20.4–38.2% of KV cache memory held real token states [1]. PagedAttention (vLLM, 2023) splits the cache into fixed-size blocks, like operating-system pages, reaching near-zero waste and 2–4× higher throughput at the same latency [1].
Fewer KV heads. Multi-query attention shares one key-value head across all query heads; grouped-query attention (GQA) shares a few, reaching quality close to full multi-head attention at speed close to multi-query [2]. Llama 3 70B uses 64 query heads but only 8 KV heads [3]: about 320 KiB per token, or about 43 GB at 128K tokens, versus about 344 GB if every head kept its own.
Compressing the cache. DeepSeek-V2's multi-head latent attention stores a small latent vector per token instead of full keys and values, cutting KV cache by 93.3% versus DeepSeek 67B and raising maximum generation throughput 5.76× [4]. KV cache quantization stores the cache in fewer bits: KIVI (2024) used 2 bits, keys per-channel and values per-token, for 2.6× lower peak memory and up to 4× larger batches [5].
Reuse across requests. If many requests share a prefix, such as a long system prompt, its cache can be kept and reused. Vendors sell this as prompt caching: Anthropic bills cache reads at 0.1× the normal input price on most models [8].
Rung 5 PhD level
Decoding is memory-bound because of the cache. Each step reads every stored key and value but does only a few operations per byte, so speed is set by memory bandwidth, not compute. The cache is the part of the working state that grows with context length × concurrent users, so it, not the weights, sets the limit for long-context, many-user serving.
The research splits into four lines:
- Shrink each entry: fewer KV heads [2], low-rank latents [4], fewer bits [5]. The question is how much can be removed before quality drops, and that depends on the task: long-range recall breaks before chat does.
- Keep fewer entries: evict or merge tokens judged unimportant. Any rule that drops tokens risks dropping one a later question needs, which is the same tension between fixed-size memory and exact recall that drives hybrid architectures.
- Place entries well: treat the cache as a memory hierarchy (GPU HBM, CPU memory, SSD, network storage) and decide what lives where. This becomes a scheduling and networking problem when prefill and decode run on different machines and the cache must be moved between them [6].
- Share entries: reuse caches for common prefixes across requests [8]. Open questions include eviction policy under load and isolation: sharing between users must not leak whether another user sent a given prefix.
There is no agreed theory of which past tokens a model will need, which is why most methods are judged empirically.
Rung 6 State of the art: what experts work on now
Last checked 18 November 2026.
As of 2026-11-18.
The KV cache moved from a GPU-memory detail to a storage tier with its own hardware.
Software (2025). NVIDIA released Dynamo, an open-source inference framework, on 18 March 2025. It splits prefill and decode onto different GPUs, routes requests to workers that already hold matching KV cache, and offloads less-used cache blocks from GPU memory to CPU memory, local SSDs or network storage. NVIDIA claimed up to 30× more requests served for DeepSeek-R1 on Blackwell, a projected vendor figure [6]. This is what people mean by KV cache offloading.
Hardware (2026). At CES on 5 January 2026 NVIDIA announced the Inference Context Memory Storage platform, built on its BlueField-4 data processor, to hold and share KV cache across nodes outside GPU memory. NVIDIA claims up to 5× more tokens per second and up to 5× better power efficiency than traditional storage, without published methodology; partner systems are expected in the second half of 2026 [7].
Pricing. Cached-prefix discounts deepened. Anthropic's 2026 docs list cache reads at 0.1× the base input price for most models, 0.05× for Claude Opus 5.5 and Sonnet 5.5, and 0.025× for some others [8].
Long contexts and agents, which re-send long histories every turn, are why the cache now gets this attention.
Sources
- Kwon et al., Efficient Memory Management for Large Language Model Serving with PagedAttention (SOSP) (2023)
- Ainslie et al., GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints (2023)
- Llama Team, Meta: The Llama 3 Herd of Models (2024)
- DeepSeek-AI, DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model (2024)
- Liu et al., KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache (2024)
- NVIDIA, Introducing NVIDIA Dynamo, a Low-Latency Distributed Inference Framework (2025)
- NVIDIA, BlueField-4 Powers New Class of AI-Native Storage Infrastructure (press release) (2026)
- Claude API docs, Prompt caching (2026)