Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksBuild a CPUToolsOpen the lab →

4-bit subtractor: A minus B with four full adders, live

A 4-bit subtractor computes D = A - B by adding the two's complement of B: four full adders in a ripple chain, an inverter on each B bit, and the first carry-in tied to 1, so the adders compute A + NOT B + 1. The borrow Bout = NOT Cout is 1 when B is larger than A.

Subtracting with an adder needs one identity: in 4 bits, minus B is NOT B + 1 (the two's complement). The inverters make NOT B, and the 1 enters as the carry into the lowest full adder, so no extra adder is needed for it. The carry out of the top adder then means "no borrow": it is 1 when A is at least B and 0 when the subtraction wrapped around, so the borrow output is its inverse. Read D as an unsigned difference when Bout = 0; when Bout = 1, D is the 4-bit two's-complement result, for example 3 - 5 gives 1110, which is -2. This is a subtract-only circuit; the 4-bit adder/subtractor swaps the fixed inverters for XOR gates and the fixed 1 for a SUB input, so one circuit does both. The bit-by-bit alternative is a chain of full subtractors, which compute the same D and borrow with borrow logic instead of an adder.

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 →

Embed or cite this circuit

Free to embed on a course page, blog or worksheet: paste this code. The circuit stays live, and the small digiwleea badge links back here.

To cite it: digiwleea, “4-bit subtractor”, https://digiwleea.wleeaf.dev/tools/build/subtractor-4bit/

What you need

Step by step

  1. Place inputs A3 to A0 and B3 to B0, and probes D3 to D0 and Bout.
  2. Chain four full adders: each carry out feeds the next carry in.
  3. Feed A straight into the adders and B through a NOT gate per bit.
  4. Tie the carry in of bit 0 to 1, and invert the last carry out to get Bout.
  5. Try 9 - 4: D = 0101 (5) and Bout = 0. Then 4 - 9: D = 1011 (-5 in two's complement) and Bout = 1.

4-bit subtractor: example rows

ABA + NOT B + 1D3..D0Bout
9 (1001)4 (0100)1001 + 1011 + 1 = 1 01010101 (5)0
7 (0111)7 (0111)0111 + 1000 + 1 = 1 00000000 (0)0
15 (1111)1 (0001)1111 + 1110 + 1 = 1 11101110 (14)0
3 (0011)5 (0101)0011 + 1010 + 1 = 0 11101110 (-2)1
0 (0000)1 (0001)0000 + 1110 + 1 = 0 11111111 (-1)1

The leading digit of the sum is the carry out; Bout is its inverse. Before the page is built, all 256 pairs of A and B are checked on the live circuit against ordinary 4-bit subtraction.

You can also read the full theory in the lesson on negative numbers and 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.

More builds: Arithmetic

All 246 build guides, by topic

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, with the free theory reference alongside.

Open the 4-bit subtractor in the lab →

Frequently asked

How do you make a 4-bit subtractor?

Use a 4-bit ripple-carry adder, invert every bit of B, and set the first carry in to 1. The adder then computes A + NOT B + 1, which is A - B in two's complement.

What does the borrow output of a 4-bit subtractor mean?

Bout = 1 means B was larger than A, so the result went below zero and D holds the negative difference in two's complement. With this adder design, Bout is the inverse of the last carry out.

Why is the carry in set to 1 in a subtractor?

Because the two's complement of B is NOT B plus 1. Feeding the 1 in as the first carry adds it without a separate adder.

What is the difference between a subtractor and an adder-subtractor?

A subtractor always computes A - B. An adder-subtractor has a mode input that XORs B and sets the carry in, so the same circuit adds when the mode is 0 and subtracts when it is 1.