How to build a half subtractor from logic gates
A half subtractor finds the difference of two single bits and is built from three gates: one XOR gate gives the difference, and a NOT feeding an AND gives the borrow.
It is the subtraction counterpart of the half adder: two inputs, two outputs, and no borrow coming in (that is what makes it a half subtractor). It computes A minus B, giving a difference bit D and a borrow-out bit Bout that is 1 when B is larger than A.
Open this circuit in the lab →
What you need
- 1× XOR — the difference bit D = A XOR B
- 1× NOT — inverting A for the borrow term
- 1× AND — the borrow bit Bout = (NOT A) AND B
Step by step
- Place two inputs,
A(the minuend) andB(the subtrahend). - Wire both inputs into an
XORgate. Its output is the difference bitD: it is 1 when the bits differ, which is exactly when 0 minus 1 or 1 minus 0 leaves a 1. - Invert
Awith aNOTgate, thenANDthat withB. The result is the borrow bitBout: it is 1 only in the 0 minus 1 case, when you must borrow from the next column. - Send the XOR output to a probe labelled
Dand the AND output to a probe labelledBout. That is the whole half subtractor.
Half subtractor truth table
| A | B | D | Bout |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
Read the second row: 0 minus 1 cannot be done in the column, so the difference is 1 and a borrow of 1 is taken from the next column. Chain a half subtractor's borrow into a full subtractor and you can subtract wider numbers.
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 half subtractor in the lab →Frequently asked
What gates make a half subtractor?
A half subtractor is one XOR gate, one NOT gate, and one AND gate. The XOR gives the difference (A XOR B) and the NOT feeding an AND gives the borrow ((NOT A) AND B).
What is the difference between a half subtractor and a half adder?
They share the XOR for the sum or difference bit, but the second output differs: a half adder's carry is A AND B, while a half subtractor's borrow is (NOT A) AND B. The half subtractor borrows when B is larger than A.
What is the borrow expression of a half subtractor?
Bout = (NOT A) AND B. The borrow is 1 only when A is 0 and B is 1, the single case (0 minus 1) where the column cannot subtract without borrowing from the next one.