What is quantization in LLMs, and what do Q4_K_M and Q8_0 mean?
ExplainerBy Lucas Matías García TorresUpdated (first published )Data checked 5 min read
Reviewed by Lucas Matías García Torres on . How we work.

Short answer
Quantization stores a model's weights with fewer bits. For Llama 3.1 8B, llama.cpp's table gives 4.58 GiB at Q4_K_M against about 14.96 GiB at 16 bits, 69% smaller. In the original k-quants measurements on LLaMA 7B, perplexity rose 0.24% at Q5_K_M, 0.91% at Q4_K_M and 14.7% at Q2_K. The name Q4_K_M reads as 4-bit, k-quant family and a medium mix of tensor precisions. Start with Q4_K_M, go up if you have memory, go below Q4 only if the model will not fit.
Prices and limits change often: check the vendor's page before you pay. How we make money.
Quantization stores a model's weights with fewer bits, so the model takes much less memory and disk space at the cost of some accuracy. It is the reason an 8-billion-parameter model that needs about 15 GiB at 16 bits fits in about 4.6 GiB as Q4_K_M, and why you can run it on an 8 GB graphics card. llama.cpp's documentation says quantization "may introduce some accuracy loss", usually measured as perplexity or KL divergence. This guide explains what the names Q4_K_M, Q8_0 and MXFP4 mean, how much memory and quality each level trades, and how to choose, using the documentation of llama.cpp and Hugging Face and the original measurements by the author of the k-quants, all checked on October 6, 2026.
What is quantization?
A language model is mostly a very large set of numbers, its weights. Trained models usually keep them as 16-bit or 32-bit floating-point numbers. Quantization stores each weight with fewer bits, for example 4 or 8, plus a small amount of extra data that lets the computer rebuild approximate values. The llama.cpp quantize documentation describes it as reducing the precision of the model weights, for example from 32-bit floats to 4-bit integers, which shrinks the model's size and can speed up inference.
The saving is large. For Llama 3.1 8B, llama.cpp's table gives these sizes, with the 16-bit size from our own calculation:
Table: size of Llama 3.1 8B by quantization (llama.cpp measurements, October 6, 2026)
| Format | Bits per weight | Size | Smaller than 16-bit by |
|---|---|---|---|
| F16 (unquantized, our calculation) | 16 | 14.96 GiB | none |
| Q8_0 | 8.5008 | 7.95 GiB | 47% |
| Q6_K | 6.5633 | 6.14 GiB | 59% |
| Q5_K_M | 5.7036 | 5.33 GiB | 64% |
| Q4_K_M | 4.8944 | 4.58 GiB | 69% |
| Q3_K_M | 3.9960 | 3.74 GiB | 75% |
The bits per weight are above the nominal 4, 5 or 8 because each block of weights also stores scaling factors. To see what a given size means for your graphics card, use our VRAM calculator or the GPU guide.
What do Q4_K_M, Q8_0 and the other names mean?
The names come from llama.cpp and the GGUF file format, described by Hugging Face as a binary format optimized for quick loading and saving of models. Read them from left to right:
- The number is the nominal bit width: Q4 is 4-bit, Q8 is 8-bit.
- K marks the "k-quants", a family added to llama.cpp in June 2023, which store weights in super-blocks of smaller blocks with their own scales. Hugging Face's table gives Q4_K at 4.5 bits per weight and Q6_K at 6.5625.
- The last letter (S, M, L) is a "quantization mix", as the k-quants pull request explains: it decides which tensors get more bits. Q4_K_S uses Q4_K for all tensors, while Q4_K_M uses the higher-precision Q6_K for half of the attention.wv and feed_forward.w2 tensors and Q4_K for the rest; Q3_K_L uses Q5_K for those tensors and Q3_K for the others.
- Q8_0 and the other _0 and _1 types are older, simpler formats. Hugging Face lists them as legacy methods that are not widely used today, although llama.cpp still offers Q8_0 and it is the 8-bit option in our memory tables.
- IQ types (IQ4_XS, IQ3_S and so on) use an importance matrix to preserve the most important weights at low bit widths.
- MXFP4 is a 4-bit "microscaling block floating point" format. OpenAI says its gpt-oss models were post-trained with MXFP4 quantization of the mixture-of-experts weights, which is how gpt-oss-20b runs within 16 GB of memory.
How much quality do you lose?
The most direct evidence is the original measurement published with the k-quants in 2023, on the LLaMA 7B model: perplexity (lower is better) on the wikitext dataset, against the 16-bit model's 5.9066.
Table: quality and size of k-quants on LLaMA 7B (original measurements, 2023)
| Format | Perplexity | Change vs 16-bit | File size |
|---|---|---|---|
| F16 | 5.9066 | none | 13.0 GB |
| Q6_K | 5.9110 | +0.07% | 5.15 GB |
| Q5_K_M | 5.9208 | +0.24% | 4.45 GB |
| Q5_K_S | 5.9419 | +0.60% | 4.33 GB |
| Q4_K_M | 5.9601 | +0.91% | 3.80 GB |
| Q4_K_S | 6.0215 | +1.95% | 3.56 GB |
| Q3_K_M | 6.1503 | +4.13% | 3.06 GB |
| Q3_K_S | 6.4571 | +9.32% | 2.75 GB |
| Q2_K | 6.7764 | +14.73% | 2.67 GB |
The shape is what matters: from 16 bits to Q5_K_M the loss in this test is a quarter of a percent, around Q4_K_M it is under 1%, and below 4 bits it grows quickly. The author's own summary is that perplexity is a fairly smooth function of model size, so you can pick the best model your memory allows. Two caveats: these numbers are for a 2023 model, so they show the trend rather than predict a current model, and perplexity is not the same as how good answers feel on your task. llama.cpp says the loss is usually measured with perplexity and KL divergence. If a model is borderline, try the next format up before buying more memory.
How do you choose a quantization?
A practical rule, which is our own reading of the data above:
- Start with Q4_K_M. In the original test it keeps the loss under 1% at about 29% of the 16-bit size, and it is the main 4-bit format in our memory tables.
- Go up to Q5_K_M, Q6_K or Q8_0 if you have the memory. The loss shrinks, but the file grows, and your context window also needs memory.
- Go down to Q3 or below only if the model will not fit otherwise. A larger model at Q3 is often better than a smaller one at Q8, but test it on your own tasks.
- Check that the model fits. With Ollama, run
ollama psand look for "100% GPU", as explained in our Ollama commands cheat sheet.
Ollama does not quantize GGUF models when you import them: its documentation says to prepare and quantize them first with a GGUF tool such as llama.cpp's llama-quantize. Ollama's library pages show the download size of each model tag, which is the memory the weights will need.
Can the cache be quantized too?
Yes. The key-value cache that holds the conversation can be stored with fewer bits. Ollama's OLLAMA_KV_CACHE_TYPE accepts f16 (the default), q8_0, which uses about half the memory, and q4_0, which uses about a quarter; it requires Flash Attention. This does not change the weights, only the memory used by long contexts.
Quantization and cloud APIs
Quantization is mostly a topic for models you run yourself. When you use a cloud API, the provider decides how the model is served and you pay per token, as in LLM API pricing compared. Running a quantized model locally has no per-token price, only the cost of the machine; see how to run an LLM locally for the steps.
What we checked
- llama.cpp: quantization reduces the precision of model weights (for example from 32-bit floats to 4-bit integers), which shrinks the model and can speed up inference; it may introduce some accuracy loss, usually measured in perplexity and/or KL divergence; for Llama 3.1 8B the bits per weight and sizes are Q3_K_M 3.9960 and 3.74 GiB, Q4_K_S 4.6672 and 4.36 GiB, Q4_K_M 4.8944 and 4.58 GiB, Q5_K_M 5.7036 and 5.33 GiB, Q6_K 6.5633 and 6.14 GiB, Q8_0 8.5008 and 7.95 GiB. (ggml-org / llama.cpp, )
- Hugging Face: GGUF is a binary format optimized for quick loading and saving of models, developed by the author of llama.cpp; its quantization table lists Q6_K at 6.5625, Q5_K at 5.5, Q4_K at 4.5, Q3_K at 3.4375 and Q2_K at 2.625 bits per weight, IQ types using an importance matrix, MXFP4 as 4-bit microscaling block floating point, and Q8_0, Q5_0, Q4_0 and similar as legacy methods not widely used today. (Hugging Face, )
- The k-quants pull request (merged June 5, 2023) adds 2 to 6 bit quantization methods and quantization mixes: Q4_K_S uses Q4_K for all tensors, Q4_K_M uses Q6_K for half of the attention.wv and feed_forward.w2 tensors and Q4_K for the others, Q3_K_L uses Q5_K for attention.wv, attention.wo and feed_forward.w2 and Q3_K for the others; perplexity is a fairly smooth function of quantized model size; on LLaMA 7B, perplexity (wikitext) and file size are F16 5.9066 and 13.0G, Q6_K 5.9110 and 5.15G, Q5_K_M 5.9208 and 4.45G, Q5_K_S 5.9419 and 4.33G, Q4_K_M 5.9601 and 3.80G, Q4_K_S 6.0215 and 3.56G, Q3_K_M 6.1503 and 3.06G, Q3_K_S 6.4571 and 2.75G, Q2_K 6.7764 and 2.67G. (ggml-org / llama.cpp, )
- OpenAI's gpt-oss models were post-trained with MXFP4 quantization of the mixture-of-experts weights, making gpt-oss-20b run within 16GB of memory. (OpenAI (Hugging Face), )
- Ollama does not quantize GGUF models during import; prepare and quantize them first with a GGUF tool such as llama.cpp's llama-quantize. (Ollama, )
- OLLAMA_KV_CACHE_TYPE accepts f16 (the default), q8_0 (about half the memory) and q4_0 (about a quarter) and requires Flash Attention; ollama ps shows 100% GPU when a model fits. (Ollama, )
What may change
- New quantization formats appear often, and the perplexity figures here are from a 2023 model: they show the trend, not the exact loss on a current model.
- The 16-bit size of Llama 3.1 8B is our calculation from its parameter count; the other sizes are llama.cpp's.
Frequently asked questions
What is quantization in LLMs?
Storing a model's weights with fewer bits (for example 4 or 8 instead of 16) so the model needs much less memory and disk space, at the cost of some accuracy. llama.cpp's documentation says it may introduce some accuracy loss, usually measured with perplexity or KL divergence.
What does Q4_K_M mean?
Q4 means a nominal 4 bits per weight, K means the k-quants family, and M is a medium quantization mix: according to the k-quants pull request, Q4_K_M uses the higher-precision Q6_K for half of the attention.wv and feed_forward.w2 tensors and Q4_K for the rest. In llama.cpp's table, Q4_K_M is 4.8944 bits per weight.
Is Q4_K_M or Q8_0 better?
Q8_0 keeps more precision and takes almost twice the memory: for Llama 3.1 8B, 7.95 GiB against 4.58 GiB. In the original k-quants measurements Q4_K_M raised perplexity by under 1%. Use Q8_0 if you have the memory and want to be safe, and Q4_K_M if you need the model to fit.
How much quality does quantization lose?
It depends on the model and the format. In the original 2023 measurements on LLaMA 7B, perplexity rose 0.07% at Q6_K, 0.24% at Q5_K_M, 0.91% at Q4_K_M, 4.13% at Q3_K_M and 14.73% at Q2_K. Perplexity is a proxy: test on your own tasks.
What is MXFP4?
A 4-bit microscaling block floating point format. OpenAI says its gpt-oss models were post-trained with MXFP4 quantization of the mixture-of-experts weights, which is how gpt-oss-20b runs within 16 GB of memory.
Can I quantize the context cache too?
Yes. In Ollama, OLLAMA_KV_CACHE_TYPE accepts f16 (default), q8_0, which uses about half the memory, and q4_0, which uses about a quarter. It requires Flash Attention and does not change the weights.
Sources
- llama.cpp: quantize (bits per weight and sizes by quantization type), ggml-org / llama.cpp. Accessed October 6, 2026.
- GGUF on the Hugging Face Hub: format description and quantization types, Hugging Face. Accessed October 6, 2026.
- k-quants (llama.cpp pull request 1684): quantization types, mixes and perplexity measurements, merged June 2023, ggml-org / llama.cpp. Accessed October 6, 2026.
- gpt-oss-20b model card and config.json, OpenAI (Hugging Face). Accessed October 6, 2026.
- Importing a model into Ollama (GGUF and quantization), Ollama. Accessed October 6, 2026.
- Ollama FAQ: context window, keep-alive, concurrency, Flash Attention, K/V cache quantization, multiple GPUs and GPU check, Ollama. Accessed October 10, 2026.
Spotted an error or an outdated price? Tell us and we will fix it.
Change history
- : Wording revised; no figure, date or source changed.
- : First published from llama.cpp's quantization documentation, Hugging Face's GGUF documentation and the original k-quants measurements.
Next review: .
Part of our Language Models Explained guide.
Keep reading
- How much VRAM do you need to run an LLM locally?
Work out how much GPU memory a local LLM needs from its size, quantization and context length. Our formula is checked against 13 real model files.
- Best GPU for local LLMs: what fits in each VRAM tier
Best GPU for local LLMs: which models fit in 8, 12, 16, 24 and 32 GB of VRAM, how memory bandwidth limits speed and which GPUs Ollama supports.
- How to run an LLM locally on Windows, Mac or Linux
Install Ollama, pick a model that fits your memory, chat with it, check it runs on the GPU and connect other apps, with the official commands for each OS.
- Ollama commands: the cheat sheet
Every Ollama command in one cheat sheet: run, pull, ls, ps, stop, rm, create, serve and launch, plus environment variables, model folders and the local API.
- What is a context window in a language model?
What a context window is, how big it is for Claude, GPT and Gemini in 2026, what happens when it fills up, why bigger is not always better and what it costs.
Other topics

Assistants & Chatbots
16 guides

LLM APIs & Costs
11 guides

Agents & Automation
8 guides

Local Models & Hardware
11 guides