🧠
CodingπŸ”¬ Ages 11-13Intermediate 12 min read

How the CPU Works

Meet the CPU, the brain of the computer: learn the fetch-decode-execute cycle, what registers and the clock do, how billions of simple steps run a program, with examples and a quiz.

Key takeaways

  • The CPU is the brain of the computer that carries out instructions
  • It repeats a simple loop called fetch, decode, execute, billions of times per second
  • The clock sets the speed; clock speed is measured in gigahertz (GHz)
  • A CPU only does tiny, simple steps, but it does them incredibly fast

The brain of the computer

Every computer, phone, and games console has a chip inside called the CPU β€” the Central Processing Unit. People often call it the "brain" of the computer, and that's a good nickname, because the CPU is the part that actually does the thinking: it carries out the instructions in your programs, one after another.

But here's the surprising part. The CPU isn't clever in the way a human brain is. It can't understand the world or have ideas. It can only follow very tiny, simple instructions. Its superpower is speed β€” it does those tiny steps billions of times every second. Let's see how.

What counts as an instruction?

When you run a program, the code you wrote gets translated into a list of extremely simple commands the CPU understands, called machine code. Each instruction is something basic, like:

  • Add these two numbers.
  • Compare two numbers β€” are they equal?
  • Move this value from one place to another.
  • Jump to a different instruction in the list.

That's it. The CPU has no instruction for "play a video" or "send an email." Those big jobs are built from millions of tiny steps like the ones above. It's like how a long novel is made of nothing but individual letters.

The fetch-decode-execute cycle

The CPU runs a program by repeating one simple loop over and over. This loop is called the fetch-decode-execute cycle:

  1. Fetch β€” Get the next instruction from memory.
  2. Decode β€” Work out what that instruction is asking for.
  3. Execute β€” Actually do it (add the numbers, make the comparison, and so on).

Then it goes straight back to step 1 and fetches the next instruction. Over and over, with no breaks, for as long as the computer is on. Every app you've ever used is really just this loop running unimaginably fast.

Think of it like a chef reading a recipe card by card:

  • Fetch: pick up the next card.
  • Decode: read what it says ("chop the onion").
  • Execute: chop the onion.
  • Then reach for the next card.

The chef does this one card at a time. A CPU does the same β€” just billions of cards per second.

Registers: the CPU's tiny pockets

To do its work, the CPU needs a place to hold numbers it's using right now. These ultra-fast storage spots are called registers. There are only a handful of them, and each holds a single value, but they are the fastest memory in the whole machine.

Imagine doing maths in your head. You keep one or two numbers "in mind" while you work on them β€” that's exactly what registers are for. When the CPU adds 7 + 5, it loads 7 into one register, 5 into another, runs the add instruction, and the answer 12 lands in a register, ready for the next step.

Registers are tiny and few, so the CPU constantly shuffles data between registers and the computer's main memory (RAM), which is bigger but slower.

The clock keeps the beat

How does the CPU keep all these steps in order and in time? It uses a clock β€” but not the kind on a wall. A CPU clock is a tiny part that "ticks" incredibly fast, and every tick tells the CPU it's time to move forward. Like a drummer setting the beat for a band, the clock keeps every part marching in step.

The speed of this clock is the clock speed, measured in hertz (ticks per second):

  • 1 megahertz (MHz) = 1 million ticks per second.
  • 1 gigahertz (GHz) = 1 billion ticks per second.

A typical modern CPU runs at around 3 GHz. That means its clock ticks about 3 billion times every second. With each tick (or small group of ticks) the CPU pushes another instruction through its cycle. This is why a computer can do so much: each step is small, but three billion small steps per second add up to enormous power.

More cores, more lanes

Old CPUs had a single processing unit. Modern CPUs have several cores, and each core can run its own fetch-decode-execute cycle. A four-core CPU is like a motorway with four lanes β€” four streams of instructions can move at once, so the computer can play music while loading a web page while checking for messages.

This teamwork is one reason today's devices feel so smooth, even when many things happen at the same time.

Simple steps, amazing results

Here's the big idea to remember: a CPU is not magic. It only ever does tiny, simple things β€” fetch an instruction, decode it, execute it, repeat. There's no cleverness hidden in a single step. The wonder comes from doing billions of those simple steps every second, perfectly in time, never getting bored or making a mistake.

Even advanced AI that seems to "think" is, underneath, a CPU (often working with other chips) running this same loop on a colossal scale. When a program behaves strangely, remember the CPU did exactly what the instructions told it β€” which is why debugging means finding the instruction that was wrong, not blaming the chip.

Try it yourself

Become a human CPU:

  • πŸ“‡ Write 5 simple instruction cards, such as "Load 4," "Load 3," "Add them," "Compare to 7," "If equal, smile." Then act as the CPU: fetch one card, decode it, execute it, and move on. Notice how you only ever do one tiny step at a time.
  • ⏱️ Pick a steady beat (clap once per second). Try to "execute" one instruction per clap. Now imagine doing that 3 billion times a second β€” that's your CPU.
  • πŸ” On a real computer, look up your device's CPU. How many GHz is it? How many cores? See if a faster-sounding clock speed always means a newer chip (it often doesn't!).

Once you can picture the fetch-decode-execute loop, you understand the heartbeat of every computer on Earth.

Quick quiz

Test yourself and earn XP

What does CPU stand for?

What are the three steps the CPU repeats?

What does the clock do in a CPU?

A clock speed of 3 GHz means roughly how many ticks per second?

Why can a CPU do so much if each step is so simple?

FAQ

Not always. Clock speed (in GHz) is one factor, but the number of cores, how much work each tick does, and how well the CPU works with memory all matter too. A modern 3 GHz CPU can easily outperform an older 4 GHz one because it does more useful work per tick.

A core is a complete processing unit inside the CPU that can run its own fetch-decode-execute cycle. A CPU with four cores can work on four streams of instructions at once, a bit like having four brains sharing the work.