Formula Bro

Math and physics formulas, explained like you are new.


Floating-Point Value

In one sentence: A floating-point number stores a value as a sign, a power of two and a binary fraction, and this formula turns those three parts back into the number.

x=(−1)s×1.f×2e−127x = (-1)^{s} \times 1.f \times 2^{e - 127}

Read it out loud: “x equals negative one to the power of s, times 1 point f, times 2 to the power of e minus 127. This form covers normal single-precision numbers. x is the number the 32 bits stand for. s is the sign bit, 0 for positive and 1 for negative. 1 point f is the significand: a 1, a point, then the 23 stored fraction bits f. e is the exponent field, the 8 stored bits read as a whole number. The 2 with e minus 127 as a small raised number is the scale, two multiplied by itself that many times.”

Before you start

The ideas and signs this page uses, explained from zero. For powers of ten, Greek letters and other notation in general, see Math basics.

Powers of ten and scientific notation, like 103810^{38}

103810^{38} means 1 followed by 38 zeros, a number so large that it is written as a power. A power of ten is ten multiplied by itself a set number of times, and the small raised number is the exponent. Scientific notation writes a number as a short number times a power of ten. So 3.4×10383.4 \times 10^{38} means 3.4 with the decimal point moved 38 places to the right. A negative exponent moves the point to the left, so 10−3=0.00110^{-3} = 0.001.

Binary fractions, like 0.120.1_{2}

A binary fraction works like a decimal fraction, but each place is a power of two. The places after a binary point are worth 12\frac{1}{2}, 14\frac{1}{4}, 18\frac{1}{8} and so on. So 0.120.1_{2} means one half, 0.0120.01_{2} means one quarter, and 0.1120.11_{2} means three quarters. A fraction such as one tenth has no finite binary form, as the explanation below shows.

Bits, bytes and 32-bit numbers

A bit is one 0 or 1. A byte is 8 bits. A 32-bit number is a pattern of 32 bits, which is four bytes. The computer can only store a fixed number of bits for each number, so every decimal value it keeps has to fit inside those 32 bits. That limit is the reason floating-point numbers are sometimes not exact.

Hexadecimal and the prefix 0x

Hexadecimal is base 16, which uses the digits 0 to 9 and the letters A to F. One hex digit stands for exactly four bits. The prefix 0x shows that the digits that follow are hexadecimal. So 0x3DCCCCCD\text{0x3DCCCCCD} is a 32-bit pattern written in eight hex digits, and the hex digit D stands for the four bits 1101.

The IEEE 754 standard

IEEE 754 is the standard that defines how computers store decimal values as binary floating-point numbers. Most processors follow it, so the same bits give the same number on different machines. The standard defines several sizes. This page covers the most common one, single precision, which uses 32 bits.

What each symbol means

SymbolMeaning

xx

The number that the 32 bits stand for. It is a decimal value with no unit of its own, and its size depends on the bits. The example pattern stands for x=6x = 6.

(−1)s(-1)^{s}

The sign factor. It equals +1+1 when the sign bit is 0, and −1-1 when the sign bit is 1. It has no unit, and it only decides whether the number is positive or negative.

ss

The sign bit, the first of the 32 bits. It is 0 for a positive number and 1 for a negative number. It has no unit, because it is one bit.

1.f1.f

The significand, a binary number from 1 up to nearly 2. Its leading 1 is implied and not stored, and the 23 stored fraction bits follow the binary point. It has no unit. It holds the digits of the number itself.

ff

The 23 stored fraction bits, written after the leading 1. Bit by bit they are worth one half, one quarter, one eighth and so on. They have no unit and are read as a binary fraction.

ee

The exponent field, 8 stored bits read as a whole number from 0 to 255. It has no unit. The real power of two is e−127e - 127, which is why the field is said to have a bias of 127.

2e−1272^{e - 127}

The scale factor, a power of two that sets the size of the number. It has no unit. A stored exponent of 130 gives a real power of 130−127=3130 - 127 = 3, so the scale is 23=82^{3} = 8.

The formula piece by piece

ff

The 23 stored fraction bits, the smallest detail of the number. Each bit that is 1 adds a fraction, such as one half or one quarter, to the significand. Together they give the digits after the leading 1.

1.f1.f

Add the implied leading 1 to the fraction. The result is a binary number from 1 up to nearly 2. An all-zero fraction gives exactly 1, and a fraction of one half gives 1.5.

(−1)s(-1)^{s}

The sign factor from the sign bit. If the sign bit is 0, the factor is +1+1 and the number stays positive. If it is 1, the factor is −1-1 and the number becomes negative.

2e−1272^{e - 127}

The scale factor from the exponent field. Subtract the bias 127 from the stored exponent to get the real power, then raise 2 to that power. A stored exponent of 127 gives a scale of 1, and a stored exponent of 128 gives a scale of 2.

x=(−1)s×1.f×2e−127x = (-1)^{s} \times 1.f \times 2^{e - 127}

The whole formula in one sentence: the number equals the sign factor times the significand times the scale factor, so the sign, the digits and the size are combined into one decimal value.

What the formula is doing, and why

What goes in and what comes out. You give the formula 32 bits: one sign bit ss, eight exponent bits ee and 23 fraction bits ff. It returns the decimal number xx that those bits stand for. This 32-bit form, called single precision, is one of the most common ways that computers store decimal numbers.

