Skip to content
Table of contents9 sections · tap to jump
  1. Step 1: Understand what quantization is
  2. Step 2: Read the labels
  3. Q4KM vs Q5KM vs Q6K vs Q80, side by side
  4. Q4KM vs Q5KM
  5. Q4KM vs Q4KS
  6. Q6K vs Q80
  7. Q4KM vs Q8_0
  8. IQ quants (IQ4XS, IQ3M, IQ2_M) explained
  9. Step 3: Estimate the memory cost
  10. Step 4: Pick a quant for your VRAM
  11. Step 5: Verify the choice in practice
  12. Where this breaks
  13. FAQ

TutorialaiDeep read4 min read

How to choose the right quantization for a local LLM

Ahmad JMay 24, 2026Updated Oct 23, 2026

Two types of computer memory modules with gold connectors arranged on a gray surface, with a smaller chip positioned separately to the right

Start with Q4_K_M. Use Q5_K_M if it still leaves room for your context, Q6_K over Q8_0, and IQ3_M or IQ2_M only when a model won't fit otherwise.

A deep read: the full picture, with the receipts.

Signalstrong4 independent sources

The short answer: start with Q4_K_M, and move up to Q5_K_M only when the bigger file still leaves room for your context. On Llama 3.1 8B, the Q5_K_M file is 0.81 GB larger (5.73 GB against 4.92 GB on Hugging Face), and llama.cpp's own table puts its perplexity loss at about a third of Q4_K_M's (+0.0569 against +0.1754 on Llama 3 8B). Both losses are small, so our rule is to spend spare memory on a bigger model before a fifth bit.

By the end of this tutorial you will be able to look at a list of model files like Q4_K_M, Q5_K_M, Q6_K, Q8_0 and IQ4_XS and pick the one that fits your hardware and your quality bar on purpose, not by guessing. You need no special tools, only a local LLM in a quantized file format such as GGUF and a rough idea of how much RAM or VRAM you can spare.

Step 1: Understand what quantization is#

A model's weights are numbers. By default they are stored as 16-bit or 32-bit floating-point values. Quantization stores those same weights using fewer bits each: 8 bits, 5 bits, 4 bits, sometimes fewer. Lower precision means each weight takes less memory and moves through the processor faster.

That is why a quantized model loads on a laptop that could never hold the full-precision version.

The tradeoff is rounding error. Squeezing a weight into 4 bits throws away information, and that error accumulates across billions of parameters.

Done well, the loss is small and barely shows up in output quality. Done too aggressively, the model starts producing weaker, less coherent text.

llama.cpp's documentation measures that loss in perplexity (and KL divergence). Perplexity is how well the model predicts a test text, where lower is better. Every quality number in this guide is the perplexity a quant adds, as llama.cpp's quantize tool lists it.

Step 2: Read the labels#

