Ages

Now you know how a computer works!

What next?

Try it yourself ↓

How do computers work?

▶ 5:14 video · Watch on YouTube

  1. 0:00 From a room to your pocket
  2. 0:41 Ones and zeros
  3. 1:30 Switches that flip switches
  4. 2:17 The parts of a computer
  5. 3:05 Fetch, decode, execute
  6. 4:08 Billions of switches

Your turn

Flip the switches yourself

Flip the switches!

Each lab is one step from the video. Write a number in binary, light up logic gates, send a key press along the bus, run a tiny program and zoom down to one switch.

Each lab isolates one idea. The CPU is a toy with four made-up instructions; real instruction sets are far larger, but the fetch, decode, execute loop is the same.

Tap the switches and buttons and watch what lights up.

1

Write numbers with switches

Binary place values and ASCII

On and off

Tap the switches (or slide). Which switches make 5? Which letter is 80?

Set any byte. Why does 8 bits give exactly 256 values? Which pattern is ASCII “P”?

Tap the switches. Can you turn them all on?

2

Switches that flip switches

Logic gates and a half adder

Switch friends

Switch A and B on and off. When does the AND lamp light? What does 1 + 1 give?

Walk through all four input pairs and check the truth table, then read sum and carry for 1 + 1.

Switch A and B. When do the lamps light up?

3

The parts of a computer

CPU, memory, storage and the bus

A team of parts

Press a key a few times, then switch the power off. What happens to memory, and to storage?

Type into RAM, then cut the power. Which part is volatile?

Press the key. Then switch it off. What is gone?

4

Run a tiny program

The fetch, decode, execute cycle

Change the three steps, then press Run. Can you make the screen show 16?

Change the instructions and step through the cycle. Watch the opcode bits during decode.

A toy processor with four made-up instructions.

5

Zoom down to one switch

From chip to transistor

Tiny, tiny switches

Drag the zoom from the laptop down to a single switch, then flip it.

Zoom through each level of the chip. Roughly how many transistors make one gate?

Slide to look closer and closer. Then flip the tiny switch!

How do computers work?

Long ago, one of the first computers was as big as a whole room. Now a computer can fit on your lap or in your hand. Inside, both are made of the same thing: switches!

On and off

A switch can be on or off, like a light switch. Computers call on one and off zero. With lots of switches in a row, they can write any number. Letters, colours and sounds are numbers too.

Switches that flip switches

The switches inside a chip are super tiny. One switch can turn on another, like a tap letting water through. Joined together, they can make choices and even add numbers.

A team of parts

The keyboard is how you tell the computer things. The processor is the busy worker. Memory is like a notepad that forgets everything when you switch it off. Storage keeps your pictures safe. The screen shows you the answer.

Tiny, tiny switches

A chip as small as your fingernail holds a huge number of switches. Every game and video is just switches flipping on and off, super fast!

Did you know? Long ago, people found a real moth stuck inside a computer. They taped it into their notebook as a joke about a "bug"!

How does electricity work? · How does AI work? · ← More explainers

How do computers work? The short answer

A computer is a machine made of huge numbers of tiny electronic switches. Each switch is either on or off, and computers write those two states as 1 and 0.146 Group switches together and you can write any number. Wire them so that switches control other switches, and they can add, compare and remember numbers.8 A program is a list of instructions, also stored as numbers, and the processor follows it one step at a time, extremely fast: its clock can tick billions of times a second.610

Everything else, from letters to photos to music, is just numbers that people have agreed how to read.136

How does a computer work, step by step?

  1. Input. A keyboard, mouse, touchscreen or microphone turns what you do into numbers.6
  2. Memory. The program and the data it's using right now sit in fast working memory (RAM).9
  3. Processing. The processor (CPU) repeats a loop: fetch the next instruction from memory, decode what its ones and zeros mean, execute it, and store the result.6
  4. Storage. Files you want to keep are saved on a drive, which remembers them even with the power off.9
  5. Output. A screen or speaker turns the resulting numbers back into light and sound.6

All these parts pass bits to each other along shared sets of wires called a bus.6

What is binary, and why do computers use it?

Binary is a way of writing numbers with only two digits, 0 and 1. It suits machines because it's easy to build parts with exactly two states, like on and off.14 Each binary digit is called a bit, and 8 bits make a byte.6

