;colony/science  / Computers, Visually  / How does a CPU run a program?
Computers, Visually

How does a CPU run a program?

A processor has no idea what your program is for. It just reads one instruction, does it, reads the next — a dumb little loop, run billions of times a second.

Plate 75 — Fetch, decode, execute program counter · ALU · ~3 GHz
Step the CPU through a four-line program and watch it add 7 + 5.
Predict firstAs you step the program, which register decides which instruction runs next?
a four-line program · fetch → decode → execute, then repeatPROGRAM (in memory) 0 LOAD 7 ◀ PC 1 ADD 5 2 STORE →M 3 HALT CPUProgram counter0Register A0Now running readyRESULT CELL (memory)7 + 5 =·cycle 0
PLATE 75 · FETCH, DECODE, EXECUTE
Phase idle
Press Step. The CPU will read the line the program counter points at.
Register A
0
Answer in memory
The CPU does the same little dance over and over: read the next line, work out what it says, then do it. This tiny program puts 7 in a box, adds 5, and saves the answer. Step through it once. A real chip runs this loop billions of times a second.
Try with the plate
  • Step through the four-line program until it loads 7 and adds 5.
  • Watch the program counter advance through one full fetch-decode-execute cycle.

A CPU runs a program by repeating one simple loop: fetch the next instruction from memory, decode what it means, then execute it. A register called the program counter holds the address of the next instruction and ticks forward each time. Every app and video is ultimately this dumb three-beat loop, run billions of times a second.

The short answer

A computer's brain doesn't think the way you do. It follows a tiny list of orders, one line at a time: read the next order, work out what it means, then do it. That's it, over and over. A line might say put 7 in a box, the next add 5, the next save the answer. Step through the simulator and watch a chip add two numbers the only way it knows how.

The common mix-up

Most people think a CPU understands what your program is for. In fact it understands nothing: it just fetches one instruction, decodes it, executes it and repeats, billions of times a second, and the intelligence is an illusion built from those mindless steps.

What's actually happening

It's tempting to imagine a processor as a clever thing that understands your spreadsheet or your game. It understands nothing. A CPU is closer to an extremely fast clerk who can only follow one-line orders from a list, has no memory of why, and never gets bored. The intelligence you see on screen is an illusion built from billions of these mindless little steps stacked up.

The loop it runs is always the same three beats. First it fetches: a register called the program counter holds the address of the next instruction, and the CPU copies that instruction out of memory. Then it decodes: it picks apart the instruction to see which operation it is and what to operate on. Then it executes: the arithmetic unit actually does the thing, adds two numbers, moves a value, compares them, or jumps somewhere else in the list. Then the program counter ticks forward and the whole cycle begins again. The simulator runs exactly this on a four-line program that loads 7, adds 5, stores the result, and halts, so you can watch the counter march and the answer appear.

What makes it feel magical is the speed and the jump. A processor running at three gigahertz grinds through this fetch-decode-execute loop about three billion times every second, so even though each step is trivial, an enormous pile of them happens between two of your heartbeats. And one instruction type, the jump, lets the program counter leap backward or forward instead of just stepping on, which is how the same handful of lines can loop, branch, and make decisions. Every app, every video, every AI model is ultimately this same dumb clerk reading its list faster than you can blink.

Remember this

Every app and video is one dumb fetch-decode-execute loop run billions of times a second, with the jump giving it decisions.

Try it at home Be the processor
  1. 1Write four orders on cards: "put 7 in your hand", "add 5", "say the number out loud", "stop". Stack them in order.
  2. 2Point at the top card (that finger is the program counter). Read it, work out what it means, then do it, then move your finger down one card.
  3. 3You just ran a program by hand. A real CPU does this with the same three beats, only a few billion times faster and without ever asking why.

Common questions

How can such a simple loop do complicated things?

A chip running at three gigahertz grinds through the fetch-decode-execute loop about three billion times every second. Each step is trivial, but an enormous pile of them happens between two of your heartbeats, and that sheer count does the work.

How does a fixed list of instructions make decisions?

One instruction type, the conditional jump, lets the program counter leap backward or forward instead of just stepping on. That single trick is how the same handful of lines can loop, branch and make decisions.

What is pipelining?

Real CPUs overlap the steps like an assembly line, fetching the next instruction while decoding the current one and executing the last. Several instructions are in flight at once, which gets more done per second.

Built & checked by Nilesh Singh · how this is made · last updated June 2026