GGUF is the model file format llama.cpp uses, and the quant name is in the file name. Take Q4_K_M (you will also see it written q4km, or Q4_K, which llama.cpp's quantize tool accepts as an alias for Q4_K_M):

Part of the labelWhat it means
Q4The base precision: 4-bit. The finished file lands above 4 bits per weight, because the block scales cost bits too and some tensors are kept at higher precision. llama.cpp's README lists Q4_K_M at 4.89 bits per weight on Llama 3.1 8B.
KA k-quant. Weights are grouped in blocks of 16 or 32 inside super-blocks of 256, and each block gets its own scale. In llama.cpp's table, Q4_K_S is about the same size as the older Q4_0 (4.37 against 4.34 GiB on Llama 3 8B) and adds less perplexity (+0.2689 against +0.4685).
MThe mix. In llama.cpp's source, Q4_K_M and Q5_K_M store about half of the attention-value (attn_v) and feed-forward-down (ffn_down) layers at Q6_K. Q4_K_S upgrades only the first few of them, to Q5_K. In llama.cpp's own list of types, L appears only in Q3_K_L.

So Q4_K_M is a 4-bit k-quant with a medium mix, and Q5_K_M is the same recipe at 5 bits. Q6_K is a 6-bit k-quant. Q8_0 is an older, plain format: blocks of 32 weights with one scale each, at 8.5 bits per weight. Names like Q4_K_L or Q6_K_L are not llama.cpp types. They come from the uploader bartowski, whose Qwen3 32B model card describes them as the standard quant with the embedding and output weights kept at Q8_0.

Q4_K_M vs Q5_K_M vs Q6_K vs Q8_0, side by side#

The sizes below are the real file listings of three Hugging Face GGUF repositories by bartowski, read on 2026-10-19. GB per billion parameters is the file size divided by the parameter count Hugging Face reports for each repo (8.03B, 14.77B and 32.76B). The perplexity column is copied from llama.cpp's quantize tool, which measures it on Llama 3 8B.

QuantLlama 3.1 8B fileQwen3 14B fileQwen3 32B fileGB per billionPerplexity added (llama.cpp, Llama 3 8B)
Q8_08.54 GB15.70 GB34.82 GB1.06+0.0026
Q6_K6.60 GB12.12 GB26.88 GB0.82+0.0217
Q5_K_M5.73 GB10.51 GB23.21 GB0.71+0.0569
Q5_K_S5.60 GB10.26 GB22.64 GB0.69 to 0.70+0.1049
Q4_K_M4.92 GB9.00 GB19.76 GB0.60 to 0.61+0.1754
Q4_K_S4.69 GB8.57 GB18.77 GB0.57 to 0.58+0.2689
IQ4_XS4.45 GB8.11 GB17.69 GB0.54 to 0.55not listed
Q3_K_M4.02 GB7.32 GB15.97 GB0.49 to 0.50+0.6569
IQ3_M3.78 GB6.88 GB14.93 GB0.46 to 0.47not listed
Q2_K3.18 GB5.75 GB12.34 GB0.38 to 0.40+3.5199
IQ2_M2.95 GB5.32 GB11.36 GB0.35 to 0.37not listed

Two things stand out. The perplexity cost is small from Q8_0 down to Q4_K_M and then climbs steeply below it: Q3_K_M adds almost four times what Q4_K_M does, and Q2_K adds twenty times as much. And GB per billion barely moves across these three models, from 8B to 32B, so for a dense model the parameter count alone gives you a close size.

Q4_K_M vs Q5_K_M#

Q5_K_M costs about 16 to 18% more memory: 0.81 GB more on the 8B, 1.51 GB on the 14B, 3.45 GB on the 32B. For that, llama.cpp's table cuts the added perplexity from +0.1754 to +0.0569. Pick Q5_K_M when it fits with your context to spare and Q4_K_M when it does not. Our rule: never drop to a smaller model just to afford the fifth bit.

Q4_K_M vs Q4_K_S#

Q4_K_S saves very little: 0.23 GB on the 8B and 0.99 GB on the 32B. It adds about half again as much perplexity (+0.2689 against +0.1754). Use it only when Q4_K_M misses your memory by less than a gigabyte.

Q6_K vs Q8_0#

On paper Q8_0 is the closer copy (+0.0026 against +0.0217), but both add almost nothing in llama.cpp's table, and Q6_K is about 23% smaller: 1.94 GB less on the 8B, 7.93 GB less on the 32B. In llama.cpp's README speed table for Llama 3.1 8B, Q6_K also generated text faster (58.67 against 50.93 tokens per second on its test machine). Our call: Q6_K, unless you are comparing quants against the original.

Q4_K_M vs Q8_0#

Q8_0 is about 1.75 times the size of Q4_K_M on every model in the table. In the same README table it generated about 29% fewer tokens per second (50.93 against 71.93); llama.cpp's k-quant PR notes that inference speed tends to follow model size. If the memory Q8_0 needs would fit a larger model at Q4_K_M, the larger model is our pick.

IQ quants (IQ4_XS, IQ3_M, IQ2_M) explained#

The IQ types (i-quants) are a newer family, added to llama.cpp from January 2024. Hugging Face's GGUF documentation describes each IQ type as using a super-block scale plus an importance matrix ("imatrix"). llama.cpp added the imatrix the same month: statistics gathered by running sample text through the model, used to weight which rounding errors matter most. bartowski's Qwen3 32B repo ships the Qwen_Qwen3-32B.imatrix file and says every quant in it was made with the imatrix option.

  • IQ4_XS is a 4.25 bits-per-weight base type. On Qwen3 32B it is 2.07 GB smaller than Q4_K_M, which is room for about 7,900 more tokens of context. bartowski's model card calls it "smaller than Q4_K_S with similar performance".
  • IQ3_M and IQ2_M are for when a model does not fit any other way. llama.cpp's quantize tool lists bits per weight for them but no perplexity figure, so test them on your own prompts before trusting them.

Speed depends on your hardware. bartowski's card recommends i-quants below Q4 on Nvidia (cuBLAS) and AMD (rocBLAS), and says they run slower than k-quants on a CPU. When IQ4_XS landed in February 2024, its author measured it slower than Q4_0 on Apple's Metal (53.9 against 63.1 tokens per second on an M2 Max GPU) and a little faster than Q4_0 on CUDA (133.7 against 128.8 on an RTX 4080). If you run on a Mac, time both before you settle.

To make a quant yourself, llama.cpp's README converts the model to a 16-bit GGUF first and then runs llama-quantize model-bf16.gguf model-Q4_K_M.gguf Q4_K_M. Adding --imatrix with an importance-matrix file is how bartowski made every quant in the Qwen3 32B repo.

Step 3: Estimate the memory cost#

You can predict a quantized file's footprint with simple arithmetic. Multiply the parameter count by the bits per weight, then divide by eight to get bytes:

text
bytes = parameters x bits_per_weight / 8

Use the file's real bits per weight, not the number in its name. Llama 3.1 8B at Q4_K_M is 8.03 billion x 4.89 / 8, about 4.9 GB, which matches the 4.92 GB file. That is why the GB-per-billion column above is the quicker rule: about 0.6 GB per billion parameters at Q4_K_M, 0.71 at Q5_K_M, 0.82 at Q6_K and 1.06 at Q8_0. For a mixture-of-experts model, use the total parameter count, because the file stores every expert.

Watch the units. The sizes in this guide are decimal gigabytes (bytes divided by 1,000,000,000), as bartowski's tables and Ollama's tag list show them, and so does llama.cpp's README memory table (the 70B figure in Step 4), but its README speed table uses GiB (1,073,741,824 bytes). A Llama 3.1 8B Q4_K_M file is 4.92 GB in the Hugging Face listing, and that speed table lists Q4_K_M on Llama 3.1 8B at 4.58 GiB.

On top of the weights you need room for the context window (the KV cache). llama.cpp stores it in 16-bit by default, and its size is 2 x layers x KV heads x head size x 2 bytes for every token. From each model's config (for Llama 3.1 8B, the GGUF file's own header):