In our everyday numbers each place is worth ten times the one to its right. In binary each place is worth double: 1, 2, 4, 8, 16, 32, 64, 128. To read a binary number, add up the places that hold a 1.147

Place value1286432168421Total
5000001014 + 1 = 5
Letter P0101000064 + 16 = 80
25511111111all on = 255

With n bits you can make 2n different patterns, so one byte has 256 patterns (0 to 255).7

How do computers store letters, pictures and sound?

As numbers, using agreed codes. In the ASCII code, for example, the binary pattern 1010000 (which is 80) means a capital P. ASCII has 128 characters, and the newer Unicode standard builds on it to cover all the world's main writing systems.13

A screen is a grid of tiny dots called pixels. Each pixel mixes red, green and blue light, so a colour can be stored as three numbers: how much of each.1617 A digital song is also just a long list of numbers that the computer reads to make sound.6

What is a transistor, and what does it do?

A transistor is the switch inside a computer chip. It has three connections. In a chip, a small voltage on one of them, called the gate, decides whether electric current can flow between the other two. Britannica compares it to a tap controlling water in a hose.11 Because a transistor is switched by electricity, and it also switches electricity, one transistor can control another. That's what makes computing possible.

The first transistor was made at Bell Labs in December 1947 by John Bardeen and Walter Brattain: two gold contacts pressed onto a small slab of germanium.3 Transistors soon replaced vacuum tubes, which were bulky, fragile, power-hungry and burned out. Transistors were small, ran cool and were reliable.11

What is a logic gate?

Wire a few transistors together and you get a logic gate, a tiny circuit that makes a simple decision about its inputs. On a chip, a gate typically uses about four transistors.8

GateOutput is 1 when…0,00,11,01,1
ANDboth inputs are 10001
OReither input is 10111
XORexactly one input is 10110
NOTits one input is 0 (it flips it)0 → 1, 1 → 0

Put an XOR gate and an AND gate side by side and you've built a half adder: it adds two bits. 0 + 1 gives 1, and 1 + 1 gives 10, which is binary for two (a sum of 0 and a carry of 1).8 Chain adders together and a chip can add numbers with more bits. A three-bit adder takes about 15 gates, or roughly 60 transistors.8

What does a CPU do?

The CPU (central processing unit) or processor is where instructions get carried out. Its control unit fetches instructions from memory in the right order and works out what they mean. Its arithmetic logic unit (ALU) does the adding, subtracting and comparing.96 Each instruction is a pattern of bits, such as "add this number to that one", and the CPU repeats the same loop over and over:

  1. Fetch: bring the next instruction from memory into a small, very fast store inside the CPU (a register).
  2. Decode: work out what those ones and zeros mean.
  3. Execute: the processor carries it out (sums and comparisons happen in the ALU), and the result goes into a register or back to memory. Then fetch the next one.6

A clock keeps the beat. A 3-gigahertz processor's clock ticks three billion times a second. Clock speed alone doesn't decide how fast a computer is, though, because some designs get more done per tick.10

What is RAM, and how is it different from storage?

RAM (random-access memory) is the computer's working memory. When you open an app, the operating system copies it from storage into memory so the CPU can reach it quickly.6 RAM is fast, but it's volatile: in common RAM chips each bit is a tiny charge that fades and must be refreshed, and everything is lost when the power goes off.158 Storage, the drive, is slower but keeps your photos, songs and apps with the power off.9

Hardware and software

Hardware is the physical machine: chips, boards, drives. Software is the programs and the data they use.6 People write programs in languages that are easy for humans to read, and special programs translate them into the binary instructions a processor can run.6

When was the first computer invented?

It depends on what counts as a computer, but ENIAC is a famous milestone. Built between 1943 and 1945 at the University of Pennsylvania and announced in February 1946, it is often called the first general-purpose electronic computer.12 It filled a room 30 by 50 feet, weighed 30 tons and used 18,000 vacuum tubes and 150 kilowatts of power. A ballistics calculation that took 12 hours with a hand calculator took ENIAC 30 seconds.2 Six women, the "ENIAC Six", programmed it by plugging in cables and setting switches.2

Here's the surprising part: the basic design hasn't really changed since the first stored-program computers, built just after ENIAC. What changed was speed, size, power use and storage.8

What is Moore's law?

