How Binary Subtraction Works
Binary subtraction follows the same place-value logic as subtracting decimal numbers, except every digit (bit) can only be 0 or 1. This calculator computes the exact difference of two binary numbers, shows the result in binary and decimal, and — when the result is negative — displays it in two's complement, the format computers use to store negative binary values in a fixed number of bits.
The borrow method
Working from the rightmost bit, subtract each pair of bits and record a borrow whenever the top bit is smaller than the bottom bit, exactly as in decimal long subtraction. The rules are: 0 − 0 = 0, 1 − 0 = 1, 1 − 1 = 0, and 0 − 1 = 1 with a borrow of 1 taken from the next column to the left. This calculator performs the equivalent operation by converting both binary numbers to decimal (A and B), computing A − B, and converting the difference back to base 2 — the two approaches always agree, because binary is simply base-2 place value.
Two's complement for negative results
When B is larger than A, the true difference is negative, and computers represent that value in two's complement rather than with a minus sign. To find the two's complement of a positive binary number within a fixed bit width: invert every bit (0 becomes 1, 1 becomes 0), then add 1. For example, the 8-bit two's complement of 8 (00001000) is 11111000, which is how a processor register would store −8. This calculator wraps the difference into the selected bit width using modular arithmetic, which produces the identical result.
Choosing a bit width
The bit width only affects the two's complement output — it must be large enough to hold both input values, or the calculator flags the inputs as out of range. Common widths are 4 bits (a nibble, values 0–15), 8 bits (a byte, values 0–255), and 16 bits (values 0–65,535), matching how registers and memory cells are typically sized.
Worked example
11012 (13 in decimal) minus 1012 (5 in decimal) equals 10002 (8 in decimal) — no final borrow remains once the column-by-column subtraction is complete. Reverse the operands (101 − 1101) and the true difference is −8; the calculator reports the magnitude as −1000 in binary and its 8-bit two's complement as 11111000.