ModelKV cache per token8K tokens32K tokens
Llama 3.1 8B (32 layers, 8 KV heads)128 KiB1.07 GB4.29 GB
Qwen3 14B (40 layers, 8 KV heads)160 KiB1.34 GB5.37 GB
Qwen3 32B (64 layers, 8 KV heads)256 KiB2.15 GB8.59 GB

With the default 16-bit cache, the cache's size does not depend on the weight quant you pick. On Llama 3.1 8B, a 32K-token cache (4.29 GB) is bigger than the whole step from Q4_K_M to Q8_0 (3.62 GB).

Step 4: Pick a quant for your VRAM#

The table below applies our rule: the file plus an 8K-token KV cache, with at least 1 GB of the card left over for the runtime and your desktop. bartowski's Qwen3 32B card gives a similar rule of thumb: pick a file 1 to 2 GB smaller than your VRAM.

VRAMLargest of the 11 quants above that fits (file + 8K cache)What we would run
8 GB8B at Q5_K_M (6.81 GB); 14B only at IQ2_M (6.67 GB)8B at Q5_K_M; Q4_K_M if you need longer prompts
12 GB8B at Q8_0 (9.61 GB); 14B at Q4_K_M (10.34 GB)14B at Q4_K_M
16 GB14B at Q6_K (13.46 GB); 32B only at Q2_K (14.49 GB)14B at Q6_K (14.81 GB even with a 16K context)
24 GB14B at Q8_0 (17.04 GB); 32B at Q4_K_M (21.91 GB)32B at Q4_K_M, or IQ4_XS for a 16K context (21.99 GB)
32 GB32B at Q6_K (29.03 GB)32B at Q6_K; Q5_K_M for a 16K context (27.51 GB)
48 GB32B at Q8_0 (36.97 GB)32B at Q6_K with a 32K context (35.47 GB)