In 1965, Gordon Moore predicted that the number of parts on a chip would keep doubling. In 1975 he revised it to about every two years, and the industry kept pace for decades. It became known as Moore's law.4 Transistors shrank from millimetres in the late 1940s to tens of nanometres by the 2010s, more than 100,000 times smaller.12 Today a chip about the size of a fingernail can hold billions of them.118

Where does the word "bug" come from?

In 1947 engineers working on the Harvard Mark II computer found a moth stuck in one of its parts. They taped it into their logbook with the note "first actual case of bug being found." Grace Hopper, a mathematician and later a Navy rear admiral, was on the team and helped make "bug" and "debug" popular.5 But the moth wasn't where the word came from. It was a joke: engineers had been calling faults "bugs" since at least the 1870s, when Thomas Edison used the word.5

Common misconceptions

"Computers understand words and pictures." Inside, there are only numbers in binary. Meaning comes from agreed codes like ASCII.13
"More RAM means more room for files." RAM is working memory that forgets when the power goes off. Your files live in storage.9
"The moth invented the word bug." "Bug" was already engineering slang, and the moth was a joke about it.5
"Gigahertz tells you how fast a computer is." It's the clock's beat. The chip's design matters just as much.10
"Computers are clever." They follow very simple instructions, just extremely fast.6

Keep exploring

See how machines learn in How does AI work?, follow your bits across the world in How does the internet work? or through the air in How does wifi work?, find out what powers your phone in How do batteries work?, and see what flows through every switch in How does electricity work?

FAQ

How does a computer work, in short?

A computer takes input (like a key press), turns it into numbers made of ones and zeros, and its processor follows a program's instructions step by step to work on those numbers. It keeps what it's using in memory, saves files in storage, and turns the results back into pictures and sound as output.

How does a computer work step by step?

The processor repeats a simple loop: fetch the next instruction from memory, decode it to work out what it means, then execute it (for example, add two numbers) and store the result. Then it fetches the next instruction. A clock keeps the beat, often billions of times a second.

What does a CPU do?

The CPU (central processing unit), or processor, carries out a program's instructions. Its control unit fetches and decodes each instruction, and its arithmetic logic unit (ALU) does the maths and comparisons.

What is the difference between RAM and storage?

RAM is the computer's working memory: fast, and it holds the programs and data in use right now, but it loses everything when the power goes off. Storage (a drive) is slower but keeps your files when the computer is switched off.

Why do computers use binary?

Because their basic parts are switches that are either on or off. Two states are easy to build and hard to confuse, so computers write on as 1 and off as 0. Any number, letter, colour or sound can be written as a pattern of these bits.

What is a transistor?

A transistor is a tiny electronic switch. A small voltage on its gate decides whether current can flow through it, so one transistor can control another. The first one was made at Bell Labs in 1947, and today a single chip can hold billions.

Did Grace Hopper's moth give us the word 'bug'?

No. In 1947 engineers working on the Harvard Mark II, a team that included Grace Hopper, found a moth stuck in the machine and taped it into their logbook as the 'first actual case of bug being found.' It was a joke, because engineers had been calling faults 'bugs' since at least the 1870s.

Did this help it click?

Sources

  1. Computer History Museum, Revolution: ENIAC
  2. Penn Engineering, ENIAC
  3. Computer History Museum, 1947: Invention of the Point-Contact Transistor
  4. Computer History Museum, 1965: "Moore's Law" Predicts the Future of Integrated Circuits
  5. Smithsonian National Museum of American History, Log Book With Computer Bug
  6. OpenStax, Introduction to Computer Science, 5.1 Computer Systems Organization
  7. OpenStax, Introduction to Computer Science, 5.3 Machine-Level Information Representation
  8. University of Cambridge, D. J. Greaves, How Computers Work
  9. University of Rhode Island, How the Computer Works: The CPU and Memory
  10. University of Vermont CS 2210, Basic performance metrics
  11. Encyclopaedia Britannica, Transistor
  12. Encyclopaedia Britannica, Moore's law
  13. Encyclopaedia Britannica, ASCII
  14. Encyclopaedia Britannica, Binary number system
  15. Encyclopaedia Britannica, Computer: Main memory
  16. Encyclopaedia Britannica, RGB color model
  17. Khan Academy / Pixar in a Box, RGB color model