FP16 - Half Precision

IEEE 754 half-precision floating point: compact and efficient for ML inference and graphics

Bit Layout

An FP16 number uses 16 bits divided into three fields:

Sign
S
1 bit
Exponent
E
E
E
E
E
5 bits
Mantissa
M
M
M
M
M
M
M
M
M
M
10 bits

The sign bit determines positive (0) or negative (1). The exponent is stored with a bias of 15. The mantissa stores 10 bits of fractional precision.

Overview

FP16, also known as half precision, was added to the IEEE 754-2008 standard as a storage and interchange format. At just 16 bits, it uses half the memory of FP32, making it attractive for applications where memory bandwidth is a bottleneck.

With only 5 exponent bits, FP16 has a much narrower range than FP32, with a maximum value of only 65,504. This means large values (like loss values in deep learning) can easily overflow to infinity. However, for values within its range, the 10 mantissa bits provide about 3.3 decimal digits of precision.

FP16 is widely used in ML inference, computer graphics (HDR textures), and as a storage format on GPUs. NVIDIA's Tensor Cores can perform FP16 matrix multiplications at 2× the throughput of FP32.

FP16 vs BF16 FP16 and BF16 are both 16-bit formats, but they make different trade-offs. FP16 has higher precision (10 mantissa bits vs 7) but much narrower range (max ~65K vs ~3.4×1038). BF16's wider range makes it better for training, while FP16's precision makes it good for inference.

Encoding Rules

Normal Numbers

value = (-1)sign × 2(exponent - 15) × (1 + mantissa / 210)

Normal FP16 numbers have a biased exponent between 1 and 30 (actual exponent -14 to +15). The bias of 15 is calculated as 2(e-1) - 1, where e is the number of exponent bits (5).

Subnormal Numbers

value = (-1)sign × 2-14 × (0 + mantissa / 210)

Subnormals bridge the gap between the smallest normal number and zero, enabling gradual underflow.

Special Values

Interactive Value Visualizer

Click any bit to flip it, drag the slider, or enter a decimal or hex value. The graphs show how values are distributed across the encoding space.

Dynamic Range & Precision

PropertyValue
Max Positive (Normal)65504
Min Positive (Normal)0.00006103515625
Max Subnormal0.00006097555161
Min Positive (Subnormal)5.960464478e-8
Machine Epsilon (at 1.0)0.0009765625
Approx. Decimal Digits~3.0
Exponent Bias15
Exponent Range2^-14 to 2^15
Total Bit Patterns65,536
Supports InfinityYes
Supports NaNYes

Special Values & Bit Patterns

ValueBit PatternDecimal
+00 00000 00000000000
-01 00000 0000000000-0
Min Subnormal0 00000 00000000015.960464478e-8
Max Subnormal0 00000 11111111110.00006097555161
Min Normal0 00001 00000000000.00006103515625
Max Normal0 11110 111111111165504
+Infinity0 11111 0000000000+Infinity
-Infinity1 11111 0000000000-Infinity
NaN0 11111 1000000000NaN

Format Comparison

PropertyFP16FP32BF16FP8 E5M2
Total Bits1632168
Sign Bits1111
Exponent Bits5885
Mantissa Bits102372
Bias1512712715
Max Value655043.402823466e+383.389531389e+3857344
Min Normal0.000061035156251.175494351e-381.175494351e-380.00006103515625
Epsilon0.00097656251.192092896e-70.00781250.25
~Decimal Digits~3.0~6.9~2.1~0.6
Has InfinityYesYesYesYes
Has NaNYesYesYesYes
Has SubnormalsYesYesYesYes

Where FP16 Is Used

Limited range FP16 overflows above 65,504 and underflows below ~6×10-8 (normal range). Loss values, gradient norms, and intermediate activations can exceed these bounds. If you encounter frequent infinities or zeros, consider BF16 (wider range) or add loss scaling.