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.

Beginner 5 min readLesson 1 of 8 Interview Q&A

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.

Applicationsbrowser, games, your codeProgramming languagesPython, Java, JavaScriptOperating systemprocesses, files, memory, devicesInstruction set (ISA)x86-64, ARM, RISC-VMicroarchitecturepipelines, caches, ALUsDigital logicgates, flip-flopsTransistors & physicselectrical switches

The four main parts

busCPUcontrol unit · ALU · registersMain memory (RAM)instructions + dataStorageSSD / HDDI/O deviceskeyboard, screen, network
PartJobAnalogy
CPUExecutes instructions, one tiny step at a time (billions per second)The chef
RAMHolds the program and data being used right now; fast, lost on power-offThe kitchen counter
StorageKeeps files permanently; slower, much largerThe pantry
I/OMoves data in and out: keyboard, display, network, sensorsThe 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:

  1. Fetch — read the next instruction from memory at the address in the program counter (PC).
  2. Decode — work out what it means: "add register 1 to register 2", "load from address X".
  3. Execute — the ALU does the arithmetic, or the memory unit loads or stores data.
  4. Write back — store the result in a register or memory; move the PC to the next instruction (or jump).
CPUMemoryfetch instruction at PCADD r1, r2decode + execute in the ALUstore result (if needed)

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.

WhereTypical latencyIf 1 CPU cycle were 1 second…
Register~0.3 ns1 s
L1 cache~1 ns3 s
L2 cache~4 ns13 s
RAM~100 ns5 minutes
SSD~100 µs4 days
Hard disk~10 ms1 year
Network round trip across the world~150 ms15 years

What happens when you open an app

  1. You double-click; the OS reads the program file from storage.
  2. The OS creates a process, gives it memory, and copies the code into RAM.
  3. The CPU's program counter jumps to the program's first instruction.
  4. The program asks the OS (via system calls) to draw windows, read files and talk to the network.
  5. 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.

Key takeaways
  • 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.
Interview questions
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.