- Key idea
- fp32’s three fields: 1 sign bit, 8 exponent bits, 23 mantissa bits; value = sign × 2^exponent × 1.mantissa
- Real world
- Scientific notation: Avogadro’s number is 6.022 × 10²³. “10²³” says how big; “6.022” says exactly which number of that size. A float does the same with powers of two.
- In an LLM
- A weight like 0.0123 is stored in bf16 as about 1.578 × 2⁻⁷: exponent −7 and mantissa 1.57. Quantization formats differ mainly in how many bits they give each part.
Scientific notation, again
Writing very large and very small numbers in ordinary digits is clumsy: 602,200,000,000,000,000,000,000. Scientific notation splits a number into two parts:
- The exponent (23) says the scale: how many places to move the decimal point.
- The significand (6.022) says the digits: exactly which number at that scale.
With just four significant digits you can write the mass of an electron or of a galaxy. You lose the digits beyond the fourth, but you never run out of room.
The same idea in binary
A floating-point number does exactly this with base 2. A 32-bit float (fp32) has three fields:
| Field | Bits | Job |
|---|---|---|
| Sign | 1 | 0 for positive, 1 for negative |
| Exponent | 8 | which power of two: the number is between and |
| Mantissa (or fraction) | 23 | where exactly the number sits between those two powers |
Two details make this work:
- The bias. The 8 exponent bits store a number from 0 to 255. Subtracting 127 turns that into exponents from −126 to +127 (the two extreme patterns are reserved), so tiny and huge numbers are both possible.
- The hidden 1. In binary scientific notation the leading digit is always 1 (just as the first digit in decimal scientific notation is never 0), so it isn’t stored. The 23 mantissa bits are the digits after the binary point, and you get 24 bits of precision for the price of 23.
Try it
Things to try:
- Start from 1 and press × 2 a few times. The exponent goes up by one each time, and the mantissa bits don’t change at all. ÷ 2 does the reverse.
- Look at the small numbers under the bits. Mantissa bits are worth ½, ¼, ⅛, …: add up the lit ones, put “1 +” in front, and you get the blue number in “putting the three parts together”.
- Type 0.1. It can’t be stored exactly, for the same reason 1/3 can’t be written exactly in decimal. fp32 stores 0.100000001490116…
- Switch to bf16 and type 0.1 again: only 7 mantissa bits remain, and the error grows to about 0.0001.
- Try 65504 in fp16, then press × 2. Its 5 exponent bits run out, and the number becomes infinity.
- Flip the last mantissa bit of any number and see how little it changes; flip the top exponent bit and see how much.
Decoding one by hand
- 5.5 is positive, so the sign bit is 0.
- Find the power of two just below it: . So .
- Exponent: , which is
10000001in binary. - Mantissa: the part after “1.” is 0.375 = 0.25 + 0.125, i.e. binary
.011. So the 23 mantissa bits are0110000…0.
Reading it back: . Exact, because 5.5 is a sum of powers of two.
A weight of 0.0123 sits between and , so its exponent is −7 and . bf16 has only 7 mantissa bits, so 1.574 must be rounded to a multiple of : . The stored weight is , off by about 0.24%. That rounding is already a mild quantization; every model trained in bf16 lives with it.
Why the parts behave so differently
The exponent and mantissa do very different jobs, and that explains most of this course:
- Exponent bits buy range. Each extra exponent bit roughly squares the largest and smallest numbers you can write. fp32’s 8 exponent bits reach about .
- Mantissa bits buy precision. Each extra mantissa bit halves the spacing between neighbouring numbers. With 23 bits, neighbours differ by about one part in 8 million; with bf16’s 7 bits, about one part in 128.
The next page shows what that spacing looks like on a number line: where floats are dense and sparse.
Where this shows up
- The spacing of representable values: where floats are dense and sparse.
- How fp16, bf16, fp8 and fp4 split their bits: fp32, fp16, bf16, fp8, fp4.
- Microscaling formats share one exponent across a block of values: FP8, MXFP4 and NVFP4.
IEEE 754
For a format with exponent bits, mantissa bits and bias , a stored exponent field and mantissa field give:
For fp32, , , : the largest value is , the smallest normal , and the smallest subnormal .
Machine epsilon, the gap between 1 and the next float, is : about for fp32 and for bf16. Rounding to nearest gives a relative error of at most half of that.
Rounding
The default rounding mode is round to nearest, ties to even: when a value is exactly halfway between two floats, pick the one whose last mantissa bit is 0. It avoids the slow upward drift that “round half up” causes when millions of values are summed. Some low-precision training recipes instead use stochastic rounding, which rounds up with probability proportional to the distance, so the expected value is preserved.