The table covers only the three models and the 11 quants sized above; bartowski's repos also hold slightly larger files, such as Q4_K_L and Q6_K_L, that it leaves out. On a 48 GB card our parameters-first rule points past them: llama.cpp's quantize README lists Llama 3.1 70B at 43.1 GB at Q4_K_M, which leaves under 5 GB for the KV cache and the runtime. Work out the cache for your context before you choose it over 32B at Q6_K.

The "what we would run" column is our call, and it follows one rule: spend memory on parameters first, then on bits. Our reasoning: above Q4_K_M, llama.cpp's table shows each step up in bits buying back less than 0.12 of perplexity, so we would rather spend the memory on a larger model. Below Q4_K_M the cost rises fast, so a 32B squeezed into 16 GB at Q2_K is an experiment, not a default.

Q4_K_M is also Ollama's default download for Llama 3.1: llama3.1:latest is the same file (digest 46e0c10c039e) as its llama3.1:8b-instruct-q4_K_M tag. bartowski's card labels Q4_K_M "default size for most use cases".

To run this for your own card, the Local-LLM GPU Checker takes your GPU or its VRAM and shows which open models fit at each quantization. If you are still choosing hardware, our guide to the best GPUs for running LLMs locally compares cards by VRAM. On a Mac, memory is shared with macOS and your apps, and the unified memory calculator works out what a model actually gets.

Step 5: Verify the choice in practice#

Numbers on paper are a starting estimate. Confirm the fit by loading the model and watching three things:

What to watchThe question to ask
LoadingDoes it load without paging weights to disk?
SpeedDoes generation run at a usable speed?
QualityDoes the output quality hold up on your own prompts?

If the model loads but answers feel degraded, move up one quantization step before blaming the model itself. If it will not fit, move down a step or shrink the parameter count.

Where this breaks#

One mistake to avoid is chasing higher bit counts when the real problem is too few parameters.

Eight bits of a tiny model is still a tiny model. Decide on parameter count first, then choose the largest quantization that fits, up to Q6_K.

The second pitfall is forgetting the context window. A long prompt or a big retrieval payload inflates the KV cache, and a model that fit comfortably with short prompts can run out of memory once you push the context. On Qwen3 32B, going from 8K to 32K tokens adds 6.44 GB, more than the whole gap between Q4_K_M and Q5_K_M.

Finally, do not assume a bigger model shrugs off aggressive quantization. When llama.cpp's k-quants were introduced in June 2023, their author measured LLaMA models from 7B to 65B and found that the relative quantization error, measured by perplexity, did not fall as the models got bigger. The perplexity figures above come from an 8B model and are a guide, not a guarantee for every model.

Test on your actual workload rather than trusting a single rule of thumb.

Frequently asked questions

What is the meaning of Q4KM on a model file?

