Binary Subtraction Calculator

Subtract one binary number from another using borrow. Learn the rules of binary subtraction with step‑by‑step examples.

Binary Subtraction Rules: 0–0=0, 0–1=1 with borrow, 1–0=1, 1–1=0. Borrowing reduces the next higher bit by 1 and adds 2 to the current column.

The number we subtract from.
The number to subtract.
1101 – 1010 (13–10)
1111 – 1 (15–1)
1001 – 11 (9–3)
1010 – 101 (10–5)
1100 – 110 (12–6)
101101 – 1001 (45–9)
Calculating...

Understanding Binary Subtraction

Binary subtraction is similar to decimal subtraction, but you only work with 0 and 1. When you need to subtract a larger digit from a smaller one, you borrow from the next higher bit.

? Full Subtractor Truth Table

A full subtractor handles borrow-in from a previous column and produces a borrow-out for the next column. The table below shows all possibilities:

Minuend (A) Subtrahend (B) Borrow-in (Bin) Difference (D) Borrow-out (Bout)
0 0 0 0 0
0 1 0 1 1
1 0 0 1 0
1 1 0 0 0
0 0 1 1 1
0 1 1 0 1
1 0 1 0 0
1 1 1 1 1

? Detailed Borrow Example: 1000₂ – 0011₂

Let’s subtract 0011₂ (3) from 1000₂ (8). This example shows how borrow propagates through multiple zeros.

      (Borrow) →  1 ← ← ← ←
                  ↓
           1 0 0 0   (8)
         – 0 0 1 1   (3)
         ---------
           0 1 0 1   (5)
                        

Step‑by‑step column analysis (right to left):

Column (from right) Minuend Subtrahend Borrow-in Calculation Difference Borrow-out
0 (LSB) 0 1 0 0–1 = –1 → need borrow, so add 2: 2–1=1 1 1
1 0 1 1 (from col0) 0–1–1 = –2 → add 2: 2–2=0 0 1
2 0 0 1 (from col1) 0–0–1 = –1 → add 2: 2–1=1 1 1
3 1 0 1 (from col2) 1–0–1 = 0 0 0

The borrow propagates left until it finds a 1 in the minuend (column 3). The final borrow-out is 0, meaning no overflow.

⚙️ Algorithm Steps (Manual)

  1. Align the numbers by padding the shorter one with leading zeros.
  2. Start from the rightmost bit (LSB) with an initial borrow of 0.
  3. For each column, compute: minuend_bit – subtrahend_bit – borrow_in.
  4. If the result is negative, add 2 to it (since borrowing gives you 2) and set borrow_out = 1 for the next column; otherwise borrow_out = 0.
  5. The computed bit (after adjustment) is the difference bit for that column.
  6. Repeat until all columns are processed.
  7. If the final borrow_out is 1, the result is negative (subtrahend larger). In unsigned arithmetic, we indicate a negative result.

? Relation to Addition

In computer hardware, subtraction is often implemented using addition with two’s complement:
A – B = A + (~B + 1). This avoids separate borrow logic and uses the same adder circuit. For example, to compute 13 – 10, we take two’s complement of 10 (01010₂ → 10110₂) and add:
01101 + 10110 = 100011; discard the carry (the leftmost bit) to get 00011₂ = 3.

Calculator Features:

  • ✅ Input validation (only digits 0 and 1 allowed).
  • ✅ Handles binary numbers of any length (using BigInt).
  • ✅ If the result is negative, displays a minus sign and the absolute difference.
  • ✅ Shows decimal equivalents for easy verification.
  • ✅ Example buttons provide quick tests of common borrow scenarios.
  • ✅ NEW: Detailed borrow steps table (click "Show Detailed Borrow Steps").

❓ Frequently Asked Questions

The calculator will show a negative result with a minus sign (e.g., 101₂ – 110₂ = –1₂). The absolute difference is displayed in binary. This is equivalent to performing subtraction in decimal and then converting the absolute value.

When you borrow, you effectively add 2 to the current column (since 10₂ = 2) and subtract 1 from the next higher column. This is exactly the same as borrowing in decimal, but you borrow 2 instead of 10.

This calculator performs unsigned binary subtraction. For signed numbers, you would typically use two's complement representation. However, the result with a minus sign gives you the correct magnitude.