QuantizationFloating point

What is inside a number?

How floating-point numbers split their bits between range and precision, from FP32 down to the 4-bit floats behind MXFP4 and NVFP4.

ContentsSign, significand, exponent

I wrote this as the opening of How much precision does intelligence need?, my article on LLM quantization, but it made that one way too long. You don’t need it to follow the other article. But if you ever wondered what FP16, BF16 or FP4 actually mean, this is the short version.

Sign, significand, exponent

You might remember Avogadro’s constant from chemistry class:

NA=+6.02214076⋅1023 mol−1N_A = \textcolor{blue}{+}\textcolor{red}{6.02214076}\cdot 10^{\textcolor{green}{23}}\ \mathrm{mol}^{-1}

The +\textcolor{blue}{+} sign tells us whether the value is positive or negative. The 6.02214076\textcolor{red}{6.02214076} is the significand, it carries the digits. The 23\textcolor{green}{23} is the exponent, it sets the scale.

Binary floating-point works the same way, just with 0s and 1s and powers of 2 instead of powers of 10. So a binary number looks like 1.1012×231.101_2 \times 2^3, where 1.10121.101_2 is the significand and 33 is the exponent.

The bits that store the number are split into a sign\textcolor{blue}{\text{sign}}, an exponent\textcolor{green}{\text{exponent}} and a fraction\textcolor{red}{\text{fraction}}. The fraction holds the bits after the leading 1 of the significand, so for 1.10121.101_2 it stores 101. The leading 1 is known in advance, so it does not need to be stored.

Ignoring some details of how the exponent is encoded (there’s a bit of bias trickery involved), we can think of the value as:

x=(−1)s⋅significand⋅2ex = (-1)^{\textcolor{blue}{s}} \cdot \textcolor{red}{\text{significand}} \cdot 2^{\textcolor{green}{e}}

Where the bits go

There are many ways to split those bits. FP32 and FP16 are defined by IEEE 754. BF16 follows the same broad design, while the FP8 and FP4 encodings below come from the Open Compute Project’s FP8 and Microscaling specifications.

More exponent bits give us a wider range, from very small to very large numbers. More fraction bits give us more precision. Every format makes its own split:

FormatSignExponentFractionNotes
FP321823wide range & high precision
FP161510less range but more precision than BF16
BF16187FP32’s exponent range, lower precision
FP8 143
You should get the gist by now+precision -range
FP8 E5M2152more range, less precision
FP4 E2M1121not much headroom here!

Exponent bits buy range. Fraction bits buy precision.

FP16 (Half Precision) and BF16 (Brain Floating Point) show this really well. Both use 16 bits, but FP16 gives more of them to the fraction, while BF16 keeps the same eight-bit exponent as FP32. Avogadro’s number wasn’t chosen by accident! It is so large that the difference becomes easy to see:

Comparison of Avogadro's constant in FP16 and BF16: FP16 lacks the necessary exponent range, while BF16 can represent an approximation

BF16 has enough range for Avogadro’s number and FP16 does not. But for values that fit in both, FP16 is the more precise one.

Sixteen possible patterns

Once we get down to 4 bits, there are not many options left. Four bits give us 24=162^4 = 16 patterns (from 0000 to 1111) and that’s it. What those 16 patterns mean depends on the format. With INT4 they are evenly spaced integers, with FP4 they follow a floating-point layout.

Probably easier to see than to explain:

Four-bit floating-point numbers represented in a grid

  • INT4 uses a uniform grid (−8 to 7) with a constant step size of 1.
  • FP4 E2M1 uses uneven spacing, keeping values close together near zero (0.5 apart) while taking larger jumps for bigger numbers (like 4 straight to 6).

The spacing between these points matters because it decides how closely we can approximate the values in between. INT4 keeps the gap fixed at 1. FP4 has small gaps near zero and bigger ones as the values grow, so it is more precise for small values and can still reach larger ones with the same four bits. E2M1 also spends two patterns on +0+0 and −0-0, so its 16 codes only give 15 distinct values.

FP4 in real models

Four bits on their own don’t get you very far, since E2M1 tops out at 6. So the formats that use it store the values in groups and give every group a shared scale. I explain why that works in the quantization article. Here I only want to show what it costs.

MXFP4 and NVFP4 are two good examples. Both use the E2M1 values from above, but they make different choices about the groups and scales around them.

MXFP4 groups 32 values together and stores an 8-bit E8M0 scale for each group. E8M0 uses all eight bits for the exponent, so the scale can only be a power of two:

32⋅4+832=4.25 bits per weight (bpw)\frac{32 \cdot 4 + 8}{32} = 4.25 \text{ bits per weight (bpw)}

NVFP4 uses smaller groups of 16 and an 8-bit E4M3 scale:

16⋅4+816=4.50 bpw\frac{16 \cdot 4 + 8}{16} = 4.50 \text{ bpw}

That extra quarter of a bit buys two things:

  • a scale for every 16 values instead of every 32
  • a scale that can sit between powers of two, not just on them

NVFP4 also adds a second FP32 scale shared across the whole tensor, but spread over that many weights it costs almost nothing per value.

So a “4-bit” format is not exactly 4 bits per weight, because the scales take space too. The same thing happens in llama.cpp’s GGUF formats, and that is what the other article is about.


All writing