IEEE 754 Floating-Point Representation: Explanation and Worked Examples
IEEE 754 defines how real numbers are encoded as fixed-width binary values, so that computers can approximate real arithmetic with predictable rules for normalization, rounding, and special cases (e.g., , infinities, NaNs). The core idea is that a floating-point number is represented as a sign plus an exponent plus a significand (mantissa) with an implied binary structure. Key concepts include: floating-point representation , significand , exponent bias , and subnormal number.
The IEEE 754 value formula for normalized numbers (base 2) has the form:
where:
- is the sign bit,
- is the fraction field interpreted as a binary fraction,
- is the stored exponent interpreted as an integer,
- is the exponent bias (e.g., 127 for binary32, 1023 for binary64).
IEEE 754 also defines encodings for:
- : exponent and fraction fields are all zero,
- subnormals: exponent field is zero but fraction is nonzero,
- infinities: exponent all ones and fraction all zeros,
- NaN (Not a Number): exponent all ones and fraction nonzero.
These rules make representations comparable in a consistent way and ensure operations follow the standard’s rounding behavior.
Footnotes
-
IEEE 754 overview and rounding concepts (IEEE 754 standard explanation) https://en.wikipedia.org/wiki/IEEE_754 - Describes IEEE 754 floating-point formats, special values, and rounding concepts. ↩
-
IEEE 754 binary32 details https://en.wikipedia.org/wiki/IEEE_754#Single-precision:_binary32 - Field sizes (1/8/23), exponent bias 127, and special-case classification. ↩
-
IEEE 754 binary64 details https://en.wikipedia.org/wiki/IEEE_754#Double-precision:_binary64 - Field sizes (1/11/52) and exponent bias 1023, plus normalized/subnormal structure. ↩
-
Rounding modes and round-to-nearest ties-to-even https://en.wikipedia.org/wiki/IEEE_754#Rounding - Explains IEEE 754 rounding rules, including round-to-nearest and ties-to-even. ↩
IEEE 754 Floating Point Explained (binary32/binary64, special cases)
IEEE 754 formats (binary32 and binary64)
Two common IEEE 754 formats are:
- binary32 (commonly called “single precision”): 32 bits total,
- binary64 (commonly called “double precision”): 64 bits total.
binary32 (single precision)
It uses:
- 1 sign bit,
- 8 exponent bits,
- 23 fraction bits.
The exponent bias is and the stored exponent is interpreted as:
- if : normalized,
- if : subnormal or zero,
- if : infinity or NaN. binary32
binary64 (double precision)
It uses:
- 1 sign bit,
- 11 exponent bits,
- 52 fraction bits.
The exponent bias is and the same exponent-field classification idea applies with exponent all-ones and all-zeros. binary64
Footnotes
-
IEEE 754 binary32 details https://en.wikipedia.org/wiki/IEEE_754#Single-precision:_binary32 - Field sizes (1/8/23), exponent bias 127, and special-case classification. ↩
-
IEEE 754 binary64 details https://en.wikipedia.org/wiki/IEEE_754#Double-precision:_binary64 - Field sizes (1/11/52) and exponent bias 1023, plus normalized/subnormal structure. ↩
Worked example (binary32): encode and decode 13.25
- 1Step 1
Convert to binary: and , so .
- 2Step 2
For IEEE 754 normalized numbers, the significand is . So shift: . Thus the exponent is and (remaining bits padded with zeros).
- 3Step 3
The number is positive, so .
- 4Step 4
For binary32, bias . Stored exponent is . In binary, .
- 5Step 5
The fraction field stores bits after the leading 1 in . Here followed by zeros to fill 23 bits: fraction = (exactly 23 bits total).
- 6Step 6
Bit layout: (fraction padded with zeros).
- 7Step 7
"Decoding yields ."
This example matches IEEE 754’s normalized-number rule and binary32 field sizes. normalized
Footnotes
-
IEEE 754 binary32 details https://en.wikipedia.org/wiki/IEEE_754#Single-precision:_binary32 - Field sizes (1/8/23), exponent bias 127, and special-case classification. ↩
-
IEEE 754 binary64 details https://en.wikipedia.org/wiki/IEEE_754#Double-precision:_binary64 - Field sizes (1/11/52) and exponent bias 1023, plus normalized/subnormal structure. ↩
-
Worked example (binary32): interpret a special value ( and NaN)
IEEE 754 uses exponent all ones to represent special values:
- exponent all ones and fraction all zeros ,
- exponent all ones and fraction nonzero NaN.
For binary32:
- exponent field = (all ones),
- fraction field = all zeros infinity,
- fraction field NaN (payload varies by fraction bits). NaN
Concrete bit patterns (conceptual):
- , , fraction=0 ,
- , , fraction=0 .
Footnotes
-
IEEE 754 binary32 details https://en.wikipedia.org/wiki/IEEE_754#Single-precision:_binary32 - Field sizes (1/8/23), exponent bias 127, and special-case classification. ↩
Subnormal numbers (underflow region) and the hidden-leading-1 rule
For normalized IEEE 754 numbers, the significand has an implicit leading 1: . For subnormals, the implicit leading 1 is removed and the value uses with a different effective exponent (effectively as the minimum normal exponent). This allows representing values closer to zero than the smallest normal number, at reduced precision. subnormal
In classification terms for binary32:
- exponent field and fraction=0 ,
- exponent field and fraction subnormal.
Footnotes
-
IEEE 754 binary32 details https://en.wikipedia.org/wiki/IEEE_754#Single-precision:_binary32 - Field sizes (1/8/23), exponent bias 127, and special-case classification. ↩
-
Rounding modes and round-to-nearest ties-to-even https://en.wikipedia.org/wiki/IEEE_754#Rounding - Explains IEEE 754 rounding rules, including round-to-nearest and ties-to-even. ↩
IEEE 754 binary32 field sizes and biases
Common layout: sign, exponent, fraction; exponent bias is used to map stored exponent to .
Common pitfalls and precise interpretation rules
Pro Tip
When decoding: first classify by the exponent field (all zeros, all ones, or middle). Only after classification should you apply vs and the correct exponent formula.
Beware of “fraction bits” vs the significand
The fraction field alone is not the significand for normalized numbers. The actual significand is where comes from the fraction bits; for subnormals it is . Misreading this is the most common error.
Mental workflow for using IEEE 754 representations
Parse fields
1) Extract bitsRead sign, exponent, fraction from the fixed-width pattern."
Decide the case
2) Classify exponentIf exponent=0, exponent=all-ones, or exponent in-between => zero/subnormal, infinity/NaN, or normalized."
Compute the value
3) Apply the right formulaUse for normalized and for subnormals, plus the correct exponent offset."
Normalize and bias
4) For encoding, reverse the stepsConvert to binary, normalize to , set , then round if needed."
Footnotes
-
IEEE 754 binary32 details https://en.wikipedia.org/wiki/IEEE_754#Single-precision:_binary32 - Field sizes (1/8/23), exponent bias 127, and special-case classification. ↩
-
IEEE 754 binary64 details https://en.wikipedia.org/wiki/IEEE_754#Double-precision:_binary64 - Field sizes (1/11/52) and exponent bias 1023, plus normalized/subnormal structure. ↩
Rounding: why examples may not terminate exactly in binary
Even when you can express a decimal as an exact rational (like ), many decimals do not have a finite binary expansion. IEEE 754 specifies rounding rules (commonly “round to nearest, ties to even”) so that the result is the closest representable float, with a deterministic tie-break rule. This is crucial for reproducibility and predictable errors. round-to-nearest
Footnotes
-
Rounding modes and round-to-nearest ties-to-even https://en.wikipedia.org/wiki/IEEE_754#Rounding - Explains IEEE 754 rounding rules, including round-to-nearest and ties-to-even. ↩
Knowledge Check
In IEEE 754 binary32, how many bits are used for the fraction (mantissa) field?