# KV Cache Size

- **Canonical URL:** https://getaimath.com/dictionary/kv-cache-size/
- **Topics:** [LLM Inference: Prefill & Decode](https://getaimath.com/dictionary/category/llm-inference-prefill-and-decode/)
- **Last updated:** 2026-11-25

## What is KV Cache Size?

**In one sentence:** KV cache size is how much memory the KV cache needs, which grows with context length, layers, heads and number of users.

Every token adds keys and values for every layer. Long conversations and many users at once can make the KV cache bigger than the model itself. Tricks like GQA and KV cache quantization shrink it.

![How an AI Replies: 1. Read Your Question → 2. Type the Answer — Simple two-step cartoon: Step 1 (Prefill) shows the AI scanning your entire question in one flash (causing the brief pause before it starts talking); Step 2 (Decode) shows it typing out the reply one word at a time.](https://getaimath.com/diagrams/llm-inference-prefill-and-decode.png)
*Napkin Diagram (LLM Inference: Prefill & Decode): Every AI reply has two halves: gulping down your whole prompt at once, then speaking the answer one word at a time.*

### Quick Math / Rule of Thumb

KV bytes per token = 2 (K & V) × Layers × KV heads × Head size × Bytes per number. Example: Llama 3 8B in FP16 (32 layers, 8 KV heads, size 128) uses ~128 KB per token—about 16 GB for a full 128K-token context. Bigger models need more.

## What is an example of KV Cache Size?

A 70B model with a 128,000-token context could need tens of gigabytes just for the KV cache.

## Why does KV Cache Size matter?

KV cache size often decides how long a context and how many users a server can handle.

## Related Concepts

- [Value Cache](https://getaimath.com/dictionary/value-cache/): The value cache is the part of the KV cache that stores the values for all previous tokens.
- [KV Cache Quantization](https://getaimath.com/dictionary/kv-cache-quantization/): KV cache quantization stores the KV cache in fewer bits to save memory.
- [Key Cache](https://getaimath.com/dictionary/key-cache/): The key cache is the part of the KV cache that stores the keys for all previous tokens.
- [PagedAttention](https://getaimath.com/dictionary/pagedattention/): PagedAttention is a way to store the KV cache in small fixed-size blocks, like pages in a book, to avoid wasting memory.
- [KV Cache](https://getaimath.com/dictionary/kv-cache/): The KV cache is the model's short-term memory of the keys and values it already computed for earlier tokens.
- [Continuous Batching](https://getaimath.com/dictionary/continuous-batching/): Continuous batching lets a server add new requests to a running batch as soon as others finish, instead of waiting for the whole batch.

---
Source: The AI Math Dictionary (https://getaimath.com/dictionary/kv-cache-size/)
