The CPU (Central Processing Unit)

Somewhere inside your phone, your games console and your laptop there is a small square chip, often no bigger than a postage stamp, that does almost all of the thinking. It is called the CPU — the Central Processing Unit — and people love to call it the "brain" of the computer.

That nickname is handy, but be careful with it. The CPU isn't clever the way a brain is. It has one job, and it does that job astonishingly fast: it carries out instructions, one after another, billions of times every second. Everything a computer ever does — showing this page, playing a video, working out where your character is in a game — is really just a huge pile of tiny instructions being carried out by the CPU.

An instruction-following machine

Think about following a recipe. Each line is a small, exact instruction: crack an egg, add the flour, stir for one minute. You don't do the whole cake in one go — you follow the steps in order, one at a time. A CPU works the same way, except its "recipes" are called programs, and its steps are called instructions.

A single instruction is tiny. A CPU instruction might be something like "add these two numbers", "copy this value over here", or "if this number is zero, jump to a different step". On their own they look almost too simple to be useful — but string billions of them together every second and you get everything from a spreadsheet to a 3-D world.

A typical CPU runs at a few gigahertz (GHz). "Giga" means a thousand million, and "hertz" means "times per second", so a 3\text{ GHz} CPU keeps time to a beat that ticks three thousand million times a second. If you carried out one instruction every second by hand, without ever sleeping or eating, it would take you roughly 95 years to do what such a CPU does in a single second. That is why computers can feel instant even when they're doing a mountain of work.

What's inside the CPU?

We usually draw the CPU as a single box, but if you could zoom inside you would find a few important parts working together. You don't need every detail yet (that comes later, at A-level) — just meet the three main players:

Notice the arrow between memory and the CPU. The CPU can't do anything with a program until that program has been loaded into memory — the CPU only ever reaches into memory, grabs the next instruction, and carries it out.

The fetch–decode–execute cycle

The CPU repeats the same simple loop over and over, for as long as it is switched on. It's called the fetch–decode–execute cycle, and it has just three steps:

  1. Fetch — the Control Unit collects the next instruction from memory.
  2. Decode — it works out what that instruction is asking for.
  3. Execute — the instruction is actually carried out (often the ALU does some maths, or a value is copied into a register).

Then it starts again with the very next instruction. Billions of laps of this little loop every second is all a CPU ever does.

When you press the power button, the CPU can't run your operating system yet — it isn't in memory. So the CPU starts by running a tiny built-in program (called the bootloader / firmware) that lives in a special chip. Its whole job is to load the operating system into memory, and once that's done the CPU can start fetching and executing it. This start-up sequence is why we say a computer "boots up".

More CPU, more speed

For decades, CPUs got faster mostly by ticking quicker — more gigahertz. But there's a limit: push the clock too high and the chip gets far too hot. So designers found another trick: put several CPUs on one chip. Each one is called a core.

A quad-core processor has four cores, so it can work on four streams of instructions at the same time — a bit like opening four checkout tills instead of one to serve a queue faster. That's why you'll see phones and laptops advertised as "octa-core" (eight cores) or with a speed like 3.2\text{ GHz}: those two numbers, how many cores and how fast each ticks, are the headline clues to how much work a CPU can get through.

Reaching out to main memory (RAM) takes the CPU a comparatively long time — like walking to another room for a book. So CPUs keep a small, super-fast store called a cache right on the chip, holding copies of the data they've used recently. If the next thing the CPU needs is already in the cache, it saves the long trip. Registers are the fastest and smallest store of all, then cache, then main memory — smaller and faster the closer you get to the ALU.

It's tempting to think the CPU understands what it's doing — that it "knows" it is adding your shopping bill or drawing your friend's face. It doesn't. A CPU has no understanding at all. It blindly follows machine instructions, one after another, unbelievably quickly, with no idea what any of it means. The cleverness you see comes from the programmer who arranged those instructions — not from the chip.

And remember the other half: a CPU can only run a program that has been loaded into memory. A game sitting on a disc or a download does nothing on its own — it has to be copied into memory first, and only then can the CPU fetch and execute it.