Binary basics

Binary subtraction

Borrowing, two's complement and one's complement, step by step. Subtract any two binary numbers and see every borrow.

Written by
Reviewed by
Updated · 6 min read

You need to work out something like 1010 - 0111 by hand. Do it the way you'd subtract decimal numbers: column by column from the right. The one change is that a borrow is worth 2 instead of 10. The four rules are 0 - 0 = 0, 1 - 0 = 1, 1 - 1 = 0, and 0 - 1 = 1 with a borrow from the next column. So 1010 - 0111 = 0011, which is 10 - 7 = 3 in decimal. Computers skip borrowing and add the two's complement instead, and that method is further down.

Key takeaways

The four rules: 0 - 0 = 0, 1 - 0 = 1, 1 - 1 = 0, and 0 - 1 = 1 with a borrow.
A borrow in binary is worth 2 in the column that receives it, not 10.
Computers subtract by adding: invert B, add 1, add it to A and drop the carry.
With two's complement, no carry out means the answer is negative.
Always pad both numbers to the same width before you invert bits.
binarytranslator.ai

Binary subtraction calculator with steps

Enter two binary numbers. The tool shows the borrow in each column, the result in binary and decimal, and the same subtraction done with two's complement.

The 4 rules of binary subtraction

DigitsResultBorrowWhy
0 - 00nonothing to take away
1 - 01nonothing to take away
1 - 10noone minus one
0 - 11yesborrow 2 from the left: 2 - 1 = 1

The last rule is the only tricky one. Borrowing from the next column gives you 2 in the current column, because each binary place is worth twice the one to its right. The column you borrowed from loses 1, the same way it does in decimal.

Method 1: subtraction with borrowing

Work out 11001 - 01011, which is 25 - 11 in decimal. Write the numbers one above the other with the same number of digits, then go from right to left. Column 1 is the rightmost:

ColumnTop digitBottom digitBorrow inResult digitBorrow out
11100no
20101yes
30011yes
41111yes
51010no

A borrow out of one column becomes the borrow in of the next, and you take it away from the top digit before subtracting. In column 3, for example, the top digit 0 minus the borrow is already below zero, so that column borrows too. Read the result digits from the bottom row up: 01110, which is 14. 25 - 11 = 14, so the answer checks out.

Binary subtraction with borrowing: 11001 minus 01011 equals 01110, which is 25 minus 11 equals 14, with borrows into the second, third and fourth columns from the right.

Borrowing across zeros

When the column to the left is 0, the borrow has to travel further, as it does in 1000 - 1 in decimal. In 1000 - 0001, the rightmost column borrows from the next 1 it can find, three places left. Every 0 it passes becomes 1 on the way, so the answer is 0111. The rule of thumb: the borrowed 1 turns into a 0, and every 0 between it and the column you are working on turns into a 1.

Method 2: subtraction with two's complement

Computers subtract by adding. To work out A - B, they turn B into its negative with two's complement and add it to A. The two's complement of B is every bit inverted, plus 1. It works as a negative because B plus its inverted bits is all 1s, and one more rolls over to all 0s once the extra digit is dropped. Here is 1010 - 0111 (10 - 7) in 4 bits:

  1. Invert 0111 to get 1000.
  2. Add 1 to get 1001. This is -7 in 4-bit two's complement.
  3. Add it to A: 1010 + 1001 = 10011.
  4. The sum has 5 digits. Drop the carry out of the leftmost column and keep 4 bits: 0011, which is 3.

The carry tells you the sign. A carry off the left end means the result is positive or zero. No carry means the result is negative and already written in two's complement. Try 0101 - 1000 (5 - 8): two's complement of 1000 is 1000, and 0101 + 1000 = 1101 with no carry. In 4-bit signed binary, 1101 is -3, and 5 - 8 = -3. The two's complement calculator shows the working for any value and width.

Binary subtraction with two's complement: invert 0111 to 1000, add 1 to get 1001, add it to 1010 to get 10011, drop the carry to get 0011, which is 3.

Method 3: one's complement with end-around carry

Some older machines used one's complement, which is the inverted bits without the +1. To subtract, add the one's complement of B to A. If a carry falls off the left, add it back to the right end. For 1010 - 0111: invert 0111 to 1000, then 1010 + 1000 = 10010. Take the carry 1 off the left and add it to 0010, which gives 0011, the same 3 as before.

One's complement has two ways to write zero, 0000 and 1111, so every test for zero has to check both patterns. That extra work is a big reason modern processors use two's complement, which has only one zero.

The three methods side by side

