Skip to content
Math

Binary Subtraction Calculator

Enter two binary numbers to subtract them instantly. Choose the borrow (direct) method or the two's complement method, pick a bit width (4, 8, 16, or 32 bits), and see the full column-by-column working. Results include the binary answer, its unsigned and signed decimal equivalents, and an overflow flag.

Your details

The binary number you are subtracting FROM (e.g. 1101 = decimal 13). Use only 0 and 1.
The binary number being subtracted (e.g. 0101 = decimal 5). Use only 0 and 1.
The register size for the calculation. Affects overflow detection and sign interpretation.
Borrow: subtract column by column, borrowing from higher bits. Two's complement: invert B, add 1, then add to A.
Binary result (A - B)Positive result
00001000

The difference expressed in binary, padded to the selected bit width.

Decimal (unsigned)8
Decimal (signed)8
A in decimal13
B in decimal5
OverflowNo
Final borrow0 (no borrow)
A (decimal)13
B (decimal)5
A - B (signed)8

1101 - 0101 = 00001000

  • 1101 (decimal 13) minus 0101 (decimal 5) = 00001000 (decimal 8 unsigned, 8 signed in 8-bit).
  • The borrow method mirrors pencil-and-paper decimal subtraction: when a column has 0 - 1, borrow from the next higher bit, turning that bit from 1 to 0 and giving the current column 2 to work with.

Next stepTo verify: convert the binary result 00001000 back to decimal using positional weights (powers of 2). It should equal 8.

Formula

AB=A+(B+1)(mod2n)A - B = A + (\overline{B} + 1) \pmod{2^n}

Worked example

Subtract 0101 (5) from 1101 (13) in 8-bit: direct borrow gives 00001000 (8). Two's complement: invert 00000101 to 11111010, add 1 to get 11111011, add to 00001101, carry-out discarded, result 00001000 = 8.

Binary subtraction basics

Binary subtraction follows the same positional logic as decimal subtraction but with only two digit values: 0 and 1. There are four fundamental cases per column: 0 - 0 = 0, 1 - 0 = 1, 1 - 1 = 0, and 0 - 1 = 1 with a borrow of 1 from the next column. That borrow propagates upward exactly like borrowing a 10 in decimal, except here you borrow a 2 (since 10 in binary equals 2 in decimal). Understanding these four rules is enough to subtract any two binary numbers by hand.

How the two's complement method works

Two's complement is the method used by virtually every modern CPU because it allows subtraction to be performed with an addition circuit. To subtract B from A, you first compute the two's complement of B by inverting all its bits (giving the ones complement) and then adding 1. You then add this value to A using regular binary addition. If a carry-out emerges from the most significant bit, discard it - the remaining bits are the positive result. If there is no carry-out, the result is negative and is itself in two's complement form. This approach also means that positive and negative integers can share the same adder hardware.

Bit width, overflow, and signed representation

The bit width you choose sets the size of the register and controls two things: the range of values it can represent and whether overflow is reported. For an 8-bit signed register the range is -128 to +127; for a 16-bit register it is -32768 to +32767. Overflow happens when the true mathematical result falls outside that range, for example subtracting -100 from +100 in an 8-bit signed system gives +200, which exceeds +127. When overflow occurs, real processors set an overflow flag (often called V or OV) but continue the calculation modularly. This calculator flags overflow for you alongside the unsigned and signed decimal interpretations of the raw bit pattern.

Borrow method vs two's complement: which to use?

Use the borrow method when learning or checking arithmetic by hand - it matches pencil-and-paper decimal subtraction and the column-by-column steps are easy to trace. Use the two's complement method when studying computer architecture or programming, because it reflects exactly what the ALU (Arithmetic Logic Unit) does inside a processor. Both methods always produce the same bit pattern in the result register for any given pair of inputs and bit width. The difference is only in the intermediate working.

Binary subtraction rules (borrow method)

A (top digit)B (bottom digit)Borrow inDigit resultBorrow out
0000 0
1001 0
1100 0
0101 1
0011 1
1010 0
1111 1
0110 1

The four fundamental cases when subtracting a single column of two binary digits.

Frequently asked questions

What happens when the result is negative in binary?

In the borrow method a borrow-out from the MSB means A < B, so the result is negative. The bit pattern you see is actually the two's complement representation of the negative number. For example, in 4-bit arithmetic 0011 - 0101 = 1110, and 1110 as a two's complement signed number is -2, which matches 3 - 5 = -2.

What is two's complement and why does it matter?

Two's complement is the standard way to represent signed integers in binary computers. To negate a number, flip all its bits and add 1. This encoding has a crucial advantage: addition and subtraction circuits can be combined into a single adder with no extra logic, which is why almost every CPU since the 1970s uses it. The range for an n-bit two's complement number is -2^(n-1) to 2^(n-1) - 1.

What is binary overflow?

Overflow occurs when an arithmetic result exceeds the range that a given number of signed bits can represent. In 8-bit signed arithmetic the range is -128 to 127. If A - B would give a result outside that range, the bit pattern wraps around and the result is incorrect unless you check the overflow flag. Unsigned overflow (also called a carry or borrow out) is a different condition: it happens when the true unsigned result exceeds 2^n.

Can I subtract a larger binary number from a smaller one?

Yes. When A < B, the borrow method produces a borrow-out of 1 from the MSB, and the bit pattern is the two's complement of the absolute difference. If you interpret the result as a signed number it gives you the correct negative value. If you interpret it as unsigned it wraps around (for example in 4-bit: 0 - 1 = 15 unsigned, or -1 signed). This calculator shows both interpretations.

How do I convert a binary number to decimal?

Assign each bit a place value that is a power of 2, starting from 2^0 at the rightmost bit. Multiply each bit (0 or 1) by its place value and sum the results. For example 1101 = 1x8 + 1x4 + 0x2 + 1x1 = 8 + 4 + 0 + 1 = 13. This calculator shows the decimal equivalents of both inputs and the result automatically.

Why does this calculator pad binary numbers with leading zeros?

Leading zeros are added to make both numbers the same width as the selected bit register. This is how real hardware works: an 8-bit register always holds exactly 8 bits, and the leading zeros are physically present. Padding makes the column alignment and two's complement inversion unambiguous. It does not change the numeric value.

Sources

Written by Dr. Rajiv Menon, PhD Applied Mathematician · Bengaluru, India

Applied mathematician bridging algebraic theory and computational tools for students, engineers, and everyday problem-solvers.

Search 3,500+ calculators

Loading search…