Build a 4-bit Binary Calculator Using Only NAND Gates

Ever tried to add two numbers on a piece of paper and thought, “What if I could do this with just a handful of tiny chips?” In today’s maker‑friendly world, a 4‑bit binary calculator built only from NAND gates is a perfect weekend project. It teaches you how any logic function can be reduced to a single gate, and you end up with a tiny, brag‑worthy device that actually works.

Why NAND‑Only?

NAND is called the “universal gate” because you can make every other gate—AND, OR, NOT, XOR—from it. If you can master NAND, you’ve mastered the whole language of digital electronics. Plus, NAND chips are cheap and plentiful; you’ll find them in almost any hobby store. Building a calculator this way forces you to think in the most fundamental terms, which is exactly the kind of mental workout I love sharing on GateCraft.

The Building Blocks

Before we dive into the calculator, let’s recap the basic NAND‑derived gates we’ll need. I’ll keep the diagrams simple—just a few truth tables and a short description.

NOT (Inverter)

A NOT gate flips a bit. With NAND, tie the two inputs together:

A ──┐
    NAND ──> NOT A
A ──┘

If A is 0, both inputs are 0, NAND outputs 1. If A is 1, both inputs are 1, NAND outputs 0.

AND

An AND gate can be built by NAND‑then‑NOT:

A ──┐
    NAND ──┐
B ──┘       NAND ──> A·B
            (output of first NAND tied together)

OR

OR needs a little more work. First invert each input, then NAND the results:

A ──┐      ┐
    NAND ──┘
A ──┘      │
           NAND ──> A+B
B ──┐      │
    NAND ──┘
B ──┘

XOR (Exclusive‑OR)

XOR is the heart of addition. One compact NAND‑only form uses four NAND gates:

A ──┐      ┐
    NAND ──┘
B ──┘      │
           NAND ──┐
A ──┐      │       ┐
    NAND ──┘       │
B ──┘              NAND ──> A⊕B
                    (output of previous NANDs tied together)

Don’t worry if the diagram looks messy; the truth table is what matters: XOR outputs 1 only when the inputs differ.

Designing the 4‑bit Adder

A binary calculator needs two main parts:

  1. A 4‑bit adder that adds two numbers and produces a 4‑bit sum plus a carry‑out.
  2. Control logic to handle subtraction, clear, and maybe a simple display driver.

For this guide we’ll stick to addition only. Subtraction can be added later by using two’s complement, but that would double the gate count and is a fun challenge for later.

Step 1: Create a Full‑Adder Cell

A full‑adder takes three inputs: A, B, and Carry‑In (Cin). It produces two outputs: Sum and Carry‑Out (Cout). Using NAND‑derived gates, the classic equations are:

Sum = A ⊕ B ⊕ Cin
Cout = (A·B) + (Cin·(A⊕B))

We already have XOR, AND, and OR built from NAND, so we can assemble the cell.

Gate count per cell:

  • XOR for A⊕B → 4 NANDs
  • XOR for (A⊕B)⊕Cin → another 4 NANDs
  • AND for A·B → 2 NANDs (NAND then NOT)
  • AND for Cin·(A⊕B) → 2 NANDs (reuse the A⊕B result)
  • OR to combine the two AND results → 3 NANDs (two NOTs then NAND)

Total: 15 NAND gates per full‑adder. Not pretty, but it proves the concept.

Step 2: Chain Four Cells

Connect four full‑adder cells in series, feeding the Cout of the lower‑order cell into the Cin of the next higher‑order cell. The least‑significant bit (LSB) gets Cin = 0 (ground). The final Cout becomes the overflow flag.

Cell 0 (LSB): A0 B0 Cin=0 → Sum0, C0
Cell 1:       A1 B1 C0   → Sum1, C1
Cell 2:       A2 B2 C1   → Sum2, C2
Cell 3 (MSB): A3 B3 C2   → Sum3, C3 (overflow)

Because each cell reuses the same NAND‑derived building blocks, you can copy‑paste the schematic on your breadboard or PCB layout.

Step 3: Wire the Inputs

You’ll need eight switches (or push‑buttons) for the two 4‑bit numbers. Label them A0‑A3 and B0‑B3. Connect each switch to the appropriate input pin of the NAND chips. Pull‑down resistors keep the lines low when the switch is open.

Step 4: Build the Output Display

For a quick visual, use four LEDs for the sum bits and a fifth LED for overflow. Each LED’s anode goes to a current‑limiting resistor (≈330 Ω) and then to the corresponding Sum output. Ground the LED cathodes.

If you want a more polished look, you can drive a 7‑segment display with a small decoder, but that adds extra chips and moves away from the pure NAND theme.

Step 5: Power and Ground

All NAND chips (74LS00 or 74HC00) run happily at 5 V. Connect VCC to the chip’s power pin and GND to the ground pin. Decouple each chip with a 0.1 µF ceramic capacitor close to the pins; this keeps the logic stable.

Putting It All Together

  1. Lay out the NAND chips on a breadboard in a tidy grid. Keep the power rails clean.
  2. Insert the NOT, AND, OR, XOR sub‑circuits as described. Double‑check each connection against the truth tables.
  3. Connect the full‑adder cells in series, making sure the carry lines line up correctly.
  4. Hook up the input switches and LED outputs. Test each bit individually before trying a full addition.
  5. Power up and try adding 0011 (3) and 0101 (5). You should see 1000 (8) light up on the sum LEDs, with no overflow.

If something doesn’t work, the first place to look is the XOR blocks—they’re the most gate‑heavy and easy to mis‑wire. A quick continuity check with a multimeter usually catches stray connections.

Lessons Learned

  • Universal gates are truly universal. Even a modest project like this forces you to break down every operation into NANDs, reinforcing the underlying logic.
  • Gate count matters. While 60‑plus NAND chips look intimidating, the exercise shows why designers use higher‑level gates in real chips—they save space, power, and cost.
  • Debugging is a skill. Tracing a wrong LED back to a single NAND pin is satisfying. It’s the same joy I felt when I first built a flip‑flop from scratch in my undergrad lab.

Next Steps

Now that you have a working adder, you can expand the calculator:

  • Add a subtract mode by feeding the two’s complement of B into the adder (invert B and set Cin = 1).
  • Implement a simple control unit with a few more NAND gates to toggle between add and subtract.
  • Replace the LED display with a binary‑to‑BCD decoder and a 7‑segment driver for a more user‑friendly readout.

Each addition will increase the NAND count, but the core idea stays the same: build everything from the humble NAND gate and watch the magic happen.

Happy hacking, and may your gates always be low‑noise!

Reactions
Do you have any feedback or ideas on how we can improve this page?