Two's Complement: Negative Numbers in Binary

Two's complement is how a fixed-width binary value carries a sign, and it is why 11111011 can be 251 or −5 depending on who reads it.

1×2⁷128=128
1×2⁶64=64
1×2⁵32=32
1×2⁴16=16
1×8=8
0×4=0
1×2=2
1×2⁰1=1
total=251

The reader above takes the digits as an unsigned number. The panel below reads the same digits both ways, at whatever width you type them.

Bits Width Read as unsigned Read as two's complement
11111011 8-bit 251 -5

What is two's complement?

Two's complement is the standard way to write negative binary numbers at a fixed width: -5 in 8 bits is 11111011. Write +5 (00000101), invert every bit (11111010), and add 1.

The width comes first, because the sign lives in the top place. In eight digits the leading place is worth −128 instead of +128 and every other place keeps its usual weight, so 11111011 adds up to −128 + 64 + 32 + 16 + 8 + 2 + 1.

Result: 11111011 is 251 unsigned and −5 signed

11111111 is 255 as an unsigned 8-bit number (0xFF, 0o377). Read as 8-bit two's complement it is −1; the 8-bit signed range is −128 to 127.

The same eight bits, read as an unsigned byte and as two's complement.
BitsUnsignedSignedOctHex
00000000 0 0 000 00
00000001 1 1 001 01
01111111 127 127 177 7F
10000000 128 -128 200 80
11111011 251 -5 373 FB
11111111 255 -1 377 FF

Nothing in the digits says which column applies. A value is signed or unsigned because the program reading it says so, which is why one byte can be 251 in one place and −5 in another.

How do you convert a negative decimal to two's complement binary?

Write the value without its sign, invert every digit, then add 1. The width has to be fixed before you start.

  1. Fix the width. Eight digits hold −128 to 127, so −5 fits with room to spare.
  2. Write the value without its sign in binary, padded to that width: 5 is 00000101.
  3. Invert every digit, one for zero and zero for one: 00000101 becomes 11111010.
  4. Add 1 to the inverted value: 11111010 plus 1 is 11111011.

Result: −5 = 11111011 in 8 digits

The same four steps work at any width; only the padding changes. A positive value needs none of them, so write a number in base 2 gives the same digits.

How do you convert two's complement binary to decimal?

Read the leading digit first. A 0 means the value is positive and reads as an ordinary binary number; a 1 means it is negative, and the steps below recover its size.

  1. Look at the leading digit. 11111011 starts with 1, so the value is negative.
  2. Invert every digit: 11111011 becomes 00000100.
  3. Add 1: 00000100 plus 1 is 00000101, which is 5.
  4. Put the sign back: the original eight digits are −5.

Result: 11111011 = −5 in 8 digits

The place-value route reaches the same answer in one line. Keep every weight as it is and make the top one negative: −128 + 64 + 32 + 16 + 8 + 2 + 1 is −5. For unsigned values of any width, binary to decimal with the power-of-2 row shows the working place by place.

What is the difference between sign-magnitude, one's complement and two's complement?

Sign-magnitude and one's complement both leave two ways of writing zero; two's complement leaves one, which is why hardware settled on it.

Three ways of writing a sign in eight bits.
SchemeMinus 5 in 8 bitsWays to write zeroRange
Sign-magnitude 10000101 Two −127 to 127
One's complement 11111010 Two −127 to 127
Two's complement 11111011 One −128 to 127

The second reason is arithmetic. In two's complement, adding a negative value is the same operation as adding a positive one, so a processor needs one adder rather than an adder and a special case. The other two schemes need a correction step whenever a carry leaves the top place.

What is the range of an 8-bit two's complement number?

An 8-bit two's complement value runs from −128 to 127: 128 negative values, zero, and 127 positive ones. The negative side reaches one further because zero sits on the positive side of the split.

A byte is 8 bits and holds 256 values, 0–255; a nibble is 4 bits.

A nibble's 16 values run 0–15 unsigned and −8 to 7 signed. Doubling the width squares the count: 16 digits give 65536 patterns, split into 2¹⁵ = 32768 negatives and 32768 values from zero up, so a signed 16-digit value runs −32768 to 32767. The pattern holds at 32 and 64 digits, which is why converting between binary, octal, decimal and hexadecimal treats width and base as two separate questions.

Frequently Asked Questions

What is binary overflow?

Overflow is a result that needs more digits than the width allows. In 8-bit two's complement, 127 plus 1 gives 10000000, which reads as −128: the value wraps to the other end of the range instead of growing.

The rest of the family sits on all the number and text converters in one place.