VRAM calculator: how much memory does a model need?
Within the journey of running language models locally, this calculator is situated at the transition between selecting the right components and actually configuring software engines. Before loading a model, it must be clear how heavily it will draw on video memory (VRAM). Anyone looking to first check which physical expansion cards or processors are suitable can consult the overview on what hardware is needed to run LLMs locally.
The most common mistake when sizing a local setup is looking exclusively at the model's file size on disk. A 4.8-gigabyte GGUF file does not simply fit into a 6-gigabyte graphics card once serious prompt input comes into play. Besides the static model weights, the KV cache (context memory), intermediate activation layers, and driver runtime overhead also demand physical memory. In this guide, we break down the exact components of memory demand and provide the calculation formulas to determine in advance whether a configuration will remain stable.
The four pillars of total memory usage
When a runtime such as llama.cpp, Ollama, vLLM, or LM Studio initializes a language model, the required VRAM is composed of four separate segments. The total required memory ($VRAM_{total}$) is the sum of these parts:
VRAM_totaal = Geheugen_Weights + Geheugen_KV_Cache + Geheugen_Activaties + Geheugen_CUDA_Overhead
Underestimating any of these factors inevitably leads to an Out-of-Memory (OOM) error or an unwanted fallback to slow system RAM. Let's analyze and quantify each component separately.
1. Model weights: the static foundation
Weight memory is the easiest to predict. This is the space required to hold all parameters of the neural network in VRAM. Its size depends on two variables: the parameter count ($P$, expressed in billions) and the precision per parameter ($b$, expressed in bits per parameter, or bpw).
The basic formula for weight memory in gigabytes (GB) is as follows:
Geheugen_Weights (GB) = (Aantal_Parameters_in_miljarden * Bits_per_parameter) / 8 * 1,05
The factor 1,05 compensates for metadata, vocabulary tensors, and tensor alignment within memory. At 16-bit precision (FP16 or BF16), each parameter uses 2 bytes (16 bits). An 8B model such as Llama-3-8B thus requires around (8 * 16) / 8 * 1,05 = 16,8 GB of VRAM at full resolution, purely to load the weights.
Because 16 GB of VRAM presents a steep barrier for consumer cards, models are shrunk using quantization. How these compression techniques work mathematically and what effect they have on precision is detailed in the article breaking down quantization and bit reduction on local hardware in depth. With a common 4-bit format (such as Q4_K_M, averaging 4.5 bits per parameter including scale factors), the weight footprint of that same 8B model drops to approximately (8 * 4,5) / 8 * 1,05 = 4,72 GB.
2. The KV Cache: why context length eats memory
During text generation, the model must store the key and value vectors (Key-Value pairs) of all preceding tokens within the context window. Without this KV cache, the model would have to recompute the entire previous context for every newly generated word, which would slow down response times quadratically.
The KV cache grows linearly with context length. Its size depends on four architectural properties of the model:
- $L$: Number of transformer layers.
- $H_{kv}$: Number of Key/Value attention heads (with Grouped-Query Attention, GQA, this is often a fraction of the total number of query heads).
- $D_h$: Dimension per head (head dimension, often the hidden dimension divided by the number of query heads, typically 64 or 128).
- $C$: Active context length in tokens (for instance 4,096, 8,192, or 32,768 tokens).
- $B_{kv}$: Precision of the KV cache in bytes (standard FP16 = 2 bytes).
The universal formula for the KV cache per token is:
KV_Cache_per_token (bytes) = 2 * L * H_kv * D_h * B_kv
The multiplication by 2 comes from storing both a Key and a Value vector. For a model with Grouped-Query Attention (such as Llama-3-8B with 32 layers, 8 KV heads, head dimension 128, and FP16 precision), this results in:
KV_Cache_per_token = 2 * 32 * 8 * 128 * 2 = 131.072 bytes = 128 KB per token
With a modest window of 4,096 tokens, the KV cache consumes: 4.096 * 128 KB = 512 MB. If the context window is expanded to 64,000 tokens, however, the KV cache suddenly takes up 8.0 GB of pure video memory. For a deeper dive into the mathematical model behind this allocation, one can experiment with the interactive KV cache memory calculator on leren.llmnet.nl to see how different model architectures scale.
| Model Architecture | Layers ($L$) | KV Heads ($H_{kv}$) | Head Dim ($D_h$) | Cache per token | Cache at 8k context | Cache at 32k context |
|---|---|---|---|---|---|---|
| Mistral-7B / Llama-3-8B | 32 | 8 | 128 | 128 KB | 1.00 GB | 4.00 GB |
| Qwen-2.5-14B | 48 | 8 | 128 | 192 KB | 1.50 GB | 6.00 GB |
| Command-R (35B) | 40 | 8 | 128 | 160 KB | 1.25 GB | 5.00 GB |
| Llama-3-70B | 80 | 8 | 128 | 320 KB | 2.50 GB | 10.00 GB |
| Older MHA models (e.g., Llama-1 13B) | 40 | 40 | 128 | 800 KB | 6.25 GB | 25.00 GB |
Misconfiguring your context window will overwhelm even the fastest graphics card. How to safely limit and manage these parameters is covered in the guide on configuring context length for local deployment.
3. Activation Memory and CUDA Runtime Overhead
In addition to static weights and dynamic KV caching, inference engines allocate temporary buffers. During the forward pass, intermediate results from matrix multiplications, layer normalization, and softmax operations must be stored briefly. This is referred to as activation memory.
At batch size 1 (a single user chatting interactively), activation memory remains limited to roughly 150 MB to 500 MB. However, if the model is deployed as a local server handling multiple concurrent requests or running parallel agent evaluations, this memory scales proportionally with the batch size.
Then there is the inevitable CUDA Runtime Overhead. As soon as an Nvidia driver and the PyTorch or CUDA context are initialized, the operating system immediately claims a fixed block of VRAM. On Windows 11, the Desktop Window Manager (DWM) system process typically reserves 400 MB to 1.2 GB of VRAM for display rendering. On a headless Linux system, this driver overhead remains capped at around 200 MB to 350 MB. For a safe estimate, we therefore always maintain a fixed margin of 0.8 GB to 1.2 GB for activations and runtime overhead combined.
Quick Reference Tables: Rules of Thumb by Model Class
To avoid running complex calculations every time, we use the matrix below in practice. This table displays the total required VRAM capacity, including model weights, an 8k context window (FP16 KV cache), and a 1 GB buffer for runtime and activations.
| Model Size | Quantization | Weights (GB) | KV Cache 8k (GB) | Overhead & Activations | Recommended VRAM |
|---|---|---|---|---|---|
| 8B parameters | Q4_K_M (4,5 bpw) | 4,7 GB | 1,0 GB | 0,8 GB | 8 GB |
| 8B parameters | Q8_0 (8,5 bpw) | 8,9 GB | 1,0 GB | 0,8 GB | 12 GB |
| 14B parameters | Q4_K_M (4,5 bpw) | 8,3 GB | 1,5 GB | 0,9 GB | 12 GB |
| 14B parameters | Q8_0 (8,5 bpw) | 15,6 GB | 1,5 GB | 0,9 GB | 20 GB |
| 32B parameters | Q4_K_M (4,5 bpw) | 18,9 GB | 2,0 GB | 1,0 GB | 24 GB |
| 70B parameters | Q4_K_M (4,5 bpw) | 41,3 GB | 2,5 GB | 1.2 GB | 48 GB (2x 24GB) |
| Mixtral 8x7B (MoE) | Q4_K_M (4.5 bpw) | 26.5 GB | 1.5 GB | 1.0 GB | 32 GB |
This table immediately shows why a 32B model with 4-bit quantization just barely fits within the budget of a 24 GB graphics card (such as the RTX 3090 or 4090), as long as the context remains limited to a maximum of 8,192 tokens. If the same 32B variant is used to analyze a large PDF document of 32,000 tokens, total memory usage exceeds 26 GB and the process crashes.
Mixture-of-Experts (MoE): storing versus computing parameters
In classic dense models (such as Llama-3), every parameter is active for each generated token. In Mixture-of-Experts (MoE) architectures, such as Mixtral 8x7B or Mixtral 8x22B, only a subset of the available 'experts' is activated for each token (for example, 2 out of the 8 experts, resulting in approximately 13 billion active parameters per token in Mixtral 8x7B).
This often leads to a persistent misconception about memory usage. Although an MoE model can computationally be as fast as a much smaller model, all experts must remain present in VRAM simultaneously. After all, routing between experts shifts with every token. For VRAM calculations, it is the total number of stored parameters that counts, not the number of active parameters:
- Mixtral 8x7B: Contains a total of 46.7 billion unique parameters. In Q4_K_M, this requires approximately 26.5 GB of VRAM for weights, even though compute speed is comparable to a 13B model.
- Mixtral 8x22B: Contains 141 billion parameters. In Q4_K_M, this requires more than 80 GB of VRAM, needing at least four 24GB GPUs or a Mac Studio with 128 GB Unified Memory.
Apple Silicon and Unified Memory: a different computing model
On an Apple Mac with an M-series processor (M2/M3/M4 Max or Ultra), there is no dedicated video memory. The processor and the graphics cores share the same memory pool (Unified Memory Architecture). This offers huge advantages for running massive models with 70B or 120B parameters, but it also comes with a significant limitation.
By default, macOS reserves a portion of shared memory for the operating system and window management. macOS allows applications like llama.cpp or MLX to allocate a maximum of 75% of total RAM to the GPU by default (sysctl iogpu.wired_mem_limit). On a Mac with 32 GB RAM, this leaves roughly 24 GB available for the language model by default.
Using the following Terminal command, this limit can be increased to 90% at your own risk, creating more headroom for heavier quantizations:
sudo sysctl iogpu.wired_mem_limit=28672
The value 28672 here represents 28 GB (in megabytes). Keep in mind that if the operating system is left with insufficient memory for essential tasks, the system may freeze or begin swapping aggressively to disk, which decimates generation speed.
Practical strategies to save memory
When a model is just a few hundred megabytes too large for the available VRAM, there is no need to immediately switch to a much smaller model. There are several advanced techniques to reduce memory usage without substantial loss of quality:
1. KV-Cache Quantization (K-quants / V-quants)
By default, llama.cpp stores the KV-cache in 16-bit float (FP16). Both llama.cpp and vLLM now support 8-bit (Q8_0) and even 4-bit (Q4_0) quantization of the KV-cache. Bringing the cache down to Q8_0 immediately halves the context window's memory footprint, while the difference in accuracy across most benchmarks is statistically negligible.
# Start llama.cpp server met 8-bit KV-cache kwantisatie
./llama-server -m models/llama-3-8b-instruct-q4_k_m.gguf -c 16384 -ctk q8_0 -ctv q8_0
2. Layer-by-layer offloading (GPU Layer Offloading)
Those with an 8 GB or 12 GB GPU who want to run a 14B or 32B model can split the model. With the parameter -ngl (number of GPU layers) in llama.cpp, for example, 20 of the 32 layers are placed on the fast graphics card, while the remaining 12 layers are computed by the CPU in regular system memory (RAM). This slows down generation considerably, but prevents an outright failure to start.
If the configuration continues to crash despite these adjustments, consult the overview on what to do about out-of-memory errors and slow token speeds for step-by-step troubleshooting.
Monitoring and measuring memory usage in practice
To verify whether theoretical calculations match reality, it is advisable to monitor memory in real time using specialized diagnostic tools while processing a prompt.
Under Linux and Windows (with WSL2), the official Nvidia tool provides direct insight into total allocation:
# Doorlopend monitoren van VRAM en GPU-belasting (elke 1000ms)
nvidia-smi --query-gpu=memory.used,memory.free,memory.total,utilization.gpu --format=csv -l 1
A much more intuitive alternative in the terminal is the interactive viewer nvtop, which shows per-process active VRAM allocations and illustrates how dynamically memory increases as a long input prompt fills the KV-cache:
# Installeer en start nvtop op Ubuntu/Debian
sudo apt update && sudo apt install -y nvtop
nvtop
During testing, pay particular attention to the peak allocation at the end of a lengthy text generation. A model that uses a stable 18 GB during prompt ingestion can suddenly spike past 24 GB and crash upon reaching token 8,000.
Data protection and network security
Accurately sizing your own hardware is directly linked to information security. When a model becomes unstable and crashes due to a lack of memory, administrators are often tempted to implement fallbacks to external cloud APIs. As a result, sensitive corporate or personal data may still inadvertently pass through external servers.
By ensuring in advance that a model—including maximum context capacity—fits within local VRAM, all data is guaranteed to remain inside your own physical perimeter. More background on the organizational and legal advantages of this approach can be found in the guide on privacy-friendly AI operations on local systems. For personal users looking to secure their home environment against unintended data leaks, the guide with practical tips for a secure AI home setup also provides useful guidelines.
Quality control and context limits
A model teetering on the edge of its VRAM capacity with extremely compressed 2-bit quantization or an artificially truncated context window delivers significantly less reliable output. Information falling outside the context window is simply 'forgotten' by the model, leading to hallucinations and factual inaccuracies.
It is therefore crucial to systematically verify generated responses, especially when concessions have been made regarding model precision to stay within video memory limits. For this, see the practical verification methodology on systematically fact-checking AI responses.
For developers looking to integrate local language models into advanced autonomous systems and multi-tool loops, a solid understanding of hardware limitations, latency, and context management is an absolute requirement. Those looking to structurally build their skills in this area to a professional level will find a complete overview in the learning path on how to become a professional AI agent engineer in 2026.
Conclusion and summary
Calculating VRAM is not a guessing game, but a straightforward addition of four factors. By calculating the sum of model weights beforehand (parameter count multiplied by bit precision), the KV cache based on the intended context window, and a fixed safety buffer of roughly 1 to 1.5 GB for CUDA activations, you prevent disappointment and system instability.
Those looking for a stable local working environment should ideally choose a model quantization where total memory usage at maximum context remains at least 10% to 15% below the graphics card's physical VRAM limit. This ensures the local AI setup stays fast, reliable, and continuously operational without hiccups.


