Math calculator

Twos Complement Calculator

One more negative than positive, and the bug that causes.

One more negative than positive

And the bug that asymmetry causes.

−128 at 8 bits

1000 0000

Read as signed that is −128; read as unsigned it is 128. Same bits, two meanings.

Stored     1000 0000
One's      0111 1111
Two's      1000 0000

As signed

−128

two’s complement reading

As unsigned

128

the same bits, read differently

Signed range

−128 to 127

one more negative than positive

Unsigned maximum

255

all bits set

Fits?

yes

within range

  • A 8-bit signed register holds −128 to 127. Note the asymmetry: there is one more NEGATIVE value than positive, because zero takes up one of the positive slots.
  • That asymmetry has a sharp consequence: negating −128 overflows back to itself, because 128 does not fit. It is the one integer whose absolute value is negative, and it is a genuine source of bugs.
  • Two’s complement is used rather than sign-and-magnitude because it makes subtraction free: the same adder handles both, and there is only one representation of zero rather than two.

Two’s complement is used because it makes subtraction free — the same adder handles both, and zero has only one representation.

What this tool shows

An 8-bit signed register holds −128 to 127 — one more negative than positive, because zero takes a positive slot. So negating −128 overflows back to itself: it is the one integer whose absolute value is negative.

  • Two’s complement of any value
  • One’s complement alongside it
  • The signed range at each width
  • Why there is one more negative
  • What happens when a value does not fit
  • Why two’s complement is used at all
Four widths The overflow trap Both complements Signed and unsigned

Same bits, two readings — signed and unsigned.

Updated 7 September 2026 · Works in any browser, no installation

Flip every bit and add one. That turns 5 into −5 and back again, within a fixed width. An 8-bit signed register holds −128 to 127 — one more negative than positive — and negating −128 overflows straight back to −128.

At a glance

Formula shown
The two’s complement of a value is its bitwise inverse plus one, within the register width. A width of n bits holds −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1 as signed, and 0 to 2ⁿ − 1 as unsigned.
Scenario support
Reading a negative value from a hex dump; understanding an integer overflow bug; working out what a register actually contains.
Educational estimate
Planning support from the values you enter — not professional advice.

How the representation works

Two’s complement is not a sign bit with a magnitude attached. It is modular arithmetic.

In an n-bit register, every value is taken modulo 2ⁿ. The top half of that range is read as negative — and because addition wraps at 2ⁿ anyway, that reading makes the arithmetic come out right with no special handling.

So 11111011 is 251 as unsigned and −5 as signed, and both are correct. The bits do not know which; the type does.

The flip-and-add-one recipe is a consequence rather than a definition: inverting gives 2ⁿ − 1 − x, and adding one gives 2ⁿ − x, which is exactly −x modulo 2ⁿ.

The asymmetry

An n-bit signed range is −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1. There is one more negative value than positive.

The reason is that zero has to live somewhere, and it lives in the non-negative half. With 256 patterns, 128 go to the negatives and 128 to zero-and-the-positives — so the positives get 127.

The consequence is sharp: negating the minimum overflows. There is no +128 in an 8-bit signed register, so −(−128) comes back as −128. It is the one integer whose absolute value is negative.

This is a genuine and recurring source of bugs. `abs(INT_MIN)` is undefined behaviour in C. Java’s `Math.abs(Integer.MIN_VALUE)` returns a negative number and always has. Any code that negates a value it did not choose has to consider it.

Why not sign-and-magnitude

There are other ways to store a negative number. Two’s complement won, and for good reasons.

Sign-and-magnitude uses one bit for the sign and the rest for the value. It is the obvious design and it has two problems: there are two zeros (+0 and −0), and addition needs a comparator and a subtractor because the signs may differ.

One’s complement negates by inverting all bits. Also two zeros, and addition needs an end-around carry.

Two’s complement has exactly one zero, and ordinary binary addition works on signed values without modification. One adder handles everything, and subtraction is addition of a complement.

