1. Home
  2. Computer Organization & Architecture
  3. IEEE 754 Floating Point

IEEE 754 Floating Point

How −6.75 becomes 32 bits. Build the sign, exponent and mantissa in 3D, and see why 0.1 can't be stored exactly.

Interactive 3DIntermediate12 min readCOAUpdated

Drag to rotate · Right-drag to pan · Click, then scroll to zoom · Space play · Left arrowRight arrow step

What's happening

Computers store real numbers like −6.75 in the IEEE 754 format: 32 bits split into a sign, an exponent and a mantissa — scientific notation, but in base 2. Press Convert to build the bits step by step.

Pseudocode

  1. 1. sign bit: 0 for +, 1 for −
  2. 2. write |x| in binary (integer part: ÷2, fraction: ×2)
  3. 3. normalise to 1.xxxx × 2^e
  4. 4. exponent field = e + 127 (8 bits)
  5. 5. mantissa field = bits after the leading 1 (23 bits)
  6. 6. pack: sign | exponent | mantissa
Read this model as text · 8 steps

One run of the model above, written out step by step. Useful with a screen reader, on a slow connection, or for quick revision. The values may differ from the run on your screen.

  1. Computers store real numbers like −6.75 in the IEEE 754 format: 32 bits split into a sign, an exponent and a mantissa — scientific notation, but in base 2. Press Convert to build the bits step by step.
  2. The number is negative, so the sign bit is 1. From now on we work with |x| = 6.75.
  3. Integer part 6 in binary: keep dividing by 2 and read the remainders bottom-up → 110.
  4. Fraction part: keep multiplying by 2 and take the integer bit each time: 0.75 × 2 = 1.5 → 1; 0.5 × 2 = 1 → 1. It ends — this number can be stored exactly.
  5. Normalise: move the binary point so exactly one 1 is in front of it → 1.1011… × 22. Every normalised number starts with 1, so that 1 is not stored (the "hidden bit") — a free extra bit of precision.
  6. The exponent is stored with a bias of 127 so negative exponents need no sign: 2 + 127 = 129 = 10000001₂.
  7. The 23 mantissa bits are the digits after the hidden 1, padded with zeros: 101100000000…
  8. Packed together: 1 10000001 10110000000000000000000 = 0xC0D80000. Value = (−1)1 × 1.mantissa × 22 = exactly -6.75.

Try this in the 3D model

  • Convert -6.75 and check the result is 0xC0D80000.
  • Convert 0.1. Does the fraction ever end? What value is actually stored?
  • Compare 1 and 0.5. Which bits change?
  • Try a big whole number like 2026. How many places does the point move?

Scientific notation, in binary

In science we write 6 020 000 as 6.02 × 10⁶: a sign, a number with one digit before the point, and an exponent. IEEE 754 — the standard used by almost every computer — does the same in base 2:

value = (−1)^sign × 1.mantissa × 2^(exponent − 127)

A 32-bit float has three fields:

Field Bits Meaning
Sign 1 0 = positive, 1 = negative
Exponent 8 the power of 2, stored with a bias of 127
Mantissa (fraction) 23 the bits after the leading 1

Converting −6.75 step by step

  1. Sign: negative → 1.
  2. Integer part: 6 = 110₂ (divide by 2: remainders 0, 1, 1, read upwards).
  3. Fraction part: multiply by 2 repeatedly: 0.75 × 2 = 1.5 → 1, 0.5 × 2 = 1.0 → 1. So 0.75 = .11₂.
  4. So 6.75 = 110.11₂. Normalise by moving the point 2 places left: 1.1011 × 2².
  5. Exponent: 2 + 127 = 129 = 10000001₂.
  6. Mantissa: the bits after the leading 1, padded to 23 bits: 10110000000000000000000.

Result: 1 10000001 10110000000000000000000 = 0xC0D80000.

The hidden bit

After normalising, the first bit is always 1 — so IEEE 754 doesn’t store it. That free “hidden bit” gives 24 bits of precision from 23 stored bits.

Why 0.1 can’t be stored exactly

0.1 × 2 = 0.2 → 0, 0.4 → 0, 0.8 → 0, 1.6 → 1, 1.2 → 1, then 0.4 again… In binary 0.1 = 0.000110011001100… forever. It must be rounded to 23 bits, so the stored float is 0.100000001490116… That’s why:

>>> 0.1 + 0.2
0.30000000000000004
>>> 0.1 + 0.2 == 0.3
False
>>> abs((0.1 + 0.2) - 0.3) < 1e-9     # compare floats with a tolerance
True

Never use floats for money — use integers (paise or cents) or a decimal type.

Special values

Exponent bits Mantissa Meaning
all 0 0 ±0
all 0 not 0 subnormal (tiny) numbers, no hidden 1
all 1 0 ±infinity (e.g. 1/0)
all 1 not 0 NaN — “not a number” (e.g. 0/0)

So normal exponents run from 1 to 254, meaning 2⁻¹²⁶ to 2¹²⁷.

Code: see the bits yourself

import struct

def float_bits(x):
    [u] = struct.unpack(">I", struct.pack(">f", x))   # the raw 32 bits
    b = f"{u:032b}"
    return b[0], b[1:9], b[9:], hex(u)

print(float_bits(-6.75))
# ('1', '10000001', '10110000000000000000000', '0xc0d80000')
print(float_bits(0.1))
# ('0', '01111011', '10011001100110011001101', '0x3dcccccd')

Common mistakes

  • Forgetting the bias: the stored exponent is e + 127, not e.
  • Including the leading 1 in the 23 mantissa bits.
  • Moving the binary point the wrong way: if the point moves left, the exponent is positive.

Complexity at a glance

Case / operationTimeWhy
Single precision (float)1 + 8 + 23 = 32 bitsAbout 7 significant decimal digits.
Double precision (double)1 + 11 + 52 = 64 bitsAbout 15–16 significant decimal digits.

Quick check

Test yourself — pick an answer to see if you got it.

1. What is the exponent bias in IEEE 754 single precision?

2. Why is the leading 1 of the mantissa not stored?

3. What is the sign bit of -0.15625?

4. Why does 0.1 + 0.2 == 0.3 give False in most languages?

Saved in this browser.
Spotted a mistake or a bug in the 3D model?

Report a mistake

in IEEE 754 Floating Point. Thank you — every report makes the lesson better for the next reader.

We'll also include a link to the step of the 3D model you're on and your browser type, so we can reproduce it.