Q4 is the 4-bit base precision, K means a k-quant (weights grouped in blocks, each with its own scale), and M is the medium mix, which stores about half of the attnv and ffndown layers at Q6K. The finished file averages about 4.9 bits per weight, so Llama 3.1 8B at Q4KM is a 4.92 GB file. "q4km" and "Q4K" are the same file type, just as "q5km" and "q4ks" are shorthand for Q5KM and Q4KS.

Q4KM vs Q5KM: which should I use?

Q4KM by default. Q5KM is 16 to 18% larger (5.73 GB against 4.92 GB on Llama 3.1 8B) and llama.cpp lists its added perplexity at +0.0569 against +0.1754 for Q4KM. Choose Q5KM when it fits with room for your context; otherwise spend the memory on context or a bigger model.

Q4KM vs Q4KS: is the S version worth it?

Only in a squeeze. Q4KS saves only 0.23 GB on an 8B model and about 1 GB on a 32B, and llama.cpp lists it at +0.2689 perplexity against +0.1754 for Q4KM. Use it only when Q4KM misses your memory by a small margin.

Q4KM vs Q80: is Q8 worth it?

Only if you have memory to spare. Q80 is about 1.75 times the size of Q4KM, and in llama.cpp's speed table for Llama 3.1 8B it generated about 29% fewer tokens per second. Its added perplexity is tiny (+0.0026), but our pick is to put that memory into a larger model at Q4KM. Use Q80 when you are comparing quants against the original.

Q6K vs Q80: what is the difference?

Both add almost nothing in llama.cpp's table: +0.0217 perplexity for Q6K and +0.0026 for Q80. Q6K is about 23% smaller (6.60 GB against 8.54 GB on Llama 3.1 8B) and generated text faster in llama.cpp's README table, so it is our pick of the two.

What are IQ quants like IQ4XS and IQ3M?

They are i-quants, a newer llama.cpp family that Hugging Face's GGUF documentation describes as using an importance matrix: statistics from sample text that weight which rounding errors matter most. IQ4XS is a little smaller than Q4KS (17.69 GB against 18.77 GB on Qwen3 32B). llama.cpp lists no perplexity figure for the IQ types in its quantize tool. bartowski's model card says they are slower than k-quants on a CPU, and IQ4XS measured slower than Q40 on Apple's Metal when it landed, so test them before relying on them.

How much VRAM does a quantized LLM need?

The file size plus the KV cache, and our rule is to keep at least a gigabyte spare. At Q4KM a dense model is about 0.6 GB per billion parameters, so a 32B model is a 19.76 GB file. Add 2.15 GB of KV cache for 8K tokens of context on Qwen3 32B, and it fits a 24 GB card with little room left.

What is GGUF?

GGUF is a model file format developed by @ggerganov, who is also the developer of llama.cpp. Hugging Face describes it as a binary format optimized for quick loading and saving, and unlike tensor-only formats such as safetensors it stores the model's metadata in the same file. llama.cpp loads GGUF files directly, and the Hugging Face Hub has built-in GGUF support.

Do bigger models tolerate quantization better?

Not reliably. When llama.cpp's k-quants were introduced in June 2023, their author tested LLaMA models from 7B to 65B and found the relative quantization error, measured by perplexity, did not shrink as the models grew. The 13B was the exception, and the 30B and 65B went back to the 7B's level.

What matters more, parameter count or quantization bits?

Our rule is parameter count first, as long as you stay at Q4KM or above. llama.cpp's numbers show every step above Q4KM removing less than 0.12 of perplexity, while the cost climbs steeply below it (+0.6569 at Q3KM, +3.5199 at Q2K). So pick the largest model that fits at Q4KM, then spend any memory left over on more bits or more context.

