What is a computer?
Before you can tell a computer what to do, it helps to know what is inside the box. This lesson opens it up: five parts, one journey from your finger to the screen, and the surprising fact that everything inside is a number.
Why this matters
At the end of this course you will build your own language model and run it on a phone. That model is, in the most literal sense, a very large pile of numbers kept in a computer's memory, worked on by its processor, and saved to its storage as a file. When something goes wrong on that road, the error messages talk in exactly these words: "out of memory", "not enough disk space", "this processor is too slow".
So this first lesson gives you the map. In Stage 7 you will do "model size and memory math" (lesson s7-02) to decide whether your model fits on a phone; it is the same arithmetic you will do today with bytes and gigabytes, only with bigger numbers.
The big idea
Input, processing, output
A computer is a machine that does three things, always in this order:
- Input: information comes in (you press a key, click, speak, open a photo).
- Processing: the computer works on it, following instructions.
- Output: a result comes out (letters on the screen, a sound, a saved file).
Picture a chai stall. You say "two cutting chai" (input). The chaiwala boils, mixes and pours (processing). Two small glasses arrive in front of you (output). Every computer, from your phone to the machines that train giant AI models, follows the same three beats.
The five parts inside
Keep the chai stall in mind; every part of a computer has a place in it.
- Input devices such as the keyboard, trackpad, microphone and camera: the customer's order arriving.
- The processor (also called the CPU, short for central processing unit): the chaiwala. It is the only part that actually does the work: adding, comparing, following each instruction. Newer Macs have an Apple chip with a name like M1, M2, M3 or M4.
- Memory (also called RAM): the counter top next to the stove. Small, but everything on it is within arm's reach, so work is fast. At closing time the counter is wiped clean: when the power goes off, memory forgets everything.
- Storage (on a Mac, an SSD, a solid-state drive): the storeroom at the back. Much bigger, slower to fetch from, but whatever you put there is still there tomorrow morning.
- Output devices such as the screen and speakers: the glass of chai handed to you.
The most important pair to keep apart is memory and storage. A Mac might have "16 GB memory" and "512 GB storage". Memory is where work happens; storage is where things are kept. The processor cannot cook in the storeroom: anything it works on is first brought to the counter, into memory.
So what does "save" mean?
When you type a message, the letters live in memory. If the power cut hits before you save, they are gone, because memory is wiped. Saving copies your work from memory into storage, where it survives switching off. This is why every app has a Save button, and why in Stage 5 your training program will save the model to a file every so often: hours of training live in memory until they are saved.
Inside, everything is a number
Deep down, memory and storage are made of billions of tiny electronic switches. Each switch can only be off or on, which we write as 0 or 1. One switch is called a bit. Eight bits in a row make a byte, which can hold any whole number from 0 to 255.
That is enough to store anything, because people agreed on ways to turn everything into numbers. Every letter has a number: capital A is 65, small a is 97. Every dot of colour in a photo is three numbers (how much red, green and blue). A song is a long list of numbers saying how the speaker should move. The computer never sees "a letter" or "a photo"; it sees numbers, and programs decide what the numbers mean.
Sizes are counted in bytes, with bigger units the same way a kilometre is a thousand metres. On a Mac:
- 1 kilobyte (KB) = 1,000 bytes, about a page of plain text.
- 1 megabyte (MB) = 1,000 KB = 1,000,000 bytes, about one phone photo.
- 1 gigabyte (GB) = 1,000 MB = 1,000,000,000 bytes (one billion), about an hour of video.
You may see 1 KB written as 1,024 bytes in some places. Both conventions exist; macOS counts in thousands, so this course does too. The language model you train in Stage 5 will be a few megabytes; the open models in Stage 6 are a few gigabytes.
The operating system: the stall manager
Many programs want the processor, memory and screen at the same time: your browser, music, a chat app. An operating system is the program in charge of sharing them out. On your Mac it is macOS; on phones it is iOS or Android. It decides which app gets the processor next, hands out space in memory, and keeps the storeroom organised into files and folders (next lesson). The apps (Safari, Calculator, Notes) are the workers it lets use the counter and the stove.
In lesson s0-04 you will meet the terminal, which is a way of giving the operating system orders by typing instead of clicking.
Watch it happen
Press ▶ to play, or ⏭ to go one step at a time (with the player selected, the ← and → keys work too). We follow one tiny job: adding 2 and 3 in the Calculator app. Lit-up parts are the ones busy in that step.
Now zoom in to the switches. This shows how one key press, the capital letter A, ends up as eight on/off switches in memory.
Try it
These boxes run real programs written in Python, the language you will use for the whole course. You do not need to understand every word yet. Press Run (the first run takes a few seconds while Python loads), look at the result, then change a number and run it again. You cannot break anything, and Reset brings the original back.
Two things to know: * means multiply (a keyboard has no × key), and print(...) means "show this on the screen". The words after # are notes for humans; the computer skips them.
1. Input, processing, output in four lines
You see 45. The first two lines put the inputs into memory, the third line is the processing (the processor multiplies 3 by 15), and only the last line produces output. Change cups to 4 and run again: you get 60. The program did not change; only its input did, so the output changed.
2. Letters really are numbers
You see 65, 97, A, 0b1000001. ord asks "which number stands for this letter?" and chr goes the other way. Capital A and small a get different numbers, which is why computers treat them as different letters. bin shows a number as switches: 0b only means "switches follow", and 1000001 is 65 written in ones and zeros (the leading 0 of the full byte 01000001 is left off). Try ord("z") or ord(" "): even a space has a number (32).
3. How big is 8 GB of memory?
You see 8000000000 (eight billion bytes) and then 64000000000 (sixty-four billion bits, because every byte is 8 bits). Change memory_gb to the memory of your own Mac (you will look it up in the practice). This is exactly the sum you will do in Stage 7 to check whether a model fits on a phone.
Common mistakes
Everyone mixes these up at first. If the quiz sends you here, read the one it points to; each takes half a minute.
Thinking memory and storage are the same thing
Both are measured in gigabytes, so they sound alike, but they do different jobs. Memory (RAM) is the counter top: small, fast, holds what is being worked on right now. Storage (SSD) is the storeroom: big, slower, holds your files and apps for good. "My Mac has 8 GB memory and 256 GB storage" describes two different parts. When a download says "not enough space", that is storage; when a program says "out of memory", that is RAM.
Thinking unsaved work is safe if the power goes
Anything you have typed but not saved lives only in memory, and memory is wiped when the power goes off, like a counter wiped at closing time. Saving copies it into storage, which keeps it with the power off. Save early and often; later, your training programs will save the model regularly for the same reason.
Thinking memory, storage or the screen does the calculating
Only the processor works things out. Memory and storage only hold things, like a counter and a storeroom hold ingredients without cooking them. The screen only shows results. When you add 2 and 3, the processor fetches both numbers from memory, adds them, and puts 5 back into memory; then the screen is told to draw a 5.
The screen is not the computer. A monitor is an output device: it shows what the computer sends it. In an iMac or a MacBook the computer and the screen sit in one case, which is why they feel like one thing, but the thinking happens in the processor chip.
Mixing up input and output
Ask "which way does the information travel?". Into the computer (keyboard, trackpad, microphone, camera, a file being opened) is input. Out of the computer to you (screen, speakers, printer) is output. A microphone listens to you, so it is input; a speaker talks to you, so it is output.
Thinking the computer understands what it is doing
The computer does not know that 65 "is" the letter A, or that a photo shows your friend. It only stores numbers and follows instructions about them, extremely fast. Meaning comes from the people who wrote the programs. Keep this in mind all through the course: even the language model you build in Stage 5 is a machine doing arithmetic on numbers. It can be very useful without understanding anything the way you do.
Mixing up bits and bytes
A bit is one switch (0 or 1). A byte is 8 bits together. So 2 bytes is 16 bits, and a 1 GB file holds 8 billion bits. Internet speeds are usually given in bits (megabits per second), and file sizes in bytes (megabytes), which is why a "100 megabit" connection does not download 100 megabytes every second.
Thinking letters are stored as little pictures of letters
Memory has no pictures and no letters, only switches. A letter is stored as its agreed number (A is 65, a is 97, space is 32), and that number is stored as on/off switches. Only when the letter is shown does a program look up how to draw it. That is also why A and a count as different: they are different numbers.
Thinking macOS is one more app
macOS is the operating system: the manager that starts first, shares the processor and memory between all the apps, and keeps files organised. Apps like Safari or Calculator run on top of it and ask it for everything they need. Without the operating system, the apps could not run at all.
Mixing up KB, MB and GB
Each unit is a thousand times the one before, like metres and kilometres. 1 KB = 1,000 bytes; 1 MB = 1,000 KB = 1,000,000 bytes; 1 GB = 1,000 MB = 1,000,000,000 bytes. So a 2 MB photo is 2,000,000 bytes, not 2,000 (that would be 2 KB).
Reading * as "plus"
Keyboards have no × key, so programming languages use * for multiply. 2 * 15 is 30; 2 + 15 is 17.
And print(total) shows a value, not a word. Without quotes, total is a name for a value the program worked out, so print(total) shows that value, such as 30. You will practise names and values properly in lesson s1-01.
Words you learned
- computer
- A machine that takes input, processes it by following instructions, and gives output.
- input
- Information going into the computer: keys, clicks, sound, photos, opened files.
- processing
- The computer working on information, step by step.
- output
- Information coming out for you: the screen, sound, printed pages.
- processor (CPU)
- The chip that does every calculation; the chaiwala.
- memory (RAM)
- Fast, temporary workspace for what is being worked on now; wiped when the power goes off; the counter top.
- storage (SSD)
- Big, slower place that keeps files and apps even when switched off; the storeroom.
- save
- Copy work from memory into storage so it survives switching off.
- bit
- One on/off switch, written 0 or 1.
- byte
- 8 bits together; holds a number from 0 to 255.
- KB, MB, GB
- A thousand, a million and a billion bytes (as macOS counts them).
- operating system
- The program that runs the computer and shares it between apps; on a Mac, macOS.
- app (program)
- A set of instructions that does one kind of job, like Calculator or Safari.
- Python
- The programming language this course uses; you will learn it from Stage 1.
Practice
The Python tasks are checked automatically; for each one you only change or add a line, and hints are there if you get stuck. The last task happens on your own Mac.
Loading the practice tasks…
Check yourself
Loading the quiz…