FP32 vs BF16 vs FP16 vs FP8: AI Number Formats Explained
FP32, BF16, FP16 and FP8 trade range and precision for speed and memory. How each AI number format works and when training or inference uses it.
FP32, BF16, FP16, and FP8 are floating-point number formats that differ in how many bits they spend on each number, and how they split those bits between range (how big or small a value can get) and precision (how finely values are spaced). Modern AI hardware is built around the smaller formats because halving the bits per number roughly halves memory traffic and lets the chip do more math per cycle. The art is choosing a format small enough to be fast but large enough that the model still learns and answers correctly.
How a floating-point number is built
Every IEEE-style float has three fields: a sign bit, an exponent, and a mantissa (also called the significand or fraction). The exponent sets the scale — roughly, which power of two the number sits near. The mantissa sets the digits within that scale. More exponent bits widen the range; more mantissa bits sharpen the precision. If you want a refresher on why floats behave the way they do, see floating-point arithmetic explained.
With a fixed bit budget, every extra exponent bit is a mantissa bit you gave up. That single trade-off explains almost everything about the formats below.
The formats side by side
| Format | Total bits | Exponent bits | Mantissa bits | Range | Precision | Typical use |
|---|---|---|---|---|---|---|
| FP32 | 32 | 8 | 23 | Wide | High (~7 decimal digits) | Master weights, optimizer state, reference math |
| FP16 | 16 | 5 | 10 | Narrow | Moderate (~3 decimal digits) | Inference, older mixed-precision training |
| BF16 | 16 | 8 | 7 | Same as FP32 | Low (~2 decimal digits) | Default for modern training |
| FP8 (E4M3) | 8 | 4 | 3 | Very narrow | Very low | Forward pass in training, inference |
| FP8 (E5M2) | 8 | 5 | 2 | Narrow | Lowest | Gradients in training |
FP32: the reference
Single precision was the default for deep learning for years. It has enough range and precision that you rarely think about numerical problems. The cost is size: four bytes per value. A model with billions of parameters stored in FP32 needs a lot of memory just to hold the weights, before activations, gradients, or optimizer state.
FP16: half the bits, a narrow range
FP16 keeps a decent mantissa but has only five exponent bits. Its largest representable value is in the tens of thousands, and very small values quickly underflow to zero. That matters in training, where gradients are often tiny. The classic fix is loss scaling: multiply the loss by a large factor before backpropagation so gradients stay representable, then divide it back out before the weight update. It works, but it adds a moving part that can fail with overflow if the scale is set too high.
BF16: FP32’s range in 16 bits
Brain floating point takes a different approach. It keeps FP32’s eight exponent bits and simply chops the mantissa down to seven. The result has the same range as FP32 — no underflow headaches, usually no loss scaling — at the cost of coarse precision. Neural networks turn out to be remarkably tolerant of imprecise individual values as long as nothing overflows or vanishes, which is why BF16 became the default training format on hardware that supports it. Converting FP32 to BF16 is also trivial: drop the low 16 bits (with rounding).
FP8: two flavors for two jobs
At eight bits the trade-off gets sharp enough that there are two common variants. E4M3 (four exponent bits, three mantissa bits) favors precision and is used for weights and activations in the forward pass. E5M2 (five exponent, two mantissa) favors range and suits gradients, which span many orders of magnitude. Because FP8’s range is so limited, values are typically paired with scaling factors — per tensor or per block — that shift each group of numbers into the range the format can represent.
Why smaller formats are faster
Two effects stack. First, memory bandwidth: an LLM generating text is usually limited by how fast weights stream from memory, not by arithmetic. Halving the bytes per weight nearly halves the time to read them, which is why memory bandwidth vs latency matters so much for inference and why accelerators lean on HBM. The decode phase described in prefill vs decode is the clearest example.
Second, compute density: matrix units such as the ones covered in CUDA cores vs tensor cores process more low-precision multiply-accumulates per clock than high-precision ones, because smaller multipliers take less silicon and power. Moving from 16-bit to 8-bit math typically doubles peak throughput on hardware that supports both.
Mixed precision: using several formats at once
Real training rarely uses a single format. Mixed precision keeps a master copy of the weights in FP32, runs the heavy matrix multiplications in BF16 or FP8, and accumulates the results of those multiplications in a wider format so rounding errors don’t pile up across thousands of additions. Optimizer state — such as the running averages Adam keeps — usually stays in FP32 because small updates would otherwise round away to nothing.
The rule of thumb: do the bulk multiplications in the narrowest format that works, and keep anything that accumulates over time (sums, weight updates, statistics) in a wider one.
Floats vs integers for inference
Inference often goes further than FP8 by using integer formats such as INT8 or INT4. That is a different technique — quantization maps a range of real values onto evenly spaced integers with a scale factor — but the motivation is the same: fewer bytes per weight, more weights per second. Floating-point formats spread their precision logarithmically, which suits values that span wide ranges; integers spread it evenly, which suits weights clustered around zero once they are scaled.
Picking a format
- Training from scratch: BF16 for matrix math with FP32 master weights is the safe, widely supported choice. FP8 training can be faster but needs careful scaling and hardware support.
- Fine-tuning: BF16 is the usual default; it rarely needs special handling.
- Inference: FP16 or BF16 is the lossless-in-practice baseline. FP8 or integer quantization cuts memory and cost further, with a quality check required for each model.
- Numerically sensitive steps: softmax, normalization layers, and loss computation are often kept in FP32 even inside a lower-precision model.
The takeaway
Floating-point formats are a trade between exponent bits (range) and mantissa bits (precision). FP32 is the comfortable reference, FP16 halves the size but needs loss scaling, BF16 keeps FP32’s range with less precision and is the modern training default, and FP8 doubles throughput again with scaling factors to keep values in range. Production systems mix them: narrow formats for the heavy math, wide formats for anything that accumulates.
Tagged
Keep reading
Chisato · · 5 min read FlashAttention Explained: Faster, Memory-Aware Attention
FlashAttention computes exact transformer attention without storing the full attention matrix in GPU memory. How tiling and online softmax make it faster.
Chisato · · 3 min read What Is a GPU? Why AI Runs on Graphics Chips
A GPU packs thousands of small cores built for parallel arithmetic. Originally for graphics, it's now the engine behind training and running AI models.
Chisato · · 5 min read State Space Models Explained: Mamba and Linear-Time AI
State space models like Mamba process sequences with a fixed-size hidden state instead of attention, scaling linearly with length. How they work and compare.