Sources

  1. Dettmers et al., LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale (arXiv)arxiv.org
  2. Frantar et al., GPTQ: Accurate Post-Training Quantization (arXiv, ICLR 2023)arxiv.org
  3. Lin et al., AWQ: Activation-aware Weight Quantization for LLM Compression (arXiv)arxiv.org
  4. Hugging Face Hub docs: GGUF (format definition; quantization types table: Q4_K 4.5 bpw, Q6_K 6.5625 bpw, IQ types use super-block scale and importance matrix, Q8_0 listed under legacy types)huggingface.co
  5. Hugging Face Transformers docs: KV cache strategies (the cache stores keys and values so they are not recomputed)huggingface.co
  6. llama.cpp quantize tool source: QUANT_OPTIONS (sizes in GiB and perplexity added on Llama 3 8B: Q8_0 +0.0026, Q6_K +0.0217, Q5_K_M +0.0569, Q5_K_S +0.1049, Q4_K_M +0.1754, Q4_K_S +0.2689, Q4_0 +0.4685, Q3_K_M +0.6569, Q2_K +3.5199; Q4_K alias for Q4_K_M)github.com
  7. llama.cpp quantize README (Llama 3.1 8B table: bits per weight, GiB sizes and tokens per second per quant, e.g. Q4_K_M 4.8944 bpw, 4.58 GiB, 71.93 t/s; Q6_K 58.67 t/s; Q8_0 8.5008 bpw, 50.93 t/s; memory table: Llama 3.1 70B Q4_K_M 43.1 GB)github.com
  8. llama.cpp source, src/llama-quant.cpp (Q4_K_M and Q5_K_M store about half of attn_v and ffn_down layers at Q6_K; Q4_K_S upgrades the first few to Q5_K)github.com
  9. llama.cpp common/common.h (KV cache type K and V default to F16)github.com
  10. llama.cpp PR #1684, k-quants by ikawrakow, merged June 2023 (block structure, S/M/L mixes, relative quantization error does not decrease from LLaMA 7B to 65B; inference speed tends to depend on model size)github.com
  11. llama.cpp PR #4773, SOTA 2-bit quants (first i-quants), merged January 2024github.com
  12. llama.cpp PR #4861, importance matrix calculation, merged January 2024github.com
  13. llama.cpp PR #5747, IQ4_XS: a 4.25 bpw quantization, merged February 2024 (Metal 53.9 vs 63.1 t/s for Q4_0 on M2 Max GPU; CUDA 133.7 vs 128.8 t/s on RTX 4080)github.com
  14. Hugging Face, bartowski/Meta-Llama-3.1-8B-Instruct-GGUF file listing (8.03B parameters; Q8_0 8.54 GB, Q6_K 6.60 GB, Q5_K_M 5.73 GB, Q4_K_M 4.92 GB, Q4_K_S 4.69 GB, IQ4_XS 4.45 GB; GGUF header: 32 layers, 8 KV heads)huggingface.co
  15. Hugging Face, bartowski/Qwen_Qwen3-14B-GGUF file listing (14.77B parameters; Q8_0 15.70 GB, Q6_K 12.12 GB, Q5_K_M 10.51 GB, Q4_K_M 9.00 GB)huggingface.co
  16. Hugging Face, bartowski/Qwen_Qwen3-32B-GGUF model card and file listing (32.76B parameters; Q4_K_M 19.76 GB 'default size for most use cases'; IQ4_XS 'smaller than Q4_K_S with similar performance'; _L variants keep embed and output at Q8_0; file 1-2GB smaller than VRAM; I-quants slower on CPU; all quants made with imatrix)huggingface.co
  17. Qwen/Qwen3-32B config.json (64 layers, 8 KV heads, head_dim 128)huggingface.co
  18. Qwen/Qwen3-14B config.json (40 layers, 8 KV heads, head_dim 128)huggingface.co
  19. Ollama library, llama3.1 tags (latest = digest 46e0c10c039e = 8b-instruct-q4_K_M, 4.9GB)ollama.com

Ask about this article

Answered only from this piece. The AI never invents.

React
ShareXLinkedInBluesky

More in ai

More in ai

Discussion