Labs / Computer Science & Data

IEEE 754 Floating-Point Explorer

Inspect how 32 bits encode sign, biased exponent, and fraction — and see firsthand why 0.1 + 0.2 ≠ 0.3.

New to this? There\'s a lesson below ↓
← BACK TO LABS
32-Bit Single Precision (float32)
Decoded Fields
CATEGORY
NORMAL
SIGN BIT
0 (+)
EXPONENT (BIAS 127)
124 (unbiased: −3)
SIGNIFICAND
1.25
STORED VALUE
0.15625
ROUNDING ERROR
0
What's happening?

Sign (1 bit): 0 is positive, 1 is negative.

Exponent (8 bits): Stored with a bias of +127 so exponents from −126 to +127 are unsigned integers.

Fraction (23 bits): Normalized numbers get a free leading 1. bit ("hidden bit") before the 23 stored fraction bits.

The lesson

IEEE 754 Single-Precision Floating-Point Representation

How 32-bit floats encode sign, +127 biased exponent, and a 23-bit mantissa (with an implicit leading 1), and why 0.1 + 0.2 has rounding error.

1. Binary Fractions and Why 0.1 + 0.2 ≠ 0.3

In base 10, columns to the right of the decimal point represent negative powers of 10 (10⁻¹ = 1/10, 10⁻² = 1/100). A fraction like 1/3 = 0.3333… repeats infinitely in base 10 because 3 does not divide any power of 10.

In base 2, columns to the right of the binary point represent negative powers of 2:

Place value:   2⁻¹     2⁻²     2⁻³      2⁻⁴       2⁻⁵
Fraction:      1/2     1/4     1/8     1/16      1/32
Decimal:       0.5    0.25   0.125   0.0625   0.03125

Any fraction whose denominator is a power of 2 terminates cleanly in binary. Click the 0.15625 (Exact) preset in the simulator above: 0.15625 = 5/32 = 1/8 + 1/32 = 0.00101₂, so its Rounding Error is 0.

By contrast, 0.1 = 1/10 has a factor of 5 in the denominator, so in binary it repeats forever: 0.0001100110011…₂. Click 0.1 (Rounded): because a 32-bit float only has 23 fraction bits, the infinite binary sequence must be rounded to the nearest representable value (0.10000000149…). When a program adds rounded 0.1 and rounded 0.2, those tiny rounding errors accumulate into 0.30000000000000004.

2. The IEEE 754 Single-Precision (float32) Layout

Just as decimal scientific notation writes numbers as ±d.ddd × 10ᵉ, the IEEE 754 standard writes binary floating-point numbers as:

Value = (−1)^S × (1.Fraction)₂ × 2^(E − 127)

A 32-bit single-precision float splits its 32 bits into three fields (color-coded in the simulator):

FieldBitsRole
Sign (S)1 bit (bit 31)0 = positive (+), 1 = negative (−).
Biased Exponent (E)8 bits (bits 30–23)Unsigned integer from 1 to 254 for normal numbers. Subtract the bias of 127 to get the true exponent (−126 to +127).
Fraction / Mantissa (M)23 bits (bits 22–0)The fractional bits after the binary point in 1.M.

Two key architectural details:

  • The Hidden Leading 1 (Implicit Bit): In base 2, every normalized non-zero number starts with 1.something. Because the leading bit before the point is always 1, IEEE 754 does not store it in memory — giving 24 bits of significand precision while only storing 23 bits.
  • Why Bias the Exponent by +127? Storing the exponent as an unsigned value E = exponent + 127 places the smallest exponent (−126 → 1) and largest exponent (+127 → 254) in strictly increasing unsigned order, allowing hardware to compare floating-point magnitudes using fast integer comparator circuits.

3. Worked Example: Encoding −6.5

Click the −6.5 preset button and follow the 4 steps used to encode it:

1. Sign:     Negative → S = 1
2. Binary:   6 = 110₂ and 0.5 = 0.1₂  →  6.5 = 110.1₂
3. Normalize (shift point 2 places left):  110.1₂ = 1.101₂ × 2²
4. Fields:
   • Biased Exponent E = 2 + 127 = 129 = 10000001₂
   • Fraction M (drop the leading 1.) = 10100000000000000000000₂
   • 32-bit Hex = 0xC0D00000

4. Special Exponent Values (E = 0 and E = 255)

The all-zeros exponent (E = 0) and all-ones exponent (E = 255) are reserved for special categories:

CategoryExponent EFraction MMeaning
Signed Zero (±0.0)00Represents exact +0.0 or −0.0 (needed because normal numbers always have a leading 1.).
Subnormal (Denormal)0≠ 0Leading bit becomes 0.M with fixed exponent 2⁻¹²⁶, providing gradual underflow near zero.
Infinity (±∞)2550Result of overflow or division by zero (1.0 / 0.0).
NaN (Not a Number)255≠ 0Result of undefined operations (0.0 / 0.0, √−1). Note: NaN === NaN is always false.

Exercises

1. Encode decimal 0.75 into IEEE 754 single-precision fields (Sign, Biased Exponent, Fraction, and Hex), then verify in the simulator.

Show solution
0.75 = 1/2 + 1/4 = 0.11₂ = 1.1₂ × 2⁻¹.
• Sign S = 0
• Biased Exponent E = −1 + 127 = 126 (01111110₂)
• Fraction M = 10000000000000000000000₂ (significand 1.5)
• Hex: 0x3F400000.

2. Type 16777217 (which is 2²⁴ + 1) into the Decimal Input box. Why does the Stored Value round back to 16777216?

Show solution
A 32-bit float has 24 bits of significand precision (1 hidden bit + 23 fraction bits). At 2²⁴ = 16,777,216, the 23rd fraction bit has weight 2²⁴ × 2⁻²³ = 2.0, so the gap between adjacent representable floats is 2. Odd integers above 2²⁴ cannot be represented in float32.

Quiz

Why can 0.125 be represented with zero rounding error in IEEE 754 while 0.1 cannot?

In 32-bit IEEE 754, if the 8-bit biased exponent field is 10000010₂ (decimal 130), what is the true unbiased exponent?

How does a 32-bit normalized float achieve 24 bits of significand precision using only 23 fraction bits?

What category of IEEE 754 value has Exponent E = 255 and a non-zero Fraction M ≠ 0?