Skip to content
digiwleea
The theory Tools Open the lab →

Binary subtraction, step by step: borrows and two's complement

Binary subtraction works like subtraction on paper: go column by column from the right, and when a column's top bit is too small, borrow 1 from the next column, which is worth 2 in base 2.

Press Next to walk through 6 − 3 and watch the borrow ripple left. Then click the bits to try your own numbers.

The rules of binary subtraction

A − BDifferenceBorrow
0 − 000
1 − 010
1 − 100
0 − 111

The last row is the only new idea: 0 − 1 cannot be done in one column, so the column borrows 1 from its left neighbour. The borrowed 1 is worth 2 here, and 2 − 1 = 1. The neighbour then subtracts that borrow too, and may have to borrow in turn.

A second worked example: 10 − 7

  borrow     1 1 1 0
             1 0 1 0   (10)
           − 0 1 1 1   ( 7)
           ---------
             0 0 1 1   ( 3)

Right column: 0 − 1 borrows, giving 1. Second column: 1 − 1 − 1 borrows again, giving 1. Third column: 0 − 1 − 1 borrows once more and gives 0. Left column: 1 − 0 − 1 = 0. The result, 0011, is 3.

The two's complement method

Computers rarely borrow column by column. They turn subtraction into addition: A − B = A + NOT B + 1, keeping the same number of bits. For 6 − 3: invert 0011 to 1100, add 1 to get 1101 (that is −3 in two's complement), and add: 0110 + 1101 = 1 0011. The carry out of the top column is dropped, leaving 0011 = 3. For 3 − 6 the same steps give 1101 with no carry out, which is −3.

To subtract any two binary numbers, of any length, use the binary calculator. To see the negation step on its own, use the two's complement calculator.

Binary subtraction in hardware

One column of the borrow method is a full subtractor: the difference is A XOR B XOR Bin and the borrow out is A'B + Bin(A XOR B)'. The right column needs no borrow in, so it can be a half subtractor. Processors use the two's complement method instead: the live 4-bit subtractor is four full adders with an inverter on each B bit and the first carry-in tied to 1, and the adder subtractor switches between adding and subtracting with one control bit. The subtraction lesson builds it step by step, and the binary addition walkthrough shows the carry this method relies on.

Common questions

How do you subtract binary numbers?

Line the numbers up and work from the rightmost column to the left, like subtraction on paper. In each column subtract the bottom bit, and any borrow, from the top bit. If that does not go, borrow 1 from the next column to the left; in binary a borrowed 1 is worth 2.

What are the rules of binary subtraction?

0 − 0 = 0, 1 − 0 = 1, 1 − 1 = 0, and 0 − 1 = 1 with a borrow of 1 from the next column. With a borrow coming in, subtract it as well: 0 − 1 − 1 = 0 with a borrow, and 1 − 1 − 1 = 1 with a borrow.

How does borrowing work in binary subtraction?

When a column needs more than it has, it takes 1 from the column to its left. That 1 is worth 2 in the current column, because each column is worth twice the one to its right. The column that lent the 1 then subtracts it as a borrow, and if it cannot, it borrows in turn, so a borrow can ripple across several columns.

How do you subtract binary numbers using two's complement?

Invert every bit of the number being subtracted, add 1, and add the result to the first number, keeping the original width. For 6 − 3 in 4 bits: NOT 0011 = 1100, plus 1 is 1101, and 0110 + 1101 = 1 0011. Dropping the carry out leaves 0011, which is 3. The two's complement calculator shows the negation step for any number.

What happens if the result of a binary subtraction is negative?

A borrow is left over after the last column (or, with two's complement, there is no carry out). The bits that remain are the answer in two's complement: 3 − 6 in 4 bits gives 1101, which is -3 as a signed number and 13 if read as unsigned.

How does a computer subtract?

With an adder. It inverts the bits of B with XOR gates and sets the adder's carry-in to 1, so the same adder computes A + NOT B + 1 = A − B. One control bit switches the circuit between adding and subtracting, as in the live 4-bit adder subtractor.

Read the theory: subtract with an adder →