How to build a full subtractor from logic gates
A full subtractor subtracts three bits (A, B and a borrow-in) and is built from two XOR gates, two NOT gates, two AND gates, and one OR gate: two half subtractors joined by an OR.
Unlike a half subtractor, a full subtractor has a borrow input, so you can chain one per bit to subtract whole numbers. It takes A, B and a borrow-in Bin, and produces a difference bit D and a borrow-out Bout.
Open this circuit in the lab →
What you need
- 2× XOR — the difference: D = A XOR B XOR Bin
- 2× NOT — inverting A, and the first difference, for the borrow terms
- 2× AND — the two borrow-generating terms
- 1× OR — combining the borrow terms into Bout
Step by step
- Place three inputs:
A,Band the borrow-inBin. - XOR
AandBin a firstXORgate to get the half-difference, then XOR that withBinin a secondXORgate. The result is the difference bitD. - Invert
AandANDit withB: this is the borrow generated by the first stage, (NOT A) AND B. - Invert the first XOR's half-difference and
ANDit withBin: this is the borrow generated when the incoming borrow cannot be covered. - OR the two AND outputs together. That
ORgate's output is the borrow-outBout. ProbeDandBoutand the full subtractor is done.
Full subtractor truth table
| 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 |
The borrow-out is 1 whenever B plus the incoming borrow exceeds A. Wire the borrow-out of one full subtractor into the borrow-in of the next and you have a ripple-borrow subtractor that subtracts multi-bit numbers, the mirror image of the ripple-carry adder.
You can also read the full theory in the lesson on binary subtraction. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.
Build more parts from gates
Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab and course.
Open the full subtractor in the lab →Frequently asked
What gates are needed for a full subtractor?
A full subtractor uses two XOR gates, two NOT gates, two AND gates, and one OR gate. The XORs make the difference bit, and the two ANDs feeding an OR make the borrow-out.
How do you build a full subtractor from two half subtractors?
Feed A and B into the first half subtractor, then feed its difference and the borrow-in into a second half subtractor. The second half subtractor's difference is the final difference; OR the two half subtractors' borrow outputs to get the borrow-out.
What is the borrow-out logic of a full subtractor?
Bout = ((NOT A) AND B) OR ((NOT (A XOR B)) AND Bin). The first term is the borrow generated by A minus B; the second passes on the incoming borrow when the first difference could not absorb it. It equals the standard form A'B + A'Bin + B Bin.
What is the difference between a full subtractor and a full adder?
Both take three input bits and give two outputs. The difference bit D = A XOR B XOR Bin is identical in form to an adder's sum, but the borrow logic inverts A where the adder's carry does not, so a subtractor borrows where an adder carries.