← All animations

πŸ”² Logic Gates to a CPU

Every computer, underneath all the software, is just billions of tiny switches doing arithmetic with two values: 0 and 1. A handful of logic gates β€” AND, OR, NOT, XOR, NAND β€” turn those values into decisions. Wire a few together and you can add numbers. Wire billions together and you get a CPU. Scroll down, flip some bits, and watch the signal flow.

1. The basic gates β€” flip the inputs, watch the output

A gate takes one or two inputs (each 0 or 1) and produces one output. Pick a gate below, then click the input circles to toggle them between 0 and 1. Wires carrying a 1 light up green; a 0 stays dim. The truth table on the right lists every possible input combination β€” the current one is highlighted.

2. Build up β€” from a half-adder to a binary adder

Adding two bits needs two outputs: the Sum and a Carry into the next column β€” exactly like carrying the 1 in grade-school addition. A half-adder is just an XOR (sum) plus an AND (carry). A full-adder also takes a carry coming in, so adders can be chained. Toggle bits A and B (and carry-in) and watch the gates resolve.

Now chain four full-adders into a 4-bit ripple-carry adder. Each column's carry-out feeds the next column's carry-in, so the carry ripples left β€” just how you add by hand. Toggle the bits of A and B and watch the carry propagate and the total appear.

0 + 0 = 0

One gate rules them all: NAND is universal β€” AND, OR, NOT, XOR and therefore every circuit (including this adder) can be built from NAND gates alone. Pack a few billion of them onto a chip, add memory and a clock, and you have a CPU.

3. From a switch to a computer β€” the abstraction stack

How does flipping switches become Minecraft, a spreadsheet, this web page? By stacking layers, each one hiding the messy details of the one below:

Transistors β€” the physical switch

A transistor is a microscopic electrical switch: a small voltage on one wire decides whether current can flow through another. A couple of transistors wired together are a logic gate. Modern chips hold tens of billions, each a few atoms wide.

Gates β€” binary logic

Transistors form gates (AND, OR, NOT, NAND…). Now we stop thinking about voltage and just think in 0s and 1s: true/false, on/off. Because NAND is universal, this single building block can express any logical function at all.

Arithmetic & memory β€” circuits

Wire gates into adders (you just built one), comparators, multiplexers, and latches that remember a bit. Logic becomes arithmetic; arithmetic plus stored bits becomes the ability to compute and to hold state.

The CPU β€” and everything above

Bundle the arithmetic unit, registers (memory), and a clock that steps the whole thing forward, and you get a processor that runs instructions. Stack software on top β€” machine code, languages, apps β€” and binary logic becomes everything a computer does.