On a chip where every gate costs area and power, halving the arithmetic hardware settled the argument. It has been effectively universal since the 1960s, and the 2020 C++ standard finally made it the only permitted representation.

Overflow, and how quiet it is

When a value does not fit, it wraps. 127 + 1 becomes −128, and nothing complains.

That silence is the problem. In C, signed overflow is undefined behaviour — which does not merely mean the result is unpredictable, but that the compiler may assume it cannot happen and optimise on that assumption. A loop check written to detect overflow can be removed entirely, because the compiler reasons that overflow never occurs.

Unsigned overflow is different: it is defined to wrap, and can be relied upon.

Real consequences follow. The Ariane 5 lost a rocket in 1996 to a 64-bit float converted into a 16-bit signed integer that did not fit. Gandhi’s famous aggression in the original Civilization is a widely repeated story about an underflow that, by most accounts, did not actually happen — a reminder that the mechanism is real even where a particular anecdote is not.

This page wraps and flags, because that is what hardware does. It also says the wrap is silent, because a page that showed the wrap without saying so would be teaching half of it.

Where it gets used

Every processor. Signed integers in essentially every architecture in use are two’s complement, which is why the same bit patterns mean the same things across machines.

Reading dumps and protocols. A hex value from a register or a packet is a bit pattern; knowing the width and signedness is what turns it into a number.

Embedded work. Sensor readings and control values are often signed and narrow, so the range limits are close and overflow is a live concern rather than a theoretical one.

Debugging. A value that should be small appearing as four billion is almost always a signed pattern read as unsigned, and this page is how you check.

Sources and methodology

The representation is standardised; these are the references.

Method. The same bit pattern is reported under both readings, signed and unsigned, because that is what a register actually holds — a pattern, not a number, and the type decides which it means. Values outside the signed range are wrapped and flagged rather than refused, since wrapping is exactly what hardware does; the page says so and adds that the wrap is silent. The suite round-trips every one of the 256 signed 8-bit values through its bit pattern. That engine is verified on every change against 90 hand-written assertions, including that every 8-bit signed value round-trips through its bit pattern, and that negating the minimum gives back the minimum with an overflow flag. The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

Binary ArithmeticAdd, subtract, multiply and divide in binary, octal or hex — with the carry row shown, and what a processor actually does instead of subtracting.
BitwiseAND, OR, XOR, NOT, NAND, NOR and XNOR with truth tables and the bits laid out — at 8, 16, 32 or 64 bits, because NOT genuinely depends on the width.
Bit ShiftLeft, logical right, arithmetic right and rotate — with the two right shifts kept apart, because they differ for negatives and one of them floors rather than truncating.
Floating PointThe exact decimal value a double actually stores, written out in full — which is why 0.1 + 0.2 does not equal 0.3 in almost every programming language.
ModuloAll three conventions at once, because −7 mod 3 is −1 in JavaScript and 2 in Python and a page that gives only one of those is wrong for half its readers.
Absolute ValueAbsolute value as a distance from zero — plus the distance between two numbers, and a relative change from zero reported as undefined rather than as infinity.

More in Math, or browse all calculators.

Read the guide

Two’s complement is modular arithmetic wearing a different name — the Modulo Calculator covers the underlying operation.

Educational use disclaimer

This is an educational tool. Signed overflow is undefined behaviour in C, so a real program may not do what the wrapping shown here suggests.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (3 updates)

Published 7 September 2026

  1. Published the two's complement page reporting the same bit pattern under both readings, signed and unsigned, because that is what a register actually holds — a pattern, not a number, and the type decides which it means.
  2. Names the asymmetry and its consequence: an 8-bit signed range is −128 to 127, so negating −128 overflows back to itself and it becomes the one integer whose absolute value is negative — a live source of bugs in C and Java alike.
  3. Wraps out-of-range values rather than refusing them, since wrapping is what hardware does, and says explicitly that the wrap is silent and that signed overflow is undefined behaviour in C.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.