digiwleea
The theory Tools Open the lab →

How do computers store negative numbers?

Binary is all 0s and 1s, with no minus sign in sight. So how does a computer write -5? With a neat trick called two's complement: make the top bit's place value negative.

Click any bit, or press flip sign to negate. Watch the value go below zero. Press Next to walk through it.

What just happened

In a normal (unsigned) 8-bit number, the place values are 128, 64, 32, ..., 1, and the total runs from 0 to 255. Two's complement changes exactly one thing: the top bit's place value becomes -128 instead of +128. Everything else is the same, you still add up the place values wherever there is a 1, but now that one negative place can pull the total below zero. That is why 11111111 is -1 (all the small positives add up to 127, minus 128 is -1) and 10000000 is -128.

To flip a number's sign you invert every bit and add 1. The real payoff is in the arithmetic: because negatives are encoded this way, ordinary binary addition just works for them too, so a single adder does both addition and subtraction (to compute A - B, negate B and add). That is why the ALU in every CPU leans on it. New to how binary counts in the first place? Start with how binary works. Need to convert a specific value? Use the two's complement calculator.

Common questions

How do computers store negative numbers?

With two's complement: the same bits as an unsigned number, but the top bit's place value is negative (-128 in 8 bits). A number is still the sum of place values where there is a 1, but that negative place lets it drop below zero. So 11111111 = -1.

What is two's complement?

The standard way to represent signed integers: the top bit carries negative weight, so 8 bits cover -128 to 127. To negate, invert every bit and add 1. Its advantage: ordinary addition works for negatives too, so one adder does add and subtract.

Why do computers use two's complement?

Because the same adder can subtract (negate the second number and add), and there is only one zero (unlike sign-and-magnitude, which has +0 and -0). Simpler, cheaper hardware, which is why nearly every computer uses it.

How do you find the two's complement of a number?

Invert every bit, then add 1. For example 5 = 00000101; invert to 11111010, add 1 to get 11111011 = -5. Do it again to get back to 5.

What range can 8-bit two's complement represent?

-128 to +127. The most negative is 10000000 (just the -128 bit), the most positive 01111111 (127). Counting past 127 wraps to -128, which is how addition can overflow.

See how the same adder handles subtraction →

Embed this interactive

Free to embed in your course page, blog, or notes: just keep the credit link under the widget. Paste this where you want it:

<iframe src="https://digiwleea.wleeaf.dev/embed/tool/?w=negatives" width="100%" height="470" style="border:0;border-radius:12px;max-width:600px" title="How computers store negative numbers" loading="lazy"></iframe>