MethodStepsUsed byNegative results
Borrowingsubtract column by column, borrow 2 when neededpeople working on paperswap the numbers and add a minus sign
Two's complementinvert B, add 1, add to A, drop the carryalmost every processor todaycome out directly in two's complement
One's complementinvert B, add to A, add the carry backsome older computerscome out inverted

On paper, use borrowing, because you can see every step. If you're learning how a processor does it, or you need negative results, use two's complement. It wins in hardware because the same adder circuit handles both addition and subtraction. To subtract, the circuit inverts B with XOR gates and sets the first carry in to 1, which adds the 1. The half adder and full adder guide shows that circuit, and the binary calculator shows the borrow row for any subtraction.

Common mistakes

  • A digit in your answer isn't 0 or 1. You borrowed 10 out of decimal habit, so 0 - 1 became 9. In binary a borrow is worth 2 in the column that receives it.
  • Two's complement gives 000 for 111 - 1, because inverting a lone 1 and adding 1 gives 1 again. Pad the shorter number first, because the inverted bits need the same width as A. As 111 - 001, the two's complement of 001 is 111, and 111 + 111 = 1110. Drop the carry and you get 110, which is 6.
  • Your answer has one digit too many, like 10011 for 10 - 7. That leftmost 1 is the carry, and with a fixed width you throw it away.
  • You expected -3 and got 13. Both are 1101: it's -3 in 4-bit signed binary and 13 as an unsigned number. Decide which one you mean before you read the result.

Practice problems with answers

ProblemAnswerCheck in decimal
1101 - 011011113 - 6 = 7
10000 - 00011110116 - 3 = 13
11111 - 10101101031 - 21 = 10
101010 - 0101111001142 - 23 = 19
0110 - 1001-116 - 9 = -3

Check any answer by converting both numbers with the binary to decimal converter, or convert a decimal answer back with the decimal to binary converter.

Questions people ask

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 to the left.

How do you borrow in binary subtraction?

Take 1 from the next column to the left. It is worth 2 in the current column, so 0 - 1 becomes 2 - 1 = 1, and the column you borrowed from is reduced by 1.

What is 1 - 1 in binary?

0, with no borrow. 10 - 1 in binary is 1, because 10 is 2 in decimal.

How do computers do binary subtraction?

They add the two's complement. To work out A - B, the processor inverts every bit of B, adds 1, and adds the result to A using the same adder it uses for addition.

How do you subtract a bigger binary number from a smaller one?

With borrowing, swap them, subtract, and put a minus sign in front. With two's complement, add as usual. If there is no carry out, the result is negative and already in two's complement form.

What is the difference between one's and two's complement subtraction?

One's complement only inverts the bits and needs the carry added back at the end. Two's complement inverts and adds 1, and the carry is dropped.

About the authors

Written byUma VictorTechnical writer

Uma Victor is a technical writer and software engineer with seven years of engineering work. He writes API documentation, integration guides and tutorials for developer tools, and his articles have run in Smashing Magazine, freeCodeCamp and LogRocket. He runs the code before he writes about it. On binarytranslator.ai he writes the guides on binary, hex and text encoding.

All guides by UmaLinkedIn

Reviewed bySam SiewertProfessor of computer science, California State University, Chico

Sam Siewert is the O'Connell Endowed Professor of computer science at California State University, Chico, where he teaches numeric and parallel computing, computer vision and machine learning. He has taught real-time embedded systems at the University of Colorado Boulder since 2000 and co-founded its Embedded Systems Engineering program. Both fields depend on how computers store numbers in binary, from fixed-width integers to floating point. He earned his PhD and MS in computer science at the University of Colorado Boulder and is a senior member of IEEE. On binarytranslator.ai he reviews the math behind the converters and the number system guides.

ProfileLinkedInHow we review

Keep reading

All posts
In an 8-bit signed integer, 127 + 1 equals -128.Binary basics

MSB and LSB: most and least significant bits, signed integers and overflow

The MSB is the leftmost, highest-value bit and the LSB the rightmost. See what each tells you, how signed integers use the MSB as a sign bit, and how integer overflow wraps values around.9 min read
In floating point, 0.1 + 0.2 equals 0.30000000000000004.Binary basics

Floating point numbers explained: why 0.1 + 0.2 is not 0.3

A floating point number is scientific notation in binary. See why 0.1 + 0.2 is 0.30000000000000004, how precise floats are, float vs double, and how to compare floats and handle money.9 min read
The hexadecimal number 2F3 equals 755 in decimal.Binary basics

What is hexadecimal? The base 16 number system explained

Hexadecimal is base 16, with digits 0 to 9 and A to F. See how place values work, why programmers use hex for bytes, the values worth knowing and how octal compares.7 min read
Scroll to Top