Skip to main content
Be Bitwise

From Gates to Circuits

Transistors to Processors · Hardware Foundations track

4 min read

In this module

Transistors Become Logic

Transistors are switches. A handful of them, wired together in the right pattern, become a logic gate — a circuit that implements a fixed Boolean operation on its inputs.

Every gate takes one or more binary inputs and produces a single binary output. The rule is captured in a truth table: every possible input combination, and the output each produces.

The Core Gates

NOT Gate (Inverter)

The simplest gate. It flips a single input: 0 becomes 1, and 1 becomes 0. In CMOS, a NOT gate uses just one PMOS and one NMOS transistor.

ANOT A
01
10

AND Gate

Outputs 1 only when both inputs are 1.

ABA AND B
000
010
100
111

OR Gate

Outputs 1 when at least one input is 1.

ABA OR B
000
011
101
111

NAND Gate

The inverse of AND - outputs 0 only when both inputs are 1. In CMOS, a NAND gate is actually simpler to build than an AND gate, requiring just four transistors (two PMOS in parallel, two NMOS in series).

ABA NAND B
001
011
101
110

NOR Gate

The inverse of OR - outputs 1 only when both inputs are 0.

ABA NOR B
001
010
100
110

XOR Gate (Exclusive OR)

Outputs 1 when exactly one input is 1, but not both. XOR is essential for arithmetic circuits - it produces the sum bit in binary addition.

ABA XOR B
000
011
101
110
Key Concept

The NAND gate is a universal (functionally complete) gate. Using only NAND gates, you can build NOT, AND, OR, XOR - every possible logic function. This is why NAND is the most common gate in real chip designs: it is the simplest to manufacture in CMOS and can express any computation.

NAND: The Universal Gate

This is one of digital logic's genuinely elegant results. One gate type — NAND — can implement any Boolean function. The construction is simple:

  • NOT from NAND: tie both inputs to the same signal. A NAND A equals NOT A.
  • AND from NAND: pass a NAND output through a second NAND-as-NOT. Double negation gives AND.
  • OR from NAND: invert each input with NAND-as-NOT, then NAND the two results. De Morgan's law makes this produce OR.

Chip designers use NAND as their default building block because it's the most efficient gate in CMOS — fewer transistors, tighter layout.

Boolean Algebra Basics

Logic gates obey the rules of Boolean algebra, a mathematical system where variables can only be 0 or 1. A few essential laws:

  • Identity: A AND 1 = A, A OR 0 = A
  • Null: A AND 0 = 0, A OR 1 = 1
  • Complement: A AND (NOT A) = 0, A OR (NOT A) = 1
  • De Morgan's Laws: NOT (A AND B) = (NOT A) OR (NOT B) and NOT (A OR B) = (NOT A) AND (NOT B)

De Morgan's laws are worth drilling. They expose AND and OR as duals of each other — and that duality is exactly why both NAND and NOR are individually sufficient to express any logic function.

Try It Yourself

Time to check those NAND recipes. Each circuit below is already wired, and every gate starts as an AND. Click a gate to flip it between AND and NAND, and find the setting that makes the truth table match the target; wrong outputs get a cross. Before you click, predict which gates need to be NAND.

First, OR from three gates. The two gates on the left have both inputs tied together, the NAND-as-NOT trick from above:

Click an input to toggle it, or a gate to change its type.
0A0BANDnaANDnbANDy0A OR B

2 of 4 rows match the target. Wrong outputs are marked with a cross.

Truth table
ABA OR B
000
010 ✗
100 ✗
111

Now XOR from four gates. This is the standard four-NAND XOR, and with only AND and NAND to choose from there's exactly one setting that works:

Click an input to toggle it, or a gate to change its type.
0A0BANDn1ANDn2ANDn3ANDy0A XOR B

1 of 4 rows match the target. Wrong outputs are marked with a cross.

Truth table
ABA XOR B
000
010 ✗
100 ✗
111 ✗

AND from NAND takes just two gates: one NAND, then a second NAND with both inputs tied to the first one's output, which inverts it back.

Understanding how gates combine is the first step toward building real computational circuits. In the next lessons, we will use these gates to construct the core of a processor.