# GGUF quantization explained: Q4_K_M, Q5_K_M or Q8_0

What GGUF is, what Q4_K_M, Q5_K_M, Q8_0, IQ4_XS and imatrix mean, how much quality and memory each quantization costs, and which file to download.

2026-11-27


A GGUF file holds a language model for llama.cpp, the program behind many local AI apps, Hearthscale among them. A name such as `Qwen3.5-9B-Q4_K_M.gguf` also says how the model's weights are stored: `Q4_K_M` is the quantization, the number of bits kept for each weight and the way they are packed. The quantization decides how much memory and disk space a model takes, how fast it writes, and how much of its quality is lost.

This guide explains what the names mean, shows what each quantization costs in quality and size, and helps you choose the file to download. The [sources](#sources) of every number are at the end.

## TL;DR {#tldr}

- **Start with Q4_K_M.** It takes less than a third of the space of the original 16-bit model. On Llama 3.1 8B, its average over five benchmarks was 69.15, against 69.47 for the 16-bit model. See [what each quantization costs](#quality).
- **Take Q5_K_M or Q6_K when your graphics card holds the file whole.** They are closer still to the original, for about a sixth and a third more memory than Q4_K_M.
- **Q8_0 is almost the original, but larger and slower.** It is about 1.7 times the size of Q4_K_M. On the device of llama.cpp's own table, Llama 3.1 8B wrote 51 tokens per second at Q8_0 and 72 at Q4_K_M.
- **Below 4 bits, the loss grows quickly.** On a math test, Q4_K_M lost 0.2 points and Q3_K_S lost 9.3. If you need a 3-bit file, take Q3_K_M or Q3_K_L, made with an [importance matrix](#imatrix).

## What is GGUF? {#what-is-gguf}

GGUF is the file format of llama.cpp and of GGML, the library it is built on. One file holds everything a program needs to load the model: the weights, and metadata such as the architecture, the tokenizer and the chat template. Programs map the file straight into memory, so it loads fast. GGUF replaced the older GGML, GGMF and GGJT files.

Models are first published in other formats, mostly as safetensors files with 16-bit weights, which programs such as Transformers and vLLM read. llama.cpp's `convert_hf_to_gguf.py` turns them into a 16-bit GGUF file, and `llama-quantize` makes each quantization from that file. You rarely need to do this yourself: on Hugging Face, model makers and others publish a GGUF file for each quantization, such as `Qwen3.5-9B-Q4_K_M.gguf`.

The file name follows a convention: the model, its size, the version and the encoding. A large model comes in shards, named `00001-of-00003` and so on, and you need all of them. A file whose name starts with `mmproj` is a vision projector, the part that lets a model read pictures. llama.cpp's guide advises keeping projectors at 16 or 8 bits: they are small, and their quality affects every answer about a picture.

## What is quantization? {#what-is-quantization}

A model's weights are numbers, and the original model stores each one in 16 bits. Quantization stores them in fewer bits. The weights are cut into blocks, and each block keeps one shared scale and a small whole number for each weight. Q8_0, for example, keeps blocks of 32 weights with 8 bits each and a 16-bit scale, which comes to 8.5 bits per weight.

Fewer bits change three things:

- **The size of the file and the memory it needs.** Llama 3.1 8B takes 14.96 GiB at 16 bits, 7.95 GiB at Q8_0 and 4.58 GiB at Q4_K_M.
- **How fast the model writes, down to about 4 bits.** To write each token, the device reads all the weights from memory, so a smaller file writes faster. Below 4 bits, the files shrink further, but on the device of llama.cpp's table, writing got no faster.
- **The quality.** Each weight is rounded, so the model's answers move a little away from the original. The change is small at 5 to 8 bits and grows below 4.

Reading a prompt changes less. On the same device, Llama 3.1 8B read 822 tokens per second at Q4_K_M and 865 at Q8_0.

## What does Q4_K_M mean? {#names}

- **Q and a number:** quantized, with about that many bits for most weights. Q4 is about 4 bits, and Q8 about 8.
- **K:** a k-quant, the family that llama.cpp added in June 2023. Its blocks are grouped in super-blocks of 256 weights, which store the blocks' scales in fewer bits.
- **S, M and L:** small, medium and large mixes. A model has many kinds of tensors, and some matter more than others. When k-quants were added, Q4_K_S used 4-bit blocks for every tensor, and Q4_K_M kept half of two kinds of tensors, `attention.wv` and `feed_forward.w2`, at 6 bits. So an M file is a little larger than an S file, and closer to the original.
- **0 and 1 at the end:** the first formats. A Q4_0 block keeps a scale, and a Q4_1 block a scale and a minimum. Hugging Face calls them legacy formats.
- **IQ:** an i-quant, a family added in 2024 for 1 to 4.5 bits per weight. Its weights are rounded with an [importance matrix](#imatrix). IQ4_XS takes less space than Q4_K_M.
- **F16 and BF16:** 16 bits, not quantized.
- **UD and XL:** Unsloth's dynamic quantizations, such as `UD-Q4_K_XL`. Unsloth chooses the type of each layer for each model, with an importance matrix of its own.
- **QAT:** quantization-aware training. The model maker trains the model for its quantized form, as Google did for the Q4_0 files of Gemma 4.
- **MXFP4:** a 4-bit floating-point format. OpenAI post-trained gpt-oss with its mixture-of-experts weights in MXFP4, and its GGUF files keep that format.

The table shows each common type on Llama 3.1 8B, from llama.cpp's own documentation. The bits per weight count the whole file, so Q4_K_M comes to 4.89. The perplexity added is llama.cpp's figure for Llama 3 8B, the model before it: the lower, the closer to the original. llama.cpp gives no perplexity figure for the i-quants. The writing speed comes from the same table, on one device that it does not name, in tokens per second.

| Type   | Bits per weight | File size, GiB | Perplexity added | Writing speed |
| ------ | --------------- | -------------- | ---------------- | ------------- |
| F16    | 16.00           | 14.96          | Reference        | 29            |
| Q8_0   | 8.50            | 7.95           | +0.0026          | 51            |
| Q6_K   | 6.56            | 6.14           | +0.0217          | 59            |
| Q5_K_M | 5.70            | 5.33           | +0.0569          | 67            |
| Q5_K_S | 5.57            | 5.21           | +0.1049          | 70            |
| Q4_K_M | 4.89            | 4.58           | +0.1754          | 72            |
| Q4_K_S | 4.67            | 4.36           | +0.2689          | 77            |
| IQ4_XS | 4.46            | 4.17           | Not given        | 78            |
| Q3_K_L | 4.30            | 4.02           | +0.5562          | 69            |
| Q3_K_M | 4.00            | 3.74           | +0.6569          | 72            |
| IQ3_M  | 3.76            | 3.52           | Not given        | 70            |
| Q3_K_S | 3.64            | 3.41           | +1.6321          | 70            |
| Q2_K   | 3.16            | 2.95           | +3.5199          | 80            |
| IQ2_M  | 2.93            | 2.74           | Not given        | 74            |
| IQ1_S  | 2.00            | 1.87           | Not given        | 80            |

From Q8_0 down to Q4_K_S, each step gives a smaller file and faster writing. Below that, the perplexity grows faster than the file shrinks, and writing gets no faster.

## How much quality do you lose? {#quality}

Perplexity measures how well a model predicts a known text; the lower, the better. It is a quick test, but it does not show everything: two files with the same perplexity can do differently on a task. A study from January 2026 tested Llama 3.1 8B Instruct in each common quantization, on math (GSM8K), knowledge (MMLU), following instructions (IFEval) and two more benchmarks, all with llama.cpp.

| Type   | Share of the 16-bit size | Math (GSM8K) | Knowledge (MMLU) | Instructions (IFEval) | Average of five | Perplexity |
| ------ | ------------------------ | ------------ | ---------------- | --------------------- | --------------- | ---------- |
| F16    | 100%                     | 77.63        | 63.50            | 78.93                 | 69.47           | 7.32       |
| Q8_0   | 53%                      | 77.48        | 63.43            | 78.79                 | 69.41           | 7.33       |
| Q6_K   | 41%                      | 78.17        | 63.17            | 77.63                 | 69.23           | 7.35       |
| Q5_K_M | 36%                      | 78.54        | 62.80            | 78.67                 | 69.36           | 7.40       |
| Q5_0   | 35%                      | 79.08        | 63.18            | 80.14                 | 69.92           | 7.43       |
| Q4_K_M | 31%                      | 77.41        | 62.43            | 79.06                 | 69.15           | 7.56       |
| Q4_K_S | 29%                      | 77.33        | 62.06            | 80.26                 | 69.17           | 7.62       |
| Q4_0   | 29%                      | 75.66        | 62.20            | 77.46                 | 67.98           | 7.74       |
| Q3_K_L | 27%                      | 74.07        | 62.31            | 79.14                 | 68.78           | 7.81       |
| Q3_K_M | 25%                      | 73.16        | 62.01            | 77.19                 | 68.07           | 7.96       |
| Q3_K_S | 23%                      | 68.31        | 59.31            | 73.89                 | 65.49           | 8.96       |

What the numbers show:

- **From 4 to 8 bits, the scores stay close to the original.** Some files scored a little higher than the 16-bit model. The study's author warns that such small gains can be noise in the tests.
- **Math suffers first.** At Q3_K_S, the math score fell by 9.3 points, and knowledge by 4.2.
- **The format matters, not only the bits.** Q3_K_M and Q3_K_L lost much less than Q3_K_S. Q4_0, the old format, averaged 1.2 points below Q4_K_S at the same size.
- **These are the results of one model with 8 billion parameters.** Other models may lose more or less, so treat the numbers as a guide, not as a rule.

## What is an imatrix? {#imatrix}

An importance matrix records which weights matter most while a model reads a sample of text. `llama-imatrix` makes one, and `llama-quantize --imatrix` uses it to round the important weights more carefully. The result is an ordinary GGUF file of the same type and size, and every program that runs GGUF runs it. Some repositories hold the importance matrix itself, a file with `imatrix` in its name. You don't need it to run the model.

When llama.cpp added the importance matrix to every k-quant, its author measured Mistral 7B with and without it. The table shows how much the perplexity rose above the 16-bit model.

| Type   | Without an importance matrix | With an importance matrix |
| ------ | ---------------------------- | ------------------------- |
| Q2_K   | 18.72%                       | 12.90%                    |
| Q3_K_S | 6.62%                        | 5.44%                     |
| Q3_K_M | 3.46%                        | 2.75%                     |
| Q4_K_S | 1.48%                        | 0.89%                     |
| Q4_K_M | 1.08%                        | 0.75%                     |
| Q5_K_S | 0.59%                        | 0.32%                     |
| Q5_K_M | 0.53%                        | 0.30%                     |
| Q6_K   | 0.18%                        | 0.15%                     |

The importance matrix helps most at the lowest bits. At 3 bits and below, choose a file made with one. The model card usually says whether the files were.

## Q4_K_M vs IQ4_XS vs UD-Q4_K_XL {#4-bit}

Most models come in several 4-bit files. These are the sizes of two current models, from their repositories on Hugging Face:

| File          | Qwen3.5 9B | Gemma 4 12B |
| ------------- | ---------- | ----------- |
| Q3_K_M        | 4.67 GB    | 5.69 GB     |
| IQ4_XS        | 5.17 GB    | 6.38 GB     |
| Q4_K_M        | 5.68 GB    | 7.12 GB     |
| UD-Q4_K_XL    | 5.97 GB    | 7.37 GB     |
| QAT Q4_0      | None       | 6.98 GB     |
| Q5_K_M        | 6.58 GB    | 8.41 GB     |
| Q6_K          | 7.46 GB    | 9.79 GB     |
| Q8_0          | 9.53 GB    | 12.67 GB    |
| BF16, 16 bits | 17.92 GB   | 23.83 GB    |

- **IQ4_XS** is about a tenth smaller than Q4_K_M. Take it when your graphics card holds IQ4_XS whole, but not Q4_K_M.
- **UD-Q4_K_XL**, from Unsloth, is 3 to 5 percent larger than Q4_K_M.
- **QAT Q4_0** comes from Google, the maker of Gemma 4, which trained the model for this format. Google publishes Gemma 4 as GGUF in this form.

A vision model also needs its projector: 0.92 GB at 16 bits for Qwen3.5 9B, and 0.18 GB for Gemma 4 12B.

## Which quantization should you use? {#choose}

Replies come fastest when your graphics card holds the whole file, with room for the context: the conversation and the files you give it. Hearthscale's recommendations count 15 percent of the file size for the context, and at least 1.5 GB, and Hearthscale Server keeps 512 MB of graphics memory for other programs. By that rule, for the model file alone:

- **8 GB of graphics memory:** Qwen3.5 9B at Q4_K_M, 7.2 GB with the context. Its Q5_K_M file, 8.1 GB with the context, does not stay whole on the card. Gemma 4 12B at 3 bits.
- **12 GB:** Qwen3.5 9B at Q8_0, 11.0 GB with the context, or Gemma 4 12B at Q6_K, 11.3 GB.
- **16 GB:** Gemma 4 12B at Q8_0, 14.6 GB with the context.

A vision model's projector adds its own size.

To choose:

1. **Choose the model first.** Then take the largest quantization, from Q4_K_M up to Q8_0, that your graphics card holds whole with room for the context.
2. **If no 4-bit file of the model stays whole on your card,** choose a smaller model, or let part of the model run in system memory, which is slower. The guides for [NVIDIA](/blog/local-ai-nvidia-gpu#memory), [AMD](/blog/local-ai-amd-gpu#memory) and [Intel Arc](/blog/local-ai-intel-gpu) cards list the models that each size holds.
3. **With no graphics card,** the processor writes faster from a smaller file, and Q4_K_M is a good start. See [Run a local LLM without a GPU](/blog/local-ai-without-gpu).
4. **A mixture-of-experts model,** such as one named 35B-A3B, needs memory for all its weights, but only a part of them computes each token. Its replies come much faster than those of a dense model of the same size, also when part of it is in system memory.

To see the models recommended for your memory, with their sizes, choose your graphics card and system memory on [What AI models can your device run?](/what-can-i-run)

## Quantizing the KV cache {#kv-cache}

While a model works, it keeps the context in its KV cache, in memory beside the weights. A long context can take several gigabytes. llama.cpp stores the cache at 16 bits unless you set another type, and the `q8_0` type takes 8.5 bits, about half the memory. In tests by a llama.cpp developer, an 8-bit cache changed the perplexity less than a 5- or 4-bit one.

In Hearthscale Server, the cache types are among the **Memory and cache options** of a model's **Load** tab. A quantized V cache needs flash attention. See [Model settings](/docs/server/models/settings#load). How much memory a long context takes differs by model: [the context of a coding agent](/blog/local-llm-for-coding#context) compares eight models.

## Downloading a quantization in Hearthscale {#hearthscale}

In Hearthscale Server, open **Explore**. **Recommended** lists the models recommended for this device, with the files of each model. Choose a model, then a file under **Download options**. The mark below the file shows whether your graphics card holds the whole model (**Full GPU offload possible**) or part of it (**Partial GPU offload possible**), or whether the file is likely too large for the device. Hover over the mark to see the sizes used in the estimate.

:::figure{caption="A model in Explore. The mark below the file shows that the graphics card holds the whole model."}
![Explore with Qwen3 0.6B selected, its Q8_0 file of 610 MB, a Download button and Full GPU offload possible.](https://hearthscale.com/docs/images/server-explore.jpg)
:::

If the model's own repository has no GGUF file, choose a converted version under **Download source**. **Model tree** lists the quantizations, finetunes, adapters and merges of the model. See [Find and download models](/docs/server/models/explore).

You can also install a file from a terminal, by its quantization:

```sh
hearthd models install Qwen/Qwen3-8B-GGUF --file Q4_K_M
```

Already have a GGUF file? `hearthd models import model.gguf` copies it into the library. See [Models](/docs/cli/use/models) in the command-line documentation.

[Download Hearthscale](/download) for Windows or Linux. Hearthscale is free, and you need no account.

## Sources {#sources}

Read on 27 November 2026. The sizes with the context are arithmetic by the rule above, not results.

- llama.cpp, [`llama-quantize`](https://github.com/ggml-org/llama.cpp/blob/master/tools/quantize/README.md): the bits per weight, file sizes and speeds of Llama 3.1 8B, and the advice on projectors; [`quantize.cpp`](https://github.com/ggml-org/llama.cpp/blob/master/tools/quantize/quantize.cpp): the perplexity added on Llama 3 8B.
- llama.cpp, [k-quants](https://github.com/ggml-org/llama.cpp/pull/1684) (June 2023) for the mixes, [SOTA 2-bit quants](https://github.com/ggml-org/llama.cpp/pull/4773) (January 2024), [the importance matrix for all k-quants](https://github.com/ggml-org/llama.cpp/pull/4930) (January 2024) for the Mistral 7B table, [`llama-imatrix`](https://github.com/ggml-org/llama.cpp/blob/master/tools/imatrix/README.md), the [cache types of `llama-server`](https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md) and the [tests of a quantized KV cache](https://github.com/ggml-org/llama.cpp/pull/7412) (May 2024).
- GGML, [the GGUF specification](https://github.com/ggml-org/ggml/blob/master/docs/gguf.md), and Hugging Face, [GGUF](https://huggingface.co/docs/hub/gguf), with the layout of each quantization type.
- Uygar Kurt, [Which Quantization Should I Use? A Unified Evaluation of llama.cpp Quantization on Llama-3.1-8B-Instruct](https://arxiv.org/abs/2601.14277), arXiv, January 2026: the benchmark scores.
- File sizes, read through the Hugging Face API: Unsloth, [Qwen3.5-9B-GGUF](https://huggingface.co/unsloth/Qwen3.5-9B-GGUF) and [gemma-4-12b-it-GGUF](https://huggingface.co/unsloth/gemma-4-12b-it-GGUF); Google, [gemma-4-12B-it-qat-q4_0-gguf](https://huggingface.co/google/gemma-4-12B-it-qat-q4_0-gguf).
- Unsloth, [Dynamic GGUFs](https://unsloth.ai/docs/basics/dynamic-3.0-ggufs), and OpenAI, the [gpt-oss-20b](https://huggingface.co/openai/gpt-oss-20b) model card.
