digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksToolsOpen the lab →

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.

Live circuit: click the inputs to toggle them and watch the outputs update. It runs the real simulator, right here on the page.

Open this circuit in the lab →

What you need

Step by step

  1. Place two inputs, A (the minuend) and B (the subtrahend).
  2. Wire both inputs into an XOR gate. Its output is the difference bit D: it is 1 when the bits differ, which is exactly when 0 minus 1 or 1 minus 0 leaves a 1.
  3. Invert A with a NOT gate, then AND that with B. The result is the borrow bit Bout: it is 1 only in the 0 minus 1 case, when you must borrow from the next column.
  4. Send the XOR output to a probe labelled D and the AND output to a probe labelled Bout. That is the whole half subtractor.

Half subtractor truth table

ABDBout
0000
0111
1010
1100

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.