digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksToolsOpen the lab →

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.

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 three inputs: A, B and the borrow-in Bin.
  2. XOR A and B in a first XOR gate to get the half-difference, then XOR that with Bin in a second XOR gate. The result is the difference bit D.
  3. Invert A and AND it with B: this is the borrow generated by the first stage, (NOT A) AND B.
  4. Invert the first XOR's half-difference and AND it with Bin: this is the borrow generated when the incoming borrow cannot be covered.
  5. OR the two AND outputs together. That OR gate's output is the borrow-out Bout. Probe D and Bout and the full subtractor is done.

Full subtractor truth table

ABBinDBout
00000
00111
01011
01101
10010
10100
11000
11111

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.