Find a course

Module 2: How Computers WorkLesson 3 of 1213 min

Inside a Computer: CPU, Memory and Storage

Meet the main parts of every computer, trace the fetch-decode-execute cycle, and see why fast memory is small and big storage is slow.

Step 1 of 16Learn

The same four parts in every computer

A gaming PC, a smartphone, a smart thermostat and the computer in a car's braking system look nothing alike. Yet they all share the same basic design, described by John von Neumann and others in the 1940s and still used today.

Every computer has four essential parts:

  1. Processor (CPU): carries out instructions: arithmetic, comparisons and decisions about what to do next.
  2. Memory (RAM): fast working space that holds the programs and data in use right now.
  3. Storage: long-term space (an SSD or hard drive) that keeps files and programs when the power is off.
  4. Input and output (I/O): keyboards, touchscreens, microphones, cameras, sensors, displays, speakers and network connections.

The key idea of the stored-program design is that instructions are just data. A program is a sequence of numbers sitting in memory, alongside the numbers it works on. That's why the same machine can be a word processor one moment and a video game the next: load different instructions, and it becomes a different tool.

When you open an app, its instructions are copied from storage into RAM, and the CPU starts executing them. When you save your work, data is copied from RAM back to storage, so it survives when the power goes off.

Step 2 of 16Practice · Sort into groups

Sort each device into its main role.

Tap an item, then tap its group (or drag it there).

Step 3 of 16Diagram

The von Neumann design

The von Neumann designParts diagram: A computer, CPU, Memory (RAM), Storage, Input, Output.A computerCPUMemory (RAM)StorageInputOutput

Tap a shape with to see more.

A computer
CPU

Fetches and executes instructions.

Memory (RAM)

Holds both the program and its data while it runs: the key von Neumann idea.

Storage

Keeps data when the power is off.

Input

Brings data in from the world.

Output

Sends results out to people or other machines.

Step 4 of 16Learn

The fetch-decode-execute cycle

A CPU does one deceptively simple thing, over and over, billions of times per second. It runs the fetch-decode-execute cycle:

  1. Fetch: read the next instruction from memory. A special register called the program counter holds that instruction's address.
  2. Decode: work out what the instruction means: "add these two numbers," "copy this value to memory," "jump to a different instruction if this value is zero."
  3. Execute: carry it out. Arithmetic and comparisons happen in the arithmetic logic unit (ALU). Results go into tiny, ultra-fast storage slots inside the CPU called registers.

Then the program counter moves to the next instruction (or jumps elsewhere, if the instruction said so) and the cycle repeats.

Each instruction is very basic. There's no "play video" instruction, only things like add, compare, load and store. Complex behavior comes from executing enormous numbers of simple steps very quickly.

The pace is set by a clock. A 3 GHz processor ticks 3 billion times per second. Modern CPUs also have several cores, each running its own cycle, and they use tricks like working on several instructions at once, so clock speed alone doesn't determine performance.

Step 5 of 16Practice · Put in order

Put the stages of the CPU's instruction cycle in order, starting from the program counter.

Drag the items, or use the arrow buttons, to put them in order.

  1. The program counter holds the address of the next instruction
  2. Update the program counter and repeat
  3. Fetch the instruction from memory
  4. Decode what the instruction means
  5. Execute it, using the ALU if arithmetic is needed

Step 6 of 16Diagram

The instruction cycle

The instruction cycleCycle diagram: Fetch → Decode → Execute → Advance.Billions oftimes persecondFetchDecodeExecuteAdvance

Tap a shape with to see more.

Fetch

Read the instruction at the address in the program counter.

Decode

The control unit works out what the instruction means.

Execute

The ALU calculates, or data moves between registers and memory.

Advance

The program counter moves to the next instruction (or jumps).

Step 7 of 16Practice · Work it out

A CPU core runs at 2 GHz and, on average, completes one instruction per clock tick. How many instructions does it complete in one millisecond (0.001 s)?

Step 8 of 16Learn

The memory hierarchy

Why not make all memory as fast as a CPU register? Because fast memory is expensive, power-hungry and physically small. Computers solve this with a memory hierarchy: a few levels, each bigger but slower than the one above.

LevelTypical sizeRough access time
RegistersHundreds of bytesUnder 1 nanosecond
CPU cacheA few MB1–10 nanoseconds
RAMSeveral to dozens of GBAbout 100 nanoseconds
SSDHundreds of GB to several TBTens to hundreds of microseconds
Hard driveSeveral TBSeveral milliseconds

The differences are enormous. If a register access took one second, reading from RAM would take a few minutes and reading from a hard drive would take weeks.

Caches make this work. Programs tend to reuse the same data and to access data stored close together, so the CPU keeps recently used data in its small, fast cache. Most of the time, the data it needs is already there.

Two more distinctions to remember. RAM is volatile: it loses its contents without power. Storage is non-volatile. And "memory" and "storage" are different: running out of RAM slows everything down as the system swaps data to storage, while running out of storage stops you from saving files.

Step 9 of 16Practice · Diagram

Rough access time down the memory hierarchy

Each layer down is bigger and cheaper per byte, but slower. Times are rough orders of magnitude.

Which level is roughly a thousand times slower than RAM? Tap it.

Tap the shape that answers the question, then press Check.

Rough access time down the memory hierarchyLayer diagram: Registers, CPU cache, RAM, SSD, Hard disk.Registers0.3 nsCPU cache5 nsRAM100 nsSSD100,000 nsHard disk10,000,000 ns
Registers

0.3 ns

CPU cache

5 ns

RAM

100 ns

SSD

About 100 microseconds: roughly a thousand times slower than RAM.

Hard disk

About 10 milliseconds, because a physical arm must move.

Step 10 of 16Practice · Choose one

Your laptop becomes very slow when you have 40 browser tabs and a video editor open, though it has plenty of free disk space. What is the most likely cause?

Step 11 of 16Note

Step 12 of 16Note

Step 13 of 16Diagram

Moore's law: transistors per chip

Moore's law: transistors per chipScale: 1971 Intel 4004, 1978 Intel 8086, 1989 Intel 486, 2000 Pentium 4, 2011 Core i7 (quad-core), 2020 Apple M1.10³10⁵10⁷10⁹10¹¹2,3001971 Intel 400429,0001978 Intel 80861,200,0001989 Intel 48642,000,0002000 Pentium 41,160,000,0002011 Core i7(quad-core)16,000,000,0002020 Apple M1
Approximate published transistor counts. Each tick on the log scale is 10 times more.
1971 Intel 4004

2,300

1978 Intel 8086

29,000

1989 Intel 486

1,200,000

2000 Pentium 4

42,000,000

2011 Core i7 (quad-core)

1,160,000,000

2020 Apple M1

16,000,000,000

Step 14 of 16Practice · Match the pairs

Match each component with its job.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. Registers
  2. Cache
  3. RAM
  4. SSD

Step 15 of 16Practice · True or false

Data in RAM survives when you turn the computer off.

Step 16 of 16Practice · What would you do?

What would you do?

Leo's 5-year-old laptop takes two minutes to start and opening apps feels sluggish, but once running, apps are fine. It has 16 GB of RAM and a hard drive. Which upgrade would most likely help?