toolery

Two's complement, explained

How computers represent negative numbers using only the same bits they use for positive ones.

Binary on its own has no minus sign. Two’s complement is the trick computers use to represent negative numbers without needing a separate symbol for negative.

The core idea

To make a number negative in two’s complement, you invert every bit and then add one. That is the entire algorithm:

00001010   (10 in binary)
11110101   (every bit inverted)
11110110   (add 1)

11110110 is now the 8-bit two’s complement representation of −10.

Why add one at all

Inverting the bits alone gives you something called one’s complement, which has an awkward side effect: it produces two different representations of zero (00000000 and 11111111). Adding one collapses that down to a single, unambiguous zero, which is why two’s complement became the standard almost every processor uses today.

Reading the sign

In two’s complement, the leftmost bit tells you the sign: 0 means positive, 1 means negative. That is also why an 8-bit two’s complement number can represent −128 to 127, rather than a symmetric −127 to 127, one extra negative value comes from that single sign bit.

Try the full working steps in the two’s complement calculator.