How Computers Work
From transistors to running apps — the CPU, memory, storage and I/O, and the fetch–decode–execute cycle that ties them together.
A computer is a machine that stores information as bits and transforms it by following instructions. Every app you use, from a web browser to a neural network, ends up as billions of very simple steps: move this number, add those two, jump if the result is zero.
This lesson gives you the big picture. Every later track (computer architecture, operating systems, compilers) zooms into one part of it.
The layers of abstraction
No one thinks about transistors while writing a web app. Computing works because each layer hides the one below.
The four main parts
| Part | Job | Analogy |
|---|---|---|
| CPU | Executes instructions, one tiny step at a time (billions per second) | The chef |
| RAM | Holds the program and data being used right now; fast, lost on power-off | The kitchen counter |
| Storage | Keeps files permanently; slower, much larger | The pantry |
| I/O | Moves data in and out: keyboard, display, network, sensors | The doors and windows |
This design — programs and data stored in the same memory, and a CPU that fetches instructions from it — is the von Neumann architecture, and nearly every computer since 1945 uses it.
Transistors: the atoms of computing
A transistor is an electrical switch controlled by electricity: voltage on one terminal lets current flow between the other two. "On" and "off" become 1 and 0. Combine a few transistors and you get logic gates (AND, OR, NOT). Combine gates and you get circuits that add numbers and remember values. A modern CPU has tens of billions of transistors.
The fetch–decode–execute cycle
The CPU runs one loop forever:
- Fetch — read the next instruction from memory at the address in the program counter (PC).
- Decode — work out what it means: "add register 1 to register 2", "load from address X".
- Execute — the ALU does the arithmetic, or the memory unit loads or stores data.
- Write back — store the result in a register or memory; move the PC to the next instruction (or jump).
A 3 GHz CPU ticks its clock 3 billion times a second. Modern CPUs overlap many instructions at once (pipelining), execute several per tick, and guess which way branches will go, but the model above is still what they promise to behave like.
Why memory speed matters
The CPU is far faster than main memory. Fetching from RAM takes about 100 ns: roughly 300 clock cycles of waiting. That's why CPUs contain small, very fast caches.
| Where | Typical latency | If 1 CPU cycle were 1 second… |
|---|---|---|
| Register | ~0.3 ns | 1 s |
| L1 cache | ~1 ns | 3 s |
| L2 cache | ~4 ns | 13 s |
| RAM | ~100 ns | 5 minutes |
| SSD | ~100 µs | 4 days |
| Hard disk | ~10 ms | 1 year |
| Network round trip across the world | ~150 ms | 15 years |
What happens when you open an app
- You double-click; the OS reads the program file from storage.
- The OS creates a process, gives it memory, and copies the code into RAM.
- The CPU's program counter jumps to the program's first instruction.
- The program asks the OS (via system calls) to draw windows, read files and talk to the network.
- The OS switches the CPU between this and hundreds of other processes so quickly it looks simultaneous.
Each step is a lesson later: How programs run, Processes, System calls.
- Computers store everything as bits and transform them with simple instructions.
- Layers of abstraction: transistors → gates → microarchitecture → ISA → OS → languages → apps.
- Von Neumann: the CPU fetches instructions and data from one shared memory.
- The CPU loops fetch → decode → execute → write back, billions of times a second.
- Memory is much slower than the CPU, so caches and locality dominate performance.
QWhat is the von Neumann bottleneck?medium
Instructions and data share one path between the CPU and memory, so the CPU often waits for memory instead of computing. Caches, prefetching, wider buses and separate instruction/data L1 caches (a partly "Harvard" design) all reduce it.
QWhat's the difference between RAM and storage?easy
RAM is fast and volatile, and holds what's in use right now. Storage (SSD/HDD) is slower and persistent, and holds files. Programs are loaded from storage into RAM to run.
QWhat does a clock speed of 3 GHz mean?easy
The CPU clock ticks 3 billion times per second. Each tick advances the pipeline. Instructions per second also depend on how many instructions complete per cycle (IPC) and how often the CPU stalls waiting for memory.