Watch on Instagram

Code Bytes · "How Computers Work" · Episode 3 · Hardware

The CPU

The CPU (central processing unit) carries out a program's instructions, one tiny job at a time, like add, compare or move. A clock paces it; each tick is a cycle, and 1 gigahertz means 1 billion cycles every second.

Posted · About a 1 minute watch, 3 minute read · Take the quiz

What the CPU is

CPU stands for central processing unit. It's the chip inside your computer, phone or games console that carries out your program's instructions. Everything you run, from a game to a web browser to a one-line Python program, ends up as instructions that the CPU works through.

A very fast, very simple worker

Each instruction the CPU understands is a tiny job. Typical ones are:

  • add two numbers, like 2 + 3
  • compare two numbers, like "is 5 bigger than 3?"
  • move a number, for example from memory into the CPU or back

On its own, none of these is clever. Big programs work because the CPU does huge numbers of these tiny jobs, one after another, very quickly.

Two tiny jobs: 2 + 3 * 4

Here is the line from the video:

``python print(2 + 3 * 4) ``

`` 14 ``

Working out 2 + 3 * 4 takes two tiny jobs: multiply first (3 × 4 = 12), then add (2 + 12 = 14). You can see the two steps by splitting them up yourself:

``python x = 3 * 4 print(x) total = 2 + x print(total) ``

`` 12 14 ``

The clock, cycles and gigahertz

The CPU keeps time with a clock: a signal that ticks on and off, billions of times a second. Each tick is called a cycle, and the CPU's work is paced by those ticks.

Clock speed says how many cycles happen each second. It is measured in hertz (one cycle per second). "Giga" means one billion, so 1 gigahertz (1 GHz) = 1 billion cycles every second, which is 1,000,000,000.

So a CPU isn't clever. It's just incredibly fast.

Try it yourself

Open any free online Python editor (search "online Python") and run:

``python print((2 + 3) * 4) ``

You should see:

`` 20 ``

The brackets change the order of the tiny jobs: now the CPU's work is add first (2 + 3 = 5), then multiply (5 × 4 = 20). Compare it with print(2 + 3 * 4), which prints 14.

Good to know

  • Every snippet on this page was run with Python 3 (3.13) and printed exactly what is shown.
  • "Multiply first, then add" describes the arithmetic, not exactly what Python does. Python actually works out 2 + 3 * 4 = 14 once, before the program even runs (called constant folding; Python's dis module shows it as the single constant 14). Running a line of Python also takes many more machine instructions inside the Python interpreter. How Python code becomes CPU instructions comes later in this course (machine code vs high-level code).
  • Clock speed alone doesn't decide how fast a CPU is. Modern CPUs have several cores (workers side by side) and can finish more than one instruction per cycle, while some instructions take several cycles.
  • Multiply before add is the same order of operations used in Code Bytes EP25 (Syntax vs logic errors).

Answer to the comment question

A CPU runs at 3 gigahertz. How many cycles is that each second?

3 billion (3,000,000,000) cycles each second.

1 gigahertz is 1 billion cycles every second, so 3 gigahertz is 3 times that. You can check it in Python 3:

``python print(3 * 1000000000) ``

`` 3000000000 ``

Test your knowledge

Quick quiz: The CPU

4 multiple-choice questions. Pick one answer for each, then check how you did.

1What does CPU stand for?
2What does print(2 + 3 * 4) print?
3What is one tick of the CPU's clock called?
4What does 1 gigahertz mean?

Sources

Video transcript

What does the CPU inside your computer actually do?

CPU stands for central processing unit. It's the part that carries out your program's instructions.

Think of it as a very fast, very simple worker. Each instruction is a tiny job: add two numbers, compare them, or move one.

Working out 2 + 3 × 4 takes two tiny jobs: multiply first, then add. 14.

The CPU keeps time with a clock: a signal that ticks billions of times a second. Each tick is called a cycle.

Clock speed is measured in gigahertz. 1 gigahertz means 1 billion cycles every second.

So a CPU isn't clever. It's just incredibly fast.

A CPU runs at 3 gigahertz. How many cycles is that each second? Comment your answer below!

That's your byte.

More from "How Computers Work"

All "How Computers Work" lessons