How a Computer Works

An interactive tour, bottom to top

A computer is a rock we tricked into thinking.

Underneath every app, every video, every message, there is nothing but switches turning on and off — billions of them, a few billion times a second. This page walks up the whole ladder: one switch, then logic, then arithmetic, then memory, then a real CPU you can step through one clock tick at a time.

Everything below is live. Click things.

This shape — a processor, a memory holding both data and the program, and a bus between them — is the stored-program or von Neumann architecture, sketched in 1945. Your phone still works this way.

01 The atom

One switch, one bit

A transistor is a switch with no moving parts: put a voltage on its control wire and current flows; take it away and it stops. That is the entire vocabulary of the machine — flowing and not flowing, which we write as 1 and 0. One switch holds one bit.

A single switch

One bit can say yes or no. Eight bits sitting side by side can say a great deal more: each position is worth twice the one to its right, so eight switches cover every whole number from 0 to 255. That group of eight is a byte.

Eight switches make a byte

Nothing in the switches says what they mean. The same eight bits are the number 82, the letter R, a shade of dark grey, or a CPU instruction — the meaning lives entirely in what reads them. That single idea is why one machine can do every job.

02 The vocabulary

Switches that answer questions

Wire a handful of transistors together and you get a logic gate: a lump of circuitry whose output depends on its inputs by a fixed rule. There are only a few rules worth naming, and every one of them fits in a sentence.

One gate is enough

NAND is universal: wire NANDs together and you can build NOT, AND, OR, XOR — and therefore everything else on this page. Real chips lean on this, because a NAND is cheap in silicon. Flip the switches below to watch three NAND gates impersonate the other three.

03 The first useful trick

Gates that do arithmetic

Add two bits and the answer needs two bits of its own: 1 + 1 is 10, a zero with a carry. XOR gives the digit, AND gives the carry. Five gates handle a carry coming in as well, and that five-gate lump is a full adder — the piece every processor is built out of.

Full adder — click any input

Chain eight of them, carry-out to carry-in, and you can add any two bytes. The carry ripples from right to left exactly the way it does when you add on paper — and that ripple is real, physical delay, which is why the whole machine has to wait for a clock tick before trusting the answer.

8-bit ripple-carry adder

Subtraction for free

There is no subtractor in most CPUs. Flip every bit of the second number, add one, and add that instead — two's complement. The adder never knows the difference, which is why the same circuit serves both instructions in the processor further down this page.

04 Standing still

Circuits that remember

Gates forget instantly: change an input and the output follows. To remember, a circuit has to feed its own output back into its input, so it holds itself in place after the signal that set it is gone. Two cross-coupled NOR gates do exactly that — the SR latch, one stored bit.

SR latch — press Set, then let go

Line up eight latches behind a single "load now" wire and you have a register: one byte the machine can hold onto. Line up millions and you have memory — but then you need a way to talk to one row without disturbing the rest. That job belongs to the address decoder: n wires in, one of 2n rows out.

3-to-8 address decoder — set an address

05 The whole machine

A CPU you can watch think

Below is a complete 8-bit computer: sixteen bytes of memory, a handful of registers, one adder, and a shared bus that only one component may speak on at a time. It does nothing but repeat three steps forever — fetch the next instruction, decode what it means, execute it — and that loop is all any processor has ever done.

Every clock tick moves one value along the bus. Step through it and watch the control lamps at the bottom: those are the wires the control unit pulls to make each move happen.

Memory — 16 bytes

next instruction being addressed click a value to edit it

What "decode" really is

There is no interpreter inside. The instruction's top four bits are just wires going into a lookup table, and that table decides which control lines to pull on each tick. LDA is not a word the machine understands — it is the pattern 0000 selecting a column of switches.

06 The clock

Why waiting is the whole problem

The simulator above runs at a few ticks a second. A real core runs about three billion, and does several instructions in each one. At that speed light itself only travels 10 cm per tick — so distance becomes the enemy, and the entire memory system is arranged as a series of increasingly desperate attempts to avoid waiting.

If one clock tick were one second

hover or tap a bar

Read that bottom bar again. To a processor, reaching across the Atlantic is not slow — it is a decade. Caches, branch prediction, out-of-order execution, the whole baroque machinery of a modern core, exist to keep the adder busy while the answer is still in the post.

Where the speed actually comes from

Clock rates stopped climbing around 2005 — faster switching meant more heat than a chip could shed. Everything since has come from doing more per tick: several instructions in flight at once, many cores, wider vector units, and specialised silicon for the jobs that repeat. The tick has barely moved in twenty years.

07 The whole tower

From a switch to a running program

Every layer below is built only out of the one beneath it, and hides that one completely. Nobody holds the whole tower in their head at once — that is the point of it. Click any floor.

So the answer to "how does a computer work" is that it doesn't, really — not in one piece. It is a stack of small honest tricks, each one pretending to be something simpler than it is, all the way down to a piece of sand that can tell whether a wire is hot.

Part two How a quantum computer works What changes when the switch at the bottom of the tower stops being a switch: qubits, interference, entanglement, and a circuit simulator you can build in.