Why it works like scientific notation. A number such as 6.02×10236.02 \times 10^{23} has a sign, a string of digits and a power that sets its scale. A floating-point number does the same in base two. The fraction bits are the digits, the exponent is a power of two that moves the binary point to the right size, and the sign bit gives the plus or minus.

Why the leading 1 is not stored, and why the bias is 127. Every normal number can be scaled so that its binary digits start with 1, as in 1.…1.\ldots. Because that leading 1 is always present, the format does not store it, and this gives one more bit of precision. The stored exponent is a whole number from 0 to 255, so the bias 127 is subtracted to give a real power from −126-126 up to 127127.

Why 0.1 is not exact. In binary, one tenth is 110\frac{1}{10}, and its denominator has a factor of 5. A fraction has a finite binary form only when its denominator, in lowest terms, is a power of two. So 0.10.1 repeats forever in binary, as 0.0001100110011…0.0001100110011\ldots, with the pattern 0011 repeating. The 23 fraction bits cut the pattern off, so the stored value is 0.100000001490116…0.100000001490116\ldots. That is very close to 0.1, but it is not equal to it.

Limits of the format. A single-precision value keeps about 7 decimal digits. Whole numbers are exact only up to 224=16,777,2162^{24} = \text{16,777,216}. The largest finite value is about 3.4×10383.4 \times 10^{38}. Exponent field values 0 and 255 are reserved for zero, very small numbers, infinity and not-a-number, so the normal formula above covers exponent fields 1 to 254.

An everyday picture

Scientific notation on a calculator is the closest everyday idea. The display has room for a fixed number of digits, such as 6.02×10236.02 \times 10^{23}, and the exponent moves the decimal point to the right size. Floating point does the same with bits. The 23 fraction bits are the fixed digits, and the exponent is the power of two that sets the scale.

Worked example: Decoding a 32-bit float

Suppose a game stores one number, the size of a sprite on screen, as the 32 bits 010000001100000000000000000000000\ 10000001\ 10000000000000000000000. These are the sign, the eight exponent bits and the 23 fraction bits, in that order. So s=0s = 0, the stored exponent field is e=129e = 129, and the fraction bits give f=0.1000…f = 0.1000\ldots in binary, which is one half.

  1. Split the 32 bits into three parts. The first bit is the sign bit, the next eight bits are the exponent field, and the last 23 bits are the fraction. Counting them gives 1+8+23=321 + 8 + 23 = 32, so the split uses every bit exactly once.
  2. Read the sign. The sign bit is s=0s = 0, so the sign factor is (−1)0=1(-1)^{0} = 1. Multiplying by 1 changes nothing, so the number is positive.
  3. Read the exponent field. The eight bits 1000000110000001 stand for 128+1=129128 + 1 = 129. The real power of two is 129−127=2129 - 127 = 2, because the bias 127 is subtracted from the stored value. So the scale factor is 22=42^{2} = 4.
  4. Read the fraction bits. The 23 fraction bits begin with a 1 and then have 22 zeros. The first bit after the binary point is worth one half, and the rest add nothing. So f=0.5f = 0.5, and the significand is 1.f=1+0.5=1.51.f = 1 + 0.5 = 1.5.
  5. Multiply the three parts. The formula says x=(−1)s×1.f×2e−127x = (-1)^{s} \times 1.f \times 2^{e - 127}, which here is 1×1.5×4=61 \times 1.5 \times 4 = 6. The sign is positive, the significand is 1.5, and the scale is 4, so these 32 bits store exactly the number 6.
  6. Check a value that is not exact. The 32-bit pattern for 0.1 is 0x3DCCCCCD\text{0x3DCCCCCD}. Its sign bit is 0, and its exponent field is 0111101101111011, which is 123, so the real power is 123−127=−4123 - 127 = -4. Its 23 fraction bits are a pattern that is cut off, so the significand is about 1.60000002381.6000000238. Multiplying gives 1.6000000238×2−4=0.10000000151.6000000238 \times 2^{-4} = 0.1000000015, which is close to 0.1 but not equal to it.

Answer: The 32 bits store exactly 6, because the sign is positive, the significand is 1.5 and the scale is 4. Many decimal values, such as 0.1, have no exact binary form, so the computer stores the nearest pattern instead. For 0.1 that stored value is about 0.1000000015.

The numbers in this example are recomputed by script every time the site is built.

Common mistakes

Where you will meet it

Questions people ask

Why is 0.1 not exact in binary?

Because 110\frac{1}{10} has a factor of 5 in its denominator, and a fraction has a finite binary form only when its denominator, in lowest terms, is a power of two. Decimal has the same kind of problem with 13=0.333…\frac{1}{3} = 0.333\ldots, which never ends.

What is the difference between single and double precision?

Double precision uses 64 bits: 1 sign bit, 11 exponent bits and 52 fraction bits. It keeps about 15 to 16 decimal digits, compared with about 7 for single precision.

Should I use floats for money?

Not for exact totals. Store amounts as whole cents in an integer, or use a decimal type designed for money. Binary rounding can make totals a cent off.

Sources

  1. IEEE 754, Wikipedia
  2. Single-precision floating-point format, Wikipedia

| All Computer Science formulas |

Published 2026-10-22. Plain-text copy for AI agents and readers: computer-science/floating-point-value.md.