Negative numbers in binary (two’s complement)

Advanced · 7 min read · Updated 28 November 2026

In shortTwo’s complement stores a negative number by inverting every bit of its positive value and adding 1. In 8 bits, +5 is 00000101, so −5 is 11111010 + 1 = 11111011. The leftmost bit acts as the sign (1 = negative), and an 8-bit signed number ranges from −128 to +127.

The method: invert and add one

To write −18 in 8 bits:

  1. Write +18: 00010010
  2. Invert every bit: 11101101
  3. Add 1: 11101110

So −18 is 11101110. To go back, do exactly the same thing: invert (00010001) and add 1 (00010010 = 18).

Reading a two’s complement number

The leftmost bit has a negative place value. In 8 bits it’s worth −128 instead of +128:

−128 64 32 16 8 4 2 1
1 1 1 0 1 1 1 0

−128 + 64 + 32 + 8 + 4 + 2 = −18 ✓

Signed ranges

Bits Unsigned range Signed (two’s complement) range
4 0 to 15 −8 to 7
8 0 to 255 −128 to 127
16 0 to 65,535 −32,768 to 32,767
32 0 to 4,294,967,295 −2,147,483,648 to 2,147,483,647

Why it makes subtraction free

7 − 5 becomes 7 + (−5):

   00000111   (7)
 + 11111011   (−5)
 ----------
 1 00000010   → drop the carry → 00000010 (2)

The carry out of the top bit is simply discarded. One adder circuit handles both operations, which is why every modern CPU uses two’s complement.

Frequently asked questions

What is −1 in two’s complement?

All ones. In 8 bits, −1 is 11111111; in 32 bits it is 32 ones (hex FFFFFFFF).

Why not just use a sign bit?

Sign-and-magnitude gives two zeros (+0 and −0) and needs separate circuits for subtraction. Two’s complement has one zero and lets the same adder do both addition and subtraction.

What is the range of a signed 16-bit number?

−32,768 to +32,767.

Next: ASCII vs Unicode vs UTF-8 →

Related tools and guides