Skip to content
BetterDL

Two's complement subtraction

Also called: subtraction by addition, subtract by adding the negative, complement subtraction

Subtracting by adding the negative: A − B is computed as A + (B inverted) + 1, so the same adder circuit handles both addition and subtraction.

Hardware almost never subtracts directly. It uses the identity A − B = A + (−B), and in twos complement, −B is easy to make: invert B and add 1. So:

A − B = A + B' + 1, where B' is B with every bit inverted.

By hand:

  1. Write both numbers at the same width.
  2. Invert every bit of B.
  3. Add A, the inverted B, and 1.
  4. Drop any carry out beyond the width.

The resulting bits are right whether you read them as unsigned or signed. What changes is how you check the answer:

  • Unsigned: carry-out 1 means no borrow, so A ≥ B. Carry-out 0 means A < B, and the result has wrapped around.
  • Signed: apply the signed overflow rule to A and −B, or use V = Cₙ ⊕ Cₙ₋₁.

In a circuit, the adder subtractor does this with a row of XOR controlled inverters on B, plus the carry-in C0 = 1 for the +1.

Worked examples

Example

1011 − 0110 (11 − 6)

Invert B, add with a carry-in of 1.

  1. 1.

    Invert B: 0110 → 1001.

  2. 2.

    Add: 11 + 9 + 1 = 21 = 1 0101.

  3. 3.

    Keep 4 bits: 0101 = 5. Correct.

  4. 4.

    Carry-out 1: no borrow, because 11 ≥ 6.

Example

0011 − 0111 (3 − 7)

A result that goes below zero.

  1. 1.

    Invert B: 0111 → 1000.

  2. 2.

    Add: 3 + 8 + 1 = 12 = 1100, with no carry-out.

  3. 3.

    Carry-out 0 means a borrow: as unsigned numbers, 3 < 7.

  4. 4.

    As two's complement, 1100 = −4, the correct signed answer.

Common mistakes

  • Forgetting the +1, which gives a result one too small.

  • Keeping the carry-out as an extra bit of the difference.

  • Inverting A instead of B.

Practice Two's complement subtraction

Interactive questions with instant feedback and a worked solution for every wrong answer.

Basic CPU / Computer Architecture lesson full course

Learn it step by step

Two's complement subtraction is taught in Number Systems and Adders and ALUs.