# Full subtractor

*One column of the borrow chain*

A full subtractor subtracts three bits, the minuend bit A minus the subtrahend bit B minus a borrow-in, producing a Difference bit and a Borrow out. Chaining one per bit position, borrow-out into borrow-in, subtracts whole binary numbers exactly as chained full adders add them.

Group: Arithmetic
URL: https://digiwleea.wleeaf.dev/learn/full-subtractor/

The [half subtractor](https://digiwleea.wleeaf.dev/learn/half-subtractor/) handles the rightmost column of a subtraction, where nothing is owed yet. Every other column has to settle a possible debt from the column below it: subtract `A - B`, and *also* pay back the borrow that column raised. So a real subtraction column takes **three** inputs: `A`, `B`, and `Bin` (borrow-in), and produces a Difference `D` plus a `Bout` that passes any new debt one column up. This is the [full adder](https://digiwleea.wleeaf.dev/learn/fulladder/)'s mirror image, column for column.

Work it on paper the way you subtract decimals. In each column you compute `A - B - Bin`. If the result is `0` or `1`, write it down and owe nothing. If it goes negative, borrow a `2` from the next column: write down the result plus `2`, and raise `Bout = 1`. For example `0 - 1 - 1 = -2`: borrow a two, write `-2 + 2 = 0`, owe `1`. And `1 - 1 - 1 = -1`: borrow, write `-1 + 2 = 1`, owe `1`.

| A | B | Bin | D | Bout |
| --- | --- | --- | --- | --- |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 |

_Full subtractor truth table: each row computes A - B - Bin. D is 1 when an odd number of the three inputs are 1, exactly like the full adder's Sum. Bout is 1 whenever B + Bin exceeds A._

> **KEY:** Two patterns worth memorizing. First, `D = A XOR B XOR Bin`, the **identical** parity function as the full adder's Sum: the difference column of subtraction and the sum column of addition are the same gate. Second, the borrow mirrors the carry with one inversion: the full adder's `COUT` is `1` when at least two of `A, B, CIN` are `1`, and the full subtractor's `Bout` is `1` when at least two of `NOT A, B, Bin` are `1`. Invert the minuend and the carry logic *becomes* the borrow logic.

```
D = A XOR B XOR Bin
```

```
Bout = ((NOT A) AND B) OR ((NOT (A XOR B)) AND Bin)
```

## Building it from two half subtractors and an OR

Just as a [full adder](https://digiwleea.wleeaf.dev/learn/fulladder/) is two half adders plus an OR, a full subtractor is two [half subtractors](https://digiwleea.wleeaf.dev/learn/half-subtractor/) plus an [OR](https://digiwleea.wleeaf.dev/learn/or/). The first half subtractor computes `A - B`; the second subtracts `Bin` from that partial result. Each stage can raise a borrow, and the two borrows merge through the OR. They are never both `1` at once (the first borrows only when `A = 0, B = 1`, and in that case the partial difference is `1`, which the second stage can always cover), so a plain OR is enough.

1. Place two half subtractor parts (HS1 and HS2) and one OR part.
2. Feed `A` and `B` into HS1. It produces a partial difference `d1 = A XOR B` and a borrow `b1`.
3. Feed `d1` and `Bin` into HS2 (with `d1` as the minuend). It produces the final Difference `D` and a borrow `b2`.
4. Feed `b1` and `b2` into the OR gate. Its output is `Bout`.
5. Label HS2's difference `D` and the OR output `Bout`.

_Circuit diagram: Full subtractor from two half subtractors (each an XOR plus a NOT-AND borrow) and one OR merging the borrows. Step through the eight rows, or follow the gate-by-gate version in [how to build a full subtractor](/tools/build/full-subtractor/)._

## Chaining columns: the ripple-borrow subtractor

Now subtract whole numbers. Line up one full subtractor per bit, wire each `Bout` into the `Bin` of the next column to the left, and tie the rightmost `Bin` to `0`. Here is `0110 - 0011` (six minus three), column by column from the right:

1. Column 0: `0 - 1 - 0` goes negative, so borrow: `D = 1`, `Bout = 1`.
2. Column 1: `1 - 1 - 1 = -1`, borrow again: `D = 1`, `Bout = 1`. The debt ripples leftward.
3. Column 2: `1 - 0 - 1 = 0`, the debt is absorbed: `D = 0`, `Bout = 0`.
4. Column 3: `0 - 0 - 0`: `D = 0`, `Bout = 0`. Read the result `0011`, which is three. Six minus three is three.

> **WARN:** **Watch the final borrow.** Subtract the other direction, `0011 - 0101` (three minus five), and the chain outputs `D = 1110` with the last `Bout = 1`. As an unsigned number `1110` reads fourteen, which looks wrong, but it is not garbage: `1110` is exactly the [two's complement](https://digiwleea.wleeaf.dev/learn/twos-complement/) pattern for `-2`, and the raised final borrow is the machine's flag that the true result went below zero (for unsigned numbers, `Bout = 1` simply means `A < B`). A ripple-borrow chain quietly produces two's complement answers whether you asked for them or not.

> **KEY:** That is the perfect setup for the punchline taught in [negative numbers and subtraction](https://digiwleea.wleeaf.dev/learn/subtract/): hardware rarely builds this dedicated borrow chain at all. Since `A - B = A + (NOT B) + 1`, one XOR per bit turns the existing [adder](https://digiwleea.wleeaf.dev/learn/adder8/) into a subtractor, and the two designs agree bit for bit; even the flags line up, since the adder's final carry-out is always the exact inverse of this chain's final borrow-out. A CPU that built both circuits would be paying twice for the same answers, so the [ALU](https://digiwleea.wleeaf.dev/learn/alu/) keeps one adder and a row of XORs, and the full subtractor remains the clearest way to *understand* what that trick is computing.

**Q (Try it):** Trace `A = 1, B = 1, Bin = 1` through the two-half-subtractor build: what are `d1` and `b1` from the first stage, `D` and `b2` from the second, and the final `Bout`?

**A:** HS1 computes `d1 = 1 XOR 1 = 0` and `b1 = (NOT 1) AND 1 = 0`: the `1 - 1` part settles with no borrow. HS2 then computes `0 - 1`: `D = 0 XOR 1 = 1` and `b2 = (NOT 0) AND 1 = 1`. The OR merges the borrows: `Bout = 0 OR 1 = 1`. So `1 - 1 - 1` gives `D = 1, Bout = 1`, matching the truth table: borrow a two, write `-1 + 2 = 1`, owe one.

### FAQ

**Q:** What is a full subtractor?

**A:** A full subtractor subtracts three bits, `A - B - Bin` (minuend, subtrahend, and the borrow coming in from the column below), producing a Difference `D` and a Borrow out `Bout` that passes any new debt to the next column. Chaining one per bit position subtracts multi-bit binary numbers.

**Q:** What is the full subtractor truth table?

**A:** Eight rows, one per combination of `A`, `B`, `Bin`. The Difference is `D = A XOR B XOR Bin` (`1` when an odd number of inputs are `1`). The borrow `Bout` is `1` in exactly four rows: `0-0-1`, `0-1-0`, `0-1-1`, and `1-1-1`, that is, whenever `B + Bin` is more than `A`.

**Q:** What is the difference between a full adder and a full subtractor?

**A:** Their first outputs are identical: the [full adder](https://digiwleea.wleeaf.dev/learn/fulladder/)'s Sum and the full subtractor's Difference are both `A XOR B XOR` the third input. The second outputs mirror each other: the adder's carry is `1` when at least two of `A, B, CIN` are `1`, while the subtractor's borrow is `1` when at least two of `NOT A, B, Bin` are `1`. Inverting the minuend inside the second-output logic is the entire difference.

**Q:** How do you build a full subtractor from half subtractors?

**A:** From two [half subtractors](https://digiwleea.wleeaf.dev/learn/half-subtractor/) and one [OR](https://digiwleea.wleeaf.dev/learn/or/) gate, mirroring the full adder build. The first half subtractor computes `A - B`; the second subtracts `Bin` from that partial difference; the OR merges the two borrows into `Bout`. The two borrows are never both `1` at once, which is why a plain OR is safe.

**Q:** Why do computers subtract with two's complement instead of a subtractor circuit?

**A:** Because one adder can then do both jobs. `A - B = A + (NOT B) + 1`, so a row of [XOR](https://digiwleea.wleeaf.dev/learn/xor/) gates (to conditionally invert `B`) plus a carry-in of `1` turns the existing adder into a subtractor, as taught in [negative numbers and subtraction](https://digiwleea.wleeaf.dev/learn/subtract/). A dedicated ripple-borrow subtractor produces bit-identical results but duplicates nearly all of the adder's hardware, so ALUs build the adder once and steer it.
