Computing From Zero — Every Topic, Step by Step

Oct 20, 2026 · @P

Document from the Computing From Zero library · folder artifacts/cfz-every-topic-step-by-step · built from every-topic-step-by-step.md.

How to use this guide#

This guide assumes you know nothing about computers and builds every idea from the one before it. Read it top to bottom the first time: each section uses words that earlier sections already explained.

Three promises it keeps:

  • Every "why" gets answered. Not just "a byte is 8 bits", but why 8, and why anyone counts that way.
  • Every step is shown. Calculations are done line by line, even the obvious lines.
  • Every new word is explained the first time it appears, and again in the glossary at the end.

The big picture in one sentence: a computer is a machine full of tiny switches; everything it does — text, photos, music, games, the internet — is just patterns of those switches being on or off, and rules for changing them.

Suggested order, matching the KS3 course:

  1. Sections 1–7 (what a computer is, and how it stores everything as on/off) — the foundation for everything else.
  2. Sections 8–10 (the parts inside a computer and the software that runs on it).
  3. Sections 11–14 (algorithms and programming) — the "how do I tell it what to do" part.
  4. Sections 15–19 (networks, the web, security, data, and the law) — the "computers in the world" part.

1. What a computer actually is#

A computer is a machine that takes in information, follows a list of instructions to change it, and gives out a result. Underneath, it does this with billions of tiny electrical switches.

Step 1: Input, process, output#

Every computer, from a phone to a games console to the chip in a washing machine, does three things:

  1. Input — it receives information (you press a key, a microphone hears a sound, a sensor reads a temperature).
  2. Process — it follows instructions to change that information (add numbers, find a word, move a character in a game).
  3. Output — it gives back a result (letters on a screen, a sound from a speaker, a motor turning).

Most computers also do a fourth thing: storage — they keep information to use later.

Step 2: Why electricity?#

A computer has to remember and change information very fast. Electricity is ideal because it moves almost instantly and can be switched on and off billions of times a second.

Step 3: A switch has two states#

Think of a light switch. It can only be in one of two positions: on or off. There is no "half on". That is the whole trick of computing: a switch is a tiny thing that can remember one choice between two options.

Step 4: Why only two states, not ten?#

You could imagine a switch with ten levels (0 to 9) to match our normal numbers. Engineers don't do this, for three reasons:

  • Reliability. Electricity is never perfectly steady. Telling "lots of power" from "almost none" is easy. Telling level 6 from level 7 is easy to get wrong when the signal wobbles.
  • Simplicity. A two-state switch is the simplest possible part to build, so you can make it tiny and cheap.
  • Logic. Two states map perfectly onto yes/no and true/false, which is how instructions and decisions work (Section 9).

Step 5: Transistors — the real switches#

Computers don't use light switches; they use transistors. A transistor is a switch with no moving parts, controlled by electricity itself: a small voltage on one wire decides whether current can flow through two others.

  • A modern processor holds billions of transistors on a piece of silicon about the size of a fingernail.
  • Each is so small you would need a powerful microscope to see one.
  • Because electricity controls them, one transistor can switch another — that is how chains of switches make decisions and do arithmetic.

Step 6: Naming the two states#

Writing "on" and "off" is slow, so we use two digits:

StateWe writeCan also mean
Off (no/low voltage)0No, False
On (voltage present)1Yes, True

From here on, whenever you see a 0 or a 1 in computing, picture one tiny switch being off or on. Everything else in this guide is built from that.

Step 7: Hardware and software#

  • Hardware = the physical parts you could touch: chips, wires, screen, keyboard.
  • Software = the instructions (programs) that tell the hardware what to do. You can't touch software; it is stored as patterns of 0s and 1s.

An analogy: hardware is a piano; software is the sheet music. The piano can play anything, but only does something useful when given music.

2. Bits and bytes#

A bit is one switch: a single 0 or 1. A byte is a group of 8 bits. Every amount of computer data — a text, a photo, a game — is measured by counting these.

Step 1: The bit#

  • Bit is short for binary digit. "Binary" means "made of two" (like a *bi*cycle has two wheels).
  • One bit = one switch = one answer to a yes/no question.
  • One bit on its own can only say two things: 0 or 1. That is not much — enough for "light on/off" or "game paused/not paused".

Step 2: More bits = more patterns#

To say more than two things, line several bits up. Watch what happens as we add one bit at a time:

BitsEvery possible patternHow many
10, 12
200, 01, 10, 114
3000, 001, 010, 011, 100, 101, 110, 1118
40000 … 111116
800000000 … 11111111256

Why does it double each time? Take all the patterns you already had. Adding one new bit, each old pattern can now be followed by a 0 or by a 1. So every old pattern becomes two new ones. Two times as many, every time you add a bit.

That gives the rule you will use constantly:

latex
\text{patterns} = 2^{n} \quad \text{where } n \text{ is the number of bits}

In words: 2 multiplied by itself n times. For 8 bits: 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 = 256.

A useful trick: to count up to a number with n bits, the biggest value is 2ⁿ − 1, because one of the patterns is used for zero. 8 bits store 0 to 255 (256 values, including the zero).

Step 3: The byte — why 8?#

A byte is 8 bits. Nothing in physics forces the number 8; people chose it. Here is why it won:

  1. It fits one letter. Early computers needed to store text. English letters (upper and lower case), digits 0–9 and punctuation come to about 100 symbols. 6 bits (64 patterns) is too few; 7 bits (128) is just enough; 8 bits (256) fits them all with room to spare.
  2. 8 is a power of 2 (2 × 2 × 2). Computers count in twos, so groups of 1, 2, 4, 8, 16, 32 bits split and combine cleanly. A group of 7 or 10 would not.
  3. It splits neatly in half. 8 bits = two groups of 4. Four bits (called a nibble, a joke: a small byte) matches exactly one hexadecimal digit (Section 3), so a byte is always written as two hex digits.
  4. A big company standardised it. IBM's System/360 computers (1964) used 8-bit bytes. They sold so well that everyone else followed, and it has been the standard ever since.

The name: an IBM engineer, Werner Buchholz, coined "byte" in 1956 — a bite-sized chunk of bits, spelt with a y so nobody would confuse it with "bit".

Step 4: Bigger units — and the 1000 vs 1024 puzzle#

One byte is tiny (one letter). Real files are millions of bytes, so we need bigger units. There are two systems, and this confuses everyone, so slowly:

System A — decimal (powers of 1000). This is the same "kilo" as in kilogram or kilometre.

UnitSymbolEquals
KilobyteKB1,000 bytes
MegabyteMB1,000 KB = 1,000,000 bytes
GigabyteGB1,000 MB
TerabyteTB1,000 GB
PetabytePB1,000 TB

System B — binary (powers of 1024). Computers count in twos, and 1000 is not a power of 2. The nearest power of 2 is 2¹⁰ = 1024. So computer memory naturally comes in sizes of 1024, and people used "kilobyte" for 1024 bytes too. To fix the confusion, in 1998 a standards body (the IEC) gave the binary sizes their own names:

UnitSymbolEquals
KibibyteKiB1,024 bytes
MebibyteMiB1,024 KiB
GibibyteGiB1,024 MiB
TebibyteTiB1,024 GiB

What exam boards want: AQA expects both systems (kilo = 1000, kibi = 1024). OCR accepts either 1000 or 1024 in calculations. Using 1000 is quicker by hand.

Why your "1 TB" drive shows about 931 GB: the maker counts 1 TB = 1,000,000,000,000 bytes. Windows divides by 1024 three times but still writes "GB":

  1. 1,000,000,000,000 ÷ 1024 = 976,562,500 KiB
  2. 976,562,500 ÷ 1024 ≈ 953,674 MiB
  3. 953,674 ÷ 1024 ≈ 931 GiB

No space is missing; it is the same amount measured with a different ruler.

Step 5: Converting between units#

One rule: going to a bigger unit, divide; going to a smaller unit, multiply. (Big units need fewer of themselves to describe the same amount.)

Example — how many bytes in 3 MB (decimal)?

  1. 3 MB × 1000 = 3,000 KB
  2. 3,000 KB × 1000 = 3,000,000 bytes

Example — how many bits is that?

  1. 3,000,000 bytes × 8 = 24,000,000 bits

Example — a 4,500,000-byte file in MB:

  1. 4,500,000 ÷ 1000 = 4,500 KB
  2. 4,500 ÷ 1000 = 4.5 MB

Step 6: Bits vs bytes in internet speeds#

  • File sizes use bytes (capital B: MB).
  • Internet speeds use bits per second (small b: Mbps, megabits per second).

So a "100 Mbps" connection does not download 100 MB a second. Divide by 8: 100 ÷ 8 = 12.5 MB per second at best.

Step 7: A sense of scale#

ThingRough size
One letter of text1 byte
A page of plain textabout 2 KB
A phone photoabout 2–5 MB
A 3-minute MP3 songabout 3–4 MB
An hour of HD videoabout 1–3 GB
A large modern game50–150 GB

3. Number systems: denary, binary, hexadecimal#

A computer stores every number as a pattern of bits, using binary (base 2). Humans normally use denary (base 10), and programmers use hexadecimal (base 16) as a short way of writing binary. All three work by the same idea: place value.

Step 1: How our normal numbers already work (denary)#

We use ten digits, 0–9, probably because we have ten fingers. When you run out of digits, you start a new column to the left and go back to 0 — that is why 9 is followed by 10.

Each column is worth 10 times the column to its right:

ThousandsHundredsTensOnes
1000100101
3507

So 3507 means (3 × 1000) + (5 × 100) + (0 × 10) + (7 × 1). You do this in your head without thinking. Binary is exactly the same, with 2 in place of 10.

Step 2: Binary place values#

Binary has only two digits, 0 and 1 (because a switch has two states). Each column is worth 2 times the column to its right. For one byte (8 bits):

1286432168421

How to build this row yourself: start at 1 on the right, then keep doubling as you move left. 1, 2, 4, 8, 16, 32, 64, 128. Learn it by heart — it is used in almost every calculation.

The leftmost bit (worth the most) is the most significant bit (MSB); the rightmost is the least significant bit (LSB).

Counting in binary, to feel it: 0, 1, 10, 11, 100, 101, 110, 111, 1000… Each time a column "fills up" at 1, it resets to 0 and carries 1 to the left — just like 9 → 10 in denary.

Step 3: Binary → denary#

Convert 01101011:

  1. Write the place values above the bits.
1286432168421
01101011
  1. Find every column with a 1: 64, 32, 8, 2, 1.
  2. Add them: 64 + 32 + 8 + 2 + 1 = 107.

That's all. A 0 means "don't count this column"; a 1 means "count it".

Step 4: Denary → binary (subtraction method)#

Convert 156:

  1. Start at 128. Does 128 fit into 156? Yes → write 1. 156 − 128 = 28 left.
  2. 64 into 28? No → 0.
  3. 32 into 28? No → 0.
  4. 16 into 28? Yes → 1. 28 − 16 = 12 left.
  5. 8 into 12? Yes → 1. 12 − 8 = 4 left.
  6. 4 into 4? Yes → 1. 4 − 4 = 0 left.
  7. 2 into 0? No → 0.
  8. 1 into 0? No → 0.

Answer: 10011100. Check by converting back: 128 + 16 + 8 + 4 = 156. Correct.

Alternative (divide by 2): keep halving and write down each remainder, then read the remainders from bottom to top. 156 → 78 r0 → 39 r0 → 19 r1 → 9 r1 → 4 r1 → 2 r0 → 1 r0 → 0 r1. Bottom to top: 10011100. Same answer.

Step 5: Hexadecimal — why it exists#

Binary is perfect for machines but painful for people: 1001110011110101 is hard to read, copy or remember. Hexadecimal (hex) is a shorthand.

The key fact: 4 bits make 16 patterns (2⁴ = 16). So if we had 16 digits, each digit could stand for exactly 4 bits. We only have ten number symbols, so we borrow letters for the other six:

Denary0123456789101112131415
Hex0123456789ABCDEF
Binary0000000100100011010001010110011110001001101010111100110111101111

One byte = two nibbles = exactly two hex digits. 11111111 becomes FF. That's why hex is everywhere: web colours (#FF0000 is pure red), MAC addresses, error codes, memory addresses.

Important: hex does not change how the computer stores anything. It is only a way for humans to write binary.

Step 6: Converting with hex#

Binary → hex: split into groups of 4 from the right, convert each group.

  1. 10011100 → 1001 | 1100
  2. 1001 = 8 + 1 = 9; 1100 = 8 + 4 = 12 = C
  3. Answer: 9C

Hex → binary: turn each digit back into 4 bits. 3F → 3 = 0011 and F = 1111, so 3F = 0011 1111.

Hex → denary: hex place values are 16 and 1 (for two digits). 9C = (9 × 16) + (12 × 1) = 144 + 12 = 156. It matches Step 4.

Denary → hex: divide by 16. 200 ÷ 16 = 12 remainder 8. 12 = C, so 200 = C8. Check: 12 × 16 + 8 = 192 + 8 = 200.

Step 7: Adding in binary#

There are only four rules. Remember that "10" in binary means two, and "11" means three.

SumAnswerWriteCarry
0 + 0000
0 + 1110
1 + 12 = binary 1001
1 + 1 + 1 (with a carry)3 = binary 1111

Worked example: 01101011 (107) + 00110110 (54). Work from the right, one column at a time:

  1. Column 1: 1 + 0 = 1 → write 1.
  2. Column 2: 1 + 1 = 10 → write 0, carry 1.
  3. Column 3: 0 + 1 + carry 1 = 10 → write 0, carry 1.
  4. Column 4: 1 + 0 + carry 1 = 10 → write 0, carry 1.
  5. Column 5: 0 + 1 + carry 1 = 10 → write 0, carry 1.
  6. Column 6: 1 + 1 + carry 1 = 11 → write 1, carry 1.
  7. Column 7: 1 + 0 + carry 1 = 10 → write 0, carry 1.
  8. Column 8: 0 + 0 + carry 1 = 1 → write 1.

Result: 10100001 = 128 + 32 + 1 = 161. And 107 + 54 = 161. Correct.

Step 8: Overflow#

A byte can hold at most 255. What if the answer is bigger?

11001000 (200) + 01100100 (100) should be 300. Doing the columns gives 00101100 with a 1 carried out of the 8th column — but there is no 9th column to put it in. The carry is lost, and the byte holds 00101100 = 44. This is an overflow error: the result is too big for the number of bits available.

Real effects: an old game score jumping back to zero, or a counter suddenly showing a tiny number.

Step 9: Binary shifts#

A shift slides every bit left or right and fills the gap with 0.

  • Left shift by 1 = multiply by 2. 00010110 (22) → 00101100 (44). Each bit moves to a column worth double.
  • Right shift by 1 = divide by 2. 00010110 (22) → 00001011 (11).
  • Shift by 2 places = × or ÷ 4; by 3 places = × or ÷ 8.
  • Bits pushed off the end are lost. 00001011 (11) shifted right becomes 00000101 (5), not 5.5 — the remainder falls off. Shifting left too far causes overflow.

Same idea in denary: moving digits one place left multiplies by 10 (35 → 350).

Step 10: Negative numbers (beyond GCSE, for interest)#

So far every pattern meant a positive number. To store negatives, the common method is two's complement: the leftmost bit is worth −128 instead of +128.

To write −5 in 8 bits:

  1. Write +5: 00000101.
  2. Flip every bit: 11111010.
  3. Add 1: 11111011.
  4. Check: −128 + 64 + 32 + 16 + 8 + 2 + 1 = −128 + 123 = −5.

A byte then holds −128 to +127 instead of 0 to 255: the same 256 patterns, split between negatives and positives. This is A-level content; KS3 and GCSE stay with positive whole numbers.

4. Representing text#

Computers store letters by giving every character a number, then storing that number in binary. The agreed list of characters and their numbers is called a character set.

Step 1: The problem#

A computer can only store bits. A letter like "A" is a shape, not a number. So we need a code — like a secret code where A = 1, B = 2 — that every computer in the world agrees on.

Step 2: Why everyone must agree#

If my computer uses A = 65 and yours uses A = 12, a message I send you turns into nonsense. A character set is the shared agreement: a table listing every character and the number that stands for it.

Step 3: ASCII#

ASCII (American Standard Code for Information Interchange, said "ass-key") was agreed in the 1960s.

  • It uses 7 bits per character → 2⁷ = 128 characters.
  • That covers A–Z, a–z, 0–9, punctuation, the space, and some invisible "control characters" (like new line).
  • In practice each character is stored in a full byte (8 bits); "extended ASCII" uses the 8th bit to add 128 more characters such as é and ñ.

A few codes worth knowing:

CharacterDenary codeBinary
A6501000001
B6601000010
Z9001011010
a9701100001
0 (the digit)4800110000
space3200100000

Step 4: Clever things about the order#

  • Letters are in sequence. If A = 65, then B = 66, C = 67… So you can work out any letter by counting. This is also why computers can sort words alphabetically: they compare the numbers.
  • Lower case = upper case + 32. a (97) − A (65) = 32. In binary, that is just one bit different, which made converting case very cheap for old machines.
  • Upper case comes before lower case. So a computer may sort "Zebra" before "apple" (90 < 97). That surprises students.
  • The digit "7" is not the number 7. The character "7" has code 55. That is why, in programming, "7" + "7" can give "77" (joining two characters) instead of 14 (Section 13).

Step 5: Worked example — storing "Hi"#

  1. Look up H → 72. Look up i → 105.
  2. Convert 72 to binary: 64 + 8 → 01001000.
  3. Convert 105 to binary: 64 + 32 + 8 + 1 → 01101001.
  4. The computer stores: 01001000 01101001.
  5. Size: 2 characters × 8 bits = 16 bits = 2 bytes.

General rule: text size in bits = number of characters × bits per character. "Hello world" (11 characters, including the space) in 8-bit ASCII = 11 × 8 = 88 bits = 11 bytes.

Step 6: Unicode — when 256 is not enough#

ASCII was built for English. It has no room for Chinese (thousands of characters), Arabic, Hindi, Greek, or emoji. Different countries made their own 8-bit sets, and they clashed: the same number meant different letters in different countries.

Unicode fixes this with one giant list for every writing system in the world.

  • It has room for over a million characters; around 150,000 are assigned so far, including emoji.
  • Its first 128 codes are identical to ASCII, so old English text still works (A is still 65).
  • The most common way to store it, UTF-8, uses 1 byte for ASCII characters and 2 to 4 bytes for others. So English text stays small, and everything else still fits.

Step 7: The trade-off#

ASCIIUnicode
Characters128 (256 extended)Over a million possible
Bits per character7 (stored in 8)8 to 32 (in UTF-8)
LanguagesEnglish onlyAll of them, plus emoji
File sizeSmallerLarger for non-English text

Spanish example: ñ is not in 7-bit ASCII. Garbled text like "España" on a web page happens when a file saved in UTF-8 is read as if it were an older 8-bit set — the two bytes of ñ get shown as two separate characters.

5. Representing images#

A digital picture is a grid of tiny coloured squares called pixels, and each pixel's colour is stored as a binary number. More pixels and more colours give a better picture — and a bigger file.

Step 1: Pixels#

Zoom right into any photo on a screen and it turns into little squares. Each square is a pixel (short for picture element): the smallest dot of a single colour. This kind of image is called a bitmap (a "map of bits").

Step 2: The simplest image — black and white#

If a pixel can only be black or white, one bit is enough: 1 = black, 0 = white. Here is a 5 × 5 letter T:

1 1 1 1 1
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0

The computer stores the rows one after another: 11111 00100 00100 00100 00100 — 25 bits. It also needs to know the grid is 5 pixels wide, otherwise it can't rebuild the rows.

Step 3: More colours = more bits per pixel#

The number of bits used for each pixel is called colour depth (or bit depth). It works exactly like Section 2: n bits give 2ⁿ patterns, so 2ⁿ possible colours.

Colour depthColours possibleTypical use
1 bit2Black and white
2 bits4Very early games
8 bits256GIFs, retro graphics
24 bits16,777,216 (about 16.7 million)Normal photos ("true colour")

With 2 bits you might agree: 00 = white, 01 = red, 10 = blue, 11 = black.

Step 4: How 24-bit colour works (RGB)#

Screens make every colour by mixing three lights: Red, Green and Blue. Each gets one byte (0–255), so 3 × 8 = 24 bits per pixel.

ColourRedGreenBlueHex code
Black000#000000
White255255255#FFFFFF
Pure red25500#FF0000
Yellow2552550#FFFF00
Orange2551280#FF8000

Why is red + green = yellow? Mixing light adds colours (unlike mixing paint, which removes them). The hex codes are just the three bytes written in hex (Section 3) — this is exactly what you type in HTML and CSS.

Step 5: Resolution#

Resolution is how many pixels make up the image, written width × height. A Full HD image is 1920 × 1080 = 2,073,600 pixels. More pixels means finer detail; too few and you see blocky squares ("pixelation").

Step 6: Calculating file size#

The formula only uses things you already know:

latex
\text{size in bits} = \text{width} \times \text{height} \times \text{colour depth}

Worked example — a 1920 × 1080 photo at 24-bit colour:

  1. Pixels: 1920 × 1080 = 2,073,600.
  2. Bits: 2,073,600 × 24 = 49,766,400 bits.
  3. Bytes: 49,766,400 ÷ 8 = 6,220,800 bytes.
  4. KB: 6,220,800 ÷ 1000 = 6,220.8 KB.
  5. MB: 6,220.8 ÷ 1000 ≈ 6.2 MB.

The real file on your phone is usually smaller because it is compressed (Section 7).

Step 7: The trade-off#

  • Double the colour depth → double the size.
  • Double the width and the height → four times the pixels → four times the size.
  • Better quality always costs more storage and more time to send over the internet.

Step 8: Metadata#

The file must also store metadata — "data about the data" — so the picture can be rebuilt: width, height and colour depth at minimum. Phones also add the date, camera model and often the GPS location where the photo was taken. That last one matters for online safety (Section 19).

Step 9: Bitmap vs vector (bonus)#

  • Bitmap: stores every pixel. Great for photos; goes blocky when enlarged.
  • Vector: stores shapes as instructions ("circle, centre here, radius 40, fill red"). Stays sharp at any size; used for logos, icons and fonts. Not good for photos.

6. Representing sound#

A computer stores sound by measuring the height of the sound wave thousands of times a second and saving each measurement as a binary number. This is called sampling.

Step 1: What sound is#

Sound is air vibrating. When a guitar string moves, it pushes air back and forth; those pushes reach your ear. Drawn on paper, the pressure going up and down over time looks like a smooth wavy line — a wave.

Step 2: Analogue vs digital#

  • Analogue = smooth and continuous. A real sound wave can take any height at any moment, infinitely fine.
  • Digital = made of separate steps (digits). A computer can only store a finite list of numbers.

So turning sound into data means turning a smooth wave into a list of numbers. A microphone first turns the air pressure into a changing electrical voltage (still analogue). Then a chip called an ADC (analogue-to-digital converter) does the sampling. To play it back, a DAC (digital-to-analogue converter) turns the numbers back into a voltage that moves a speaker.

Step 3: Sampling, step by step#

  1. Pick regular moments in time (say, every thousandth of a second).
  2. At each moment, measure how high the wave is.
  3. Round that height to the nearest level you're allowed to store.
  4. Save the level as a binary number.
  5. Repeat for the whole recording.

Tiny example: suppose we can store only 3 bits per sample (levels 0–7, because 2³ = 8). We measure a wave 8 times and get:

Sample12345678
Level46764212
Binary100110111110100010001010

The file stores 100110111110100010001010. Playing it back, the computer joins the dots — a blocky copy of the original curve.

Step 4: Sample rate — how often you measure#

Sample rate = number of samples per second, measured in hertz (Hz). 1 Hz = once per second; 1 kHz = 1000 times per second.

  • More samples per second → the dots are closer → the copy follows the curve more closely.
  • CDs use 44,100 Hz (44.1 kHz).

Why 44,100? Humans hear up to about 20,000 vibrations a second. To capture a wave you must measure it at least twice per vibration (once near the top, once near the bottom), so you need over 40,000 samples a second.

Step 5: Bit depth — how precisely you measure#

Bit depth (also called sample resolution) = number of bits per sample. Same rule again: n bits give 2ⁿ levels.

  • 3 bits → 8 levels (our toy example: very rough).
  • 8 bits → 256 levels (old games, phone calls).
  • 16 bits → 65,536 levels (CD quality).

More levels → each measurement rounds less → less hiss and distortion.

Step 6: Calculating file size#

latex
\text{size in bits} = \text{sample rate} \times \text{bit depth} \times \text{seconds} \times \text{channels}

(Channels: 1 for mono, 2 for stereo — a left and a right speaker each get their own samples. GCSE questions usually leave channels out, meaning mono.)

Worked example — a 3-minute song, CD quality, stereo:

  1. Seconds: 3 × 60 = 180.
  2. Bits per second, one channel: 44,100 × 16 = 705,600.
  3. Two channels: 705,600 × 2 = 1,411,200 bits per second.
  4. Whole song: 1,411,200 × 180 = 254,016,000 bits.
  5. Bytes: 254,016,000 ÷ 8 = 31,752,000 bytes ≈ 31.8 MB.

An MP3 of the same song is about 3–4 MB because it is compressed (next section).

Step 7: The trade-off#

Higher sample rate and higher bit depth → closer to the real sound, but bigger files. Halve either one and the file halves.

7. Compression#

Compression makes files smaller by storing the same information in fewer bits. Lossless compression gets back every bit exactly; lossy compression throws away detail you probably won't notice, in exchange for much smaller files.

Step 1: Why compress?#

Sections 5 and 6 showed a photo can be 6 MB and a song 32 MB before compression. Smaller files:

  • take up less storage,
  • download and stream faster,
  • use less mobile data.

Step 2: Lossless vs lossy#

LosslessLossy
What happensFinds repetition and writes it more cleverlyPermanently removes detail
Get the original back?Yes, exactlyNo — the removed detail is gone
Size reductionModerateLarge
Used forText, code, spreadsheets, PNG images, ZIP files, FLAC audioPhotos (JPEG), music (MP3, AAC), video (MP4), streaming

Why you must never use lossy compression on text or a program: losing even one bit could change a word, a number or an instruction, and the program would break.

Step 3: Run-length encoding (RLE) — lossless#

Idea: instead of writing the same thing many times in a row, write how many and what.

Worked example with letters: AAAABBBCCD

  1. Read from the left: four A's in a row → write 4A.
  2. Then three B's → 3B.
  3. Then two C's → 2C.
  4. Then one D → 1D.
  5. Result: 4A3B2C1D — 8 characters instead of 10.

Worked example with an image row (W = white, B = black): WWWWWWWWBBBW → 8W 3B 1W. Pictures with big areas of one colour (logos, cartoons, the letter T from Section 5) compress very well this way.

When RLE fails: ABCD becomes 1A1B1C1D — twice as long. RLE only helps when there are runs of repeats; photos with constantly changing colours have few.

Step 4: Huffman coding — lossless#

Idea: in normal text every character uses 8 bits, even very common ones. Huffman gives common characters short codes and rare characters long codes, like Morse code does (E is a single dot).

Worked example — compress BANANA:

  1. Count each letter. A = 3, N = 2, B = 1.
  2. List them from least to most common: B(1), N(2), A(3).
  3. Join the two smallest into one branch: B(1) + N(2) = a group worth 3.
  4. Repeat: now we have A(3) and the group(3). Join them: total 6. Only one thing is left, so the tree is finished.
  5. Label the branches: left = 0, right = 1.
        (6)
       0/ \1
      A(3) (3)
          0/ \1
         B(1) N(2)
  1. Read each letter's code by following the path from the top: A = 0, B = 10, N = 11.
  2. Encode BANANA: B A N A N A → 10 0 11 0 11 0 → 100110110 = 9 bits.
  3. Compare: in 8-bit ASCII, 6 letters × 8 = 48 bits. Huffman uses 9. That is over 80% smaller.

How does the computer know where one code ends, with no spaces? No code is the start of another code (0 vs 10 vs 11). So reading 100110110 from the left, the first possible match is always the right one: 10 = B, 0 = A, 11 = N, 0 = A, 11 = N, 0 = A. The tree itself must be saved with the file so it can be decoded.

Step 5: How lossy compression decides what to throw away#

  • Images (JPEG): human eyes notice changes in brightness more than small changes in colour, so JPEG keeps brightness and simplifies colour in small blocks. Over-compress and you see blocky squares ("artefacts").
  • Sound (MP3): removes sounds outside human hearing, and quiet sounds hidden under louder ones at the same moment.
  • Video: most of a frame is the same as the last one, so it stores mainly what changed.

Step 6: Choosing#

Ask one question: would losing a tiny bit of detail matter? A holiday photo for Instagram — no, use lossy. A medical scan, a contract, a game's code — yes, use lossless.

8. Inside the computer: CPU, memory and storage#

The CPU (processor) does the work, memory (RAM) holds what it is working on right now, and storage keeps everything long-term. The CPU runs programs by repeating one loop — fetch, decode, execute — billions of times a second.

Step 1: A kitchen analogy#

KitchenComputerWhy
The chefCPUDoes all the actual work, one step at a time
The worktopRAM (main memory)Small, very fast to reach, holds only what's being used now; cleared at closing time
The cupboards and freezerStorage (SSD / hard drive)Large, slower to reach, keeps everything even when the kitchen is closed
The recipeA programThe list of steps to follow

Keep this in mind: the CPU cannot work directly from storage. Anything it uses must first be copied into RAM — like taking ingredients out of the cupboard and putting them on the worktop.

Step 2: The stored-program idea (von Neumann architecture)#

Early machines were rewired by hand for each new job. In the 1940s, John von Neumann described a better design that almost every computer still uses:

  • Program instructions and data are both just binary numbers.
  • So both can be stored in the same memory.
  • The CPU fetches instructions from memory one at a time and carries them out.

To change what the computer does, you just load a different program. No rewiring.

Step 3: The parts of the CPU#

  • Control Unit (CU) — the manager. It fetches each instruction, works out what it means (decodes it) and sends signals telling the other parts what to do.
  • Arithmetic Logic Unit (ALU) — the calculator. It does arithmetic (+, −) and logic (comparisons like "is A bigger than B?", AND, OR, NOT — Section 9).
  • Registers — a handful of tiny, super-fast storage spaces inside the CPU, each holding one value it is using this instant.
  • Cache — a small amount of very fast memory on the CPU chip that keeps copies of data used often, so the CPU doesn't wait for slower RAM.
  • Clock — sends out a steady pulse; each tick lets the CPU take a step.

Step 4: The registers you need to know#

RegisterFull nameHolds
PCProgram CounterThe address (location in memory) of the next instruction
MARMemory Address RegisterThe address the CPU is about to read from or write to
MDRMemory Data RegisterThe data or instruction just read from memory, or about to be written
ACCAccumulatorThe result of the latest calculation by the ALU

Memory is like a long street of numbered houses; an address is the house number, and the data is what's inside.

Step 5: The fetch–decode–execute cycle#

This is the loop the CPU repeats for as long as the computer is on.

Fetch

  1. The PC holds the address of the next instruction — say, address 20.
  2. That address (20) is copied into the MAR.
  3. The CPU sends the address to RAM along wires called the address bus.
  4. RAM sends back the instruction stored at address 20, along the data bus, into the MDR.
  5. The PC goes up by 1 (to 21), ready for next time.

Decode

  1. The Control Unit reads the instruction and works out what it means — for example "add the number at address 50 to the accumulator".

Execute

  1. The instruction is carried out: data might be fetched from memory, the ALU might add, the result goes into the accumulator or back to memory.
  2. Go back to step 1.
In the original, a live figure here

fetch–decode–execute cycle · 3 stages, 7 steps

Read it left to right, then follow the arrow back: after step 5 the PC already points at address 21, so the next loop fetches the next instruction automatically.

Step 6: What makes a CPU faster#

  • Clock speed — how many cycles per second, in hertz. 3.5 GHz = 3.5 billion ticks a second. More ticks, more instructions done.
  • Number of cores — a core is a complete processing unit (its own CU, ALU, registers). A quad-core CPU can work on 4 things at once — but only if the program can be split into parts that run at the same time. Doubling cores never quite doubles speed.
  • Cache size — more cache means fewer slow trips to RAM.

Step 7: Main memory — RAM and ROM#

RAM (Random Access Memory)ROM (Read Only Memory)
HoldsPrograms and data in use right nowThe start-up instructions (the BIOS/boot program)
When power goes offVolatile — everything is lostNon-volatile — kept forever
Can it be changed?Yes, constantlyNormally no (read only)
SizeLarge (8–32 GB in a typical PC)Tiny

Why ROM is needed: when you switch on, RAM is empty. Something must already be there to tell the CPU how to start and load the operating system from storage. That "something" lives in ROM.

Virtual memory: if RAM fills up, the operating system borrows part of the storage drive and pretends it's extra RAM. It works, but storage is far slower, so the computer becomes sluggish. Buying more RAM fixes it.

Step 8: Secondary storage — keeping things for good#

Storage is non-volatile: it keeps data with no power. There are three ways to physically hold bits:

TypeHow a bit is storedExamplesStrengthsWeaknesses
MagneticTiny areas of a spinning disk magnetised one way (1) or the other (0)Hard disk drive (HDD)Cheapest per GB, huge capacityMoving parts: slower, can break if dropped
Solid stateElectrical charge trapped in flash memory cellsSSD, USB stick, SD card, phonesVery fast, silent, no moving parts, toughCosts more per GB
OpticalTiny pits and flat areas on a disc, read by a laserCD, DVD, Blu-rayCheap to post and sellSmall capacity, slow, scratches

How to choose: think about capacity, speed, portability, durability, reliability and cost. A laptop that gets carried around → SSD (no moving parts). A company backup of huge amounts of data → HDD or tape (cheap per GB).

Step 9: Embedded systems#

An embedded system is a small computer built inside another device to do one job: the controller in a washing machine, a microwave, a car's braking system, a smart thermostat, a micro:bit. It usually has its program fixed in ROM, uses little power, and costs very little. Most computers in the world are embedded — far more than PCs and phones.

9. Logic gates and Boolean logic#

A logic gate is a tiny circuit, made of transistors, that takes one or two bits in and gives one bit out according to a fixed rule. Chaining millions of gates is how a CPU makes decisions and does arithmetic.

Step 1: Boolean = true or false#

In the 1850s, mathematician George Boole worked out an algebra for statements that are only ever true or false. A century later engineers noticed it fits switches perfectly: 1 = true, 0 = false. Values that can only be true or false are called Boolean.

Step 2: How switches make a decision#

Imagine a bulb, a battery and two switches A and B:

  • Put A and B one after the other (in series): the bulb lights only if A and B are both on. That's an AND gate.
  • Put A and B side by side (in parallel): the bulb lights if A or B (or both) is on. That's an OR gate.

Inside a chip the "switches" are transistors, so one gate's output can switch the next gate.

Step 3: The three basic gates#

A truth table lists every possible input and the output for each. With 2 inputs there are 2² = 4 rows (same rule as Section 2).

NOT — flips the bit. One input.

ANOT A
01
10

AND — output is 1 only if both inputs are 1.

ABA AND B
000
010
100
111

OR — output is 1 if at least one input is 1.

ABA OR B
000
011
101
111

Everyday meaning: "You can go out if your homework is done AND your room is tidy" vs "You can have juice OR milk" (in logic, having both still counts as true).

XOR (exclusive OR) — 1 if the inputs are different: 0 1 → 1, 1 0 → 1, but 1 1 → 0. AQA uses it; OCR sticks to AND, OR, NOT.

Standard symbols: AND is a D shape; OR is a curved shield shape; NOT is a triangle with a small circle (the circle means "flip"). In written logic: A AND B is written A ∧ B or A·B; A OR B is A ∨ B or A+B; NOT A is ¬A or Ā.

Step 4: Combining gates#

Gates can feed into each other. Example: P = (A AND B) OR (NOT C).

With 3 inputs there are 2³ = 8 rows. Work out the middle columns first, then the final one:

ABCA AND BNOT CP
000011
001000
010011
011000
100011
101000
110111
111101

Tip for writing the input columns without missing a row: count from 0 to 7 in binary (000, 001, 010 … 111).

A real-world one: a car alarm sounds if (the alarm is set) AND (a door is opened OR the window is broken). That's ALARM = S AND (D OR W).

Step 5: How gates do arithmetic#

Look back at binary addition (Section 3, Step 7) for two single bits:

ABSum bitCarry bit
0000
0110
1010
1101
  • The carry column is exactly the AND table.
  • The sum column is exactly the XOR table.

So one XOR gate plus one AND gate can add two bits — this is called a half adder. Chain 8 of these (with a bit more logic for carries) and you can add two bytes. Inside the ALU, that is all addition is: gates.

Step 6: Logic in programming#

The same three words appear in code (Section 13): if age >= 13 and has_permission: or if key == "q" or key == "Escape":. The CPU runs these using its ALU's logic gates.

10. Software: operating systems, utilities, languages and translators#

Software comes in two kinds: system software that runs the computer itself, and application software that does jobs for people. Programs are written in human-readable languages and must be translated into the CPU's binary machine code before they can run.

Step 1: Two kinds of software#

System softwareApplication software
JobRuns and looks after the computerLets the user do a task
ExamplesOperating system, antivirus, backup tools, driversWord processor, browser, games, Spotify, Unreal Engine

Step 2: The operating system (OS)#

The OS (Windows, macOS, Linux, Android, iOS) sits between the hardware and every other program. Without it, each app would need to know how to talk to every model of printer, screen and drive. Its jobs:

  1. User interface — gives you a way to use the computer: windows, icons, menus, a pointer (a GUI), or typed commands.
  2. Memory management — decides which program gets which part of RAM, stops programs overwriting each other, and uses virtual memory when RAM is full (Section 8).
  3. Process management (multitasking) — a single core can only run one instruction at a time. The OS switches between programs thousands of times a second, so music, a browser and a game seem to run together.
  4. Peripheral management — uses small programs called drivers to talk to each piece of hardware (printer, keyboard, graphics card).
  5. File management — organises storage into files and folders; lets you name, move, copy and delete them.
  6. User management — accounts, passwords, and who may access what.

Step 3: Utility software#

Small programs that keep the computer healthy:

  • Antivirus / anti-malware — scans for harmful software and removes it.
  • Backup — copies files elsewhere. A full backup copies everything; an incremental backup only copies what changed since last time (faster, smaller).
  • Compression — shrinks files (Section 7), e.g. making a ZIP.
  • Encryption — scrambles data so only someone with the key can read it (Section 17).
  • Defragmentation — on hard disks, a file's pieces get scattered across the disk over time; defragging moves them back together so the read head moves less. Not needed (and not good) for SSDs, which have no moving parts.

Step 4: Levels of programming language#

The CPU only understands machine code: binary instructions specific to that type of processor. Humans find that almost impossible to write, so we use languages closer to English and translate them.

The same job — add two numbers and store the result — at three levels:

LevelLooks likeNotes
Machine code (low level)10100101 00110010 …What the CPU actually runs. Different CPUs use different codes
Assembly language (low level)LDA 50 / ADD 51 / STA 52Short words for each machine instruction, one-to-one. Used for drivers and tiny embedded chips
High-level languagetotal = a + bPython, C#, Java, JavaScript. One line can become many machine instructions. Works on any CPU once translated

High-level: easier to write, read and fix; portable between machines. Low-level: direct control of the hardware, can be faster and smaller, but slow to write and tied to one CPU.

Step 5: Translators#

A translator converts code into machine code. Three kinds:

  • Assembler — turns assembly language into machine code.
  • Compiler — translates the whole high-level program at once into a separate machine-code file (like a .exe). Then you run that file.
  • Interpreter — translates and runs the program one line at a time, every time it runs.
CompilerInterpreter
When it translatesAll at once, before runningLine by line, while running
OutputA standalone executable fileNo file — needs the interpreter every time
Speed when runningFastSlower
ErrorsReports all errors after compiling; nothing runs until fixedStops at the first error line — handy for beginners
SharingUsers don't see the source codeUsers need the source code and the interpreter
ExamplesC, C++ (Unreal Engine)Python (in school), JavaScript in browsers

Analogy: a compiler is a translator who translates a whole book before publishing it. An interpreter is a live interpreter at a meeting, translating each sentence as it is spoken.

Step 6: The IDE#

An IDE (Integrated Development Environment) is the program you write code in — Thonny, IDLE, VS Code, Visual Studio. Common tools:

  • Editor with syntax highlighting (colours for keywords), auto-indent, line numbers.
  • Run button that calls the translator for you.
  • Error messages that point to the line with a problem.
  • Debugger: breakpoints (pause at a line), stepping (run one line at a time), and watching variable values change.

11. Algorithms and computational thinking#

An algorithm is a precise, step-by-step set of instructions to solve a problem. Computational thinking is the set of habits for turning a messy real problem into an algorithm a computer can follow.

Step 1: What an algorithm is#

A recipe, directions to a friend's house, the steps to tie a shoelace — all algorithms. For a computer, an algorithm must be:

  • Precise — no step can be misunderstood.
  • Ordered — steps happen in a set order.
  • Finite — it must eventually stop.

Why precision matters: ask someone to follow "put jam on the bread" literally and they may put the jar on the bread. Computers are that literal. They do exactly what you say, never what you meant.

An algorithm is not code. It's the plan. The same algorithm can be written in Scratch, Python or plain English; a program is an algorithm written in a programming language.

Step 2: The four parts of computational thinking#

  1. Decomposition — break a big problem into smaller ones you can solve one at a time. "Make a game" → draw the player, make it move, add enemies, detect collisions, keep score.
  2. Pattern recognition — notice what's similar, so one solution covers many cases. Every enemy moves the same way → write the movement once and reuse it.
  3. Abstraction — ignore detail that doesn't matter for this problem. The London Tube map ignores real distances and street layouts, keeping only stations, lines and the order of stops. A football game may ignore the weather.
  4. Algorithmic thinking — write the exact sequence of steps, including the decisions and repeats.

Step 3: The three building blocks#

Every algorithm, however complicated, is built from only three structures:

BlockMeaningEveryday example
SequenceDo steps in order, one after anotherPut on socks, then shoes
SelectionChoose a path based on a condition (if… else…)If it's raining, take an umbrella; otherwise take sunglasses
IterationRepeat steps (loops)Stir 20 times; or keep stirring until smooth

There are two kinds of iteration: count-controlled (repeat a fixed number of times) and condition-controlled (repeat until something becomes true).

Step 4: Writing algorithms down — flowcharts#

A flowchart draws the algorithm with standard shapes joined by arrows:

ShapeMeans
Rounded ovalStart / Stop
ParallelogramInput or output (ask the user, show a result)
RectangleA process — doing something (calculate, set a value)
DiamondA decision — a yes/no question with two arrows out
Rectangle with double side linesA subroutine (a named mini-algorithm defined elsewhere)
ArrowWhich step comes next

A loop in a flowchart is simply an arrow that goes back up to an earlier step.

Step 5: Writing algorithms down — pseudocode#

Pseudocode ("fake code") looks like a programming language but isn't one. It ignores fussy rules so you can focus on the logic. Exam boards each publish their own style; any clear version is accepted.

Example — find the biggest number in a list:

numbers ← [7, 3, 12, 5]
biggest ← numbers[0]
FOR EACH n IN numbers
    IF n > biggest THEN
        biggest ← n
    ENDIF
ENDFOR
OUTPUT biggest

The arrow ← means "store this value in this name" (Section 13). Indenting shows which lines are inside the loop and inside the IF.

Step 6: Tracing — checking an algorithm by hand#

A trace table records the value of every variable at each step, to check the algorithm does what you expect (or to find where it goes wrong).

Tracing the example above. At the start, biggest = 7 (the first item).

Loop passnIs n > biggest?biggest after this pass
177 > 7? No7
233 > 7? No7
31212 > 7? Yes12
455 > 12? No12

Output: 12. Correct.

Step 7: Inputs, processes, outputs#

Before writing any algorithm, ask three questions: what goes in (the inputs)? what must happen to them (the processing)? what must come out (the outputs)? For the example: in = a list of numbers; process = compare each to the best so far; out = the biggest.

12. Searching and sorting#

Searching finds an item in a list; sorting puts a list in order. Different algorithms solve the same problem at very different speeds, and the gap grows enormous as lists get long — that is why computer scientists study efficiency.

Check every item, from the start, until you find it or reach the end.

Find 23 in [12, 5, 38, 23, 9]:

  1. Is 12 the one? No.
  2. Is 5? No.
  3. Is 38? No.
  4. Is 23? Yes — found at position 4 (or index 3, if counting from 0 as Python does).
  • Works on any list, sorted or not.
  • Simple to write.
  • Slow on long lists: 1,000,000 items may need 1,000,000 checks.

Only works on a sorted list. Like finding a word in a dictionary: open in the middle, see if your word comes before or after, throw away the wrong half, repeat.

Find 23 in this sorted list of 10 items (positions 0–9):

Position0123456789
Value25812162338567291
  1. Search area is positions 0–9. Middle = (0 + 9) ÷ 2 = 4.5, round down → 4. Value 16. Is 23 bigger? Yes → throw away 0–4. Search area now 5–9.
  2. Middle = (5 + 9) ÷ 2 = 7. Value 56. Is 23 smaller? Yes → throw away 7–9. Search area now 5–6.
  3. Middle = (5 + 6) ÷ 2 = 5.5 → 5. Value 23. Found in 3 checks (linear search would need 6).

If the search area ever becomes empty, the item isn't in the list.

Why it's so fast: each check halves the list. Doubling the list adds just one extra check.

Items in listLinear search, worst caseBinary search, worst case
10104
1,0001,00010
1,000,0001,000,00020

(Because 2¹⁰ = 1,024 and 2²⁰ ≈ 1 million — powers of 2 again.)

Step 3: Bubble sort#

Go along the list comparing neighbours; swap them if they're in the wrong order. One trip along the list is a pass. Repeat passes until a whole pass makes no swaps.

Sort [5, 1, 4, 2, 8] smallest to largest:

Pass 1

  1. 5 and 1: wrong order → swap → [1, 5, 4, 2, 8]
  2. 5 and 4: swap → [1, 4, 5, 2, 8]
  3. 5 and 2: swap → [1, 4, 2, 5, 8]
  4. 5 and 8: fine → [1, 4, 2, 5, 8]. The biggest number has "bubbled" to the end.

Pass 2

  1. 1 and 4: fine.
  2. 4 and 2: swap → [1, 2, 4, 5, 8]
  3. 4 and 5: fine. 5 and 8: fine.

Pass 3

  1. No swaps at all → the list is sorted. Stop.

Easy to understand and code, but very slow on big lists: lots of comparisons.

Step 4: Insertion sort#

Like sorting a hand of cards: take the next card and slide it into the right place among the cards you've already sorted.

Sort [5, 1, 4, 2, 8] (the bar | separates sorted from unsorted):

  1. [5 | 1, 4, 2, 8] — one card is always "sorted".
  2. Take 1, slide it left past 5 → [1, 5 | 4, 2, 8]
  3. Take 4, slide it left past 5, stop at 1 → [1, 4, 5 | 2, 8]
  4. Take 2, slide past 5 and 4, stop at 1 → [1, 2, 4, 5 | 8]
  5. Take 8, already bigger than 5 → [1, 2, 4, 5, 8]. Done.

Faster than bubble sort in practice, and very quick when the list is nearly sorted already.

Step 5: Merge sort#

"Divide and conquer": split the list in half again and again until every piece has one item (a single item is always sorted). Then merge pieces back together in order.

Sort [6, 3, 8, 1, 5, 2, 7, 4]:

  1. Split: [6, 3, 8, 1] and [5, 2, 7, 4]
  2. Split: [6, 3] [8, 1] [5, 2] [7, 4]
  3. Split: [6] [3] [8] [1] [5] [2] [7] [4]
  4. Merge pairs: [3, 6] [1, 8] [2, 5] [4, 7]
  5. Merge pairs: [1, 3, 6, 8] [2, 4, 5, 7]
  6. Merge: [1, 2, 3, 4, 5, 6, 7, 8]

How a merge works (step 6 in detail): only ever compare the front item of each list and take the smaller.

  • Fronts 1 vs 2 → take 1. Then 3 vs 2 → take 2. Then 3 vs 4 → take 3. Then 6 vs 4 → take 4.
  • 6 vs 5 → take 5. 6 vs 7 → take 6. 8 vs 7 → take 7. Only 8 left → take 8.

Much faster on large lists, but uses extra memory to hold all the pieces, and is harder to code.

Step 6: Comparing them#

AlgorithmNeeds sorted list?Speed on big listsMemoryEasy to code?
Linear searchNoSlowVery littleVery
Binary searchYesVery fastVery littleFairly
Bubble sort—Very slowVery littleVery
Insertion sort—Slow (fast if nearly sorted)Very littleFairly
Merge sort—FastExtra memory neededHarder

The lesson: there is rarely one "best" algorithm — only the best one for this data and this situation.

13. Programming basics: variables, types, decisions and loops#

A program stores information in variables, works on it with operators, and controls the order of steps with sequence, selection and iteration. Examples use Python, the language of the Y8–9 units; the Scratch equivalent is given where it helps.

Step 1: A program runs top to bottom#

python
print("Hello")
print("Welcome to Computing")

The computer runs line 1, then line 2. That's sequence. print(...) shows whatever is inside the brackets on the screen. Text in quote marks is shown exactly as typed.

Step 2: Variables — labelled boxes#

A variable is a named place in memory (RAM) that holds a value. Picture a box with a label on it.

python
score = 0
score = score + 10
print(score)
  1. score = 0 → make a box called score and put 0 in it. This is assignment.
  2. score = score + 10 → read the right side first: take what's in score (0), add 10, get 10. Then put 10 back in the box. The old 0 is gone.
  3. print(score) → shows 10.

The = sign in programming does not mean "equals" as in maths. It means "store the right side in the left side". (That's why pseudocode uses the arrow ←.) To ask whether two things are equal, use == (Step 6).

Naming rules in Python: no spaces (use high_score), can't start with a digit, case matters (Score and score are different boxes). Choose names that say what they hold.

Scratch equivalent: the orange "set score to 0" and "change score by 10" blocks.

Step 3: Data types — what kind of value#

The computer must know what kind of data is in a box, because it stores and handles each kind differently (Sections 3 and 4).

TypeHoldsPython examplesPython name
IntegerWhole numbers7, -3, 0int
Real / floatNumbers with a decimal point3.14, 0.5, -2.0float
StringText — any characters in quotes"Hello", "7", ""str
BooleanTrue or false onlyTrue, Falsebool
CharacterA single character"A" (Python treats it as a 1-letter string)—

The classic trap: "7" (in quotes) is a string, the character 7, not the number. So:

python
print(7 + 7)        # 14   — adding numbers
print("7" + "7")    # 77   — joining text (called concatenation)

Anything after # is a comment: a note for humans that the computer ignores.

Step 4: Input and casting#

python
name = input("What is your name? ")
age = int(input("How old are you? "))
print("Hi " + name + ", next year you'll be " + str(age + 1))
  1. input(...) shows the question, waits for the user to type and press Enter, then gives back what they typed — always as a string, even if they typed digits.
  2. int(...) converts ("casts") the string "13" to the integer 13 so we can do maths with it. Without it, age + 1 crashes: you can't add a number to text.
  3. str(age + 1) casts the number 14 back to the string "14" so it can be joined with other text.

Casting functions: int(), float(), str(), bool().

Step 5: Arithmetic operators#

OperatorMeaningExampleResult
+Add7 + 29
-Subtract7 - 25
*Multiply7 * 214
/Divide (always gives a float)7 / 23.5
//Whole-number division (DIV)7 // 23
%Remainder (MOD)7 % 21
**Power2 ** 8256

MOD is surprisingly useful: n % 2 == 0 tests if a number is even. Normal maths order applies (brackets, then powers, then × ÷, then + −).

Step 6: Comparison and Boolean operators#

Comparisons give back a Boolean (True or False):

OperatorMeaning5 ? 3 gives
==Equal to5 == 3 → False
!=Not equal to5 != 3 → True
> / <Greater / less than5 > 3 → True
>= / <=Greater or equal / less or equal5 <= 3 → False

Combine them with and, or, not — exactly the logic gates of Section 9.

Step 7: Selection — making decisions#

python
score = int(input("Score out of 50: "))
if score >= 40:
    print("Gold badge!")
elif score >= 25:
    print("Bronze badge")
else:
    print("Try the Respawn quest")
  1. The computer checks the if condition. If True, it runs the indented line(s) under it and skips the rest of the block.
  2. If False, it checks the elif ("else if").
  3. If nothing was True, it runs the else part.

Order matters: with 45, the first check is True, so it prints "Gold badge!" and never looks at the others. If you put >= 25 first, 45 would wrongly get Bronze.

Indentation (4 spaces) is how Python knows which lines belong inside the if. The colon : at the end of the if line is required. Scratch equivalent: the "if … then … else" C-shaped block — the C-shape is the indentation.

Step 8: Iteration — count-controlled loops (for)#

Use when you know how many times to repeat.

python
for i in range(5):
    print("Lap", i)

Prints Lap 0, Lap 1, Lap 2, Lap 3, Lap 4. range(5) produces 0, 1, 2, 3, 4 — five numbers, starting at 0 and stopping before 5. range(1, 6) gives 1 to 5. i is a variable that changes each time round.

Scratch equivalent: "repeat 5".

Step 9: Iteration — condition-controlled loops (while)#

Use when you don't know how many times — repeat while something is true.

python
password = ""
while password != "dragon":
    password = input("Password: ")
print("Access granted")
  1. Check the condition: is password not "dragon"? It's empty, so True → run the loop body.
  2. Ask for the password. Go back to step 1 and check again.
  3. As soon as the user types "dragon", the condition becomes False → leave the loop → print "Access granted".

Danger: if the condition can never become False, the loop runs forever (an infinite loop). Scratch equivalent: "repeat until" (note: Scratch's version repeats until true, Python's while true — opposite tests).

Step 10: Putting it together — a guessing game#

python
import random
secret = random.randint(1, 10)   # a random whole number from 1 to 10
guesses = 0
guess = 0
while guess != secret:
    guess = int(input("Guess 1-10: "))
    guesses = guesses + 1
    if guess < secret:
        print("Too low")
    elif guess > secret:
        print("Too high")
print("Got it in", guesses, "guesses")

This uses all three building blocks: sequence (top to bottom), selection (if/elif), iteration (while). import random loads a ready-made library of random-number tools.

Step 11: Scratch → Python at a glance#

Scratch blockPython
when green flag clicked(the program just starts at line 1)
say [Hello]print("Hello")
ask [Name?] and wait / answername = input("Name? ")
set [score] to 0score = 0
change [score] by 1score = score + 1
if … then … elseif …: / else:
repeat 10for i in range(10):
repeat until …while not …:
foreverwhile True:
pick random 1 to 10random.randint(1, 10)
join [a] [b]"a" + "b"

14. Programming further: lists, strings, subroutines, errors and testing#

Real programs group data into lists, take text apart as strings, split work into named subroutines, and are tested on purpose to find mistakes before users do.

Step 1: Lists — one name, many values#

Imagine storing 30 students' scores in 30 variables. A list (called an array in many languages and in exam pseudocode) stores them all under one name, in order.

python
scores = [12, 45, 33, 50]

Each item has a position number called an index, and counting starts at 0:

Index0123
Value12453350

Why start at 0? The index really means "how many steps from the start". The first item is 0 steps from the start.

CodeWhat it doesResult
scores[0]Get the first item12
scores[3]Get the fourth item50
scores[-1]Get the last item50
scores[1] = 40Replace the second item[12, 40, 33, 50]
scores.append(28)Add to the end[12, 40, 33, 50, 28]
len(scores)How many items5
scores[10]Index that doesn't existError: IndexError

Looping over a list, e.g. to add up the total:

python
total = 0
for s in scores:
    total = total + s
print(total / len(scores))   # the average

2D lists (lists of lists) store grids: a game board, a seating plan, a spreadsheet. board[2][0] = row 2, column 0.

Step 2: Strings — text you can take apart#

A string is really a list of characters, so it has indexes too.

python
word = "Computing"
CodeResultWhy
len(word)99 characters
word[0]"C"First character
word[0:3]"Com"Slice: from index 0 up to (not including) 3
word.upper()"COMPUTING"All capitals
word.lower()"computing"All lower case
"put" in wordTrueIs it inside?
word + "!""Computing!"Concatenation (joining)

Use: checking a password has at least 8 characters (len), making answers case-insensitive (.lower() before comparing), building usernames from initials (slicing).

Step 3: Subroutines — naming a chunk of code#

A subroutine is a named block of code you can run ("call") whenever you need it, instead of copying it out again. In Scratch these are the pink "My Blocks".

python
def greet(name):
    print("Hello, " + name + "!")

greet("Ana")
greet("Leo")
  1. def defines the subroutine. Nothing runs yet — you're only teaching Python the new word.
  2. name is a parameter: a placeholder for a value the subroutine will be given.
  3. greet("Ana") calls it. The value "Ana" (an argument) goes into name, and the indented code runs: Hello, Ana!
  4. Call it again with a different argument and the same code does the job for Leo.

Two kinds:

  • Procedure — does something, gives nothing back (like greet).
  • Function — works something out and returns a value to wherever it was called.
python
def area(width, height):
    return width * height

room = area(4, 3)    # room now holds 12

Why bother:

  • No repetition — write once, use many times.
  • Easier to fix — a bug fixed in one place is fixed everywhere.
  • Decomposition in code — each subroutine is one small, testable problem (Section 11).
  • Teamwork — different people can write different subroutines.

Scope: a variable created inside a subroutine is local — it exists only while that subroutine runs and can't be seen outside. A variable created in the main program is global. Using local variables avoids subroutines accidentally changing each other's data.

Step 4: Files — keeping data after the program stops#

Variables live in RAM, so they vanish when the program ends (Section 8). To keep data — a high-score table, saved settings — write it to a file in storage.

python
file = open("scores.txt", "a")   # "a" = append (add to the end)
file.write("Ana,45\n")           # \n = new line
file.close()

file = open("scores.txt", "r")   # "r" = read
for line in file:
    print(line)
file.close()

Modes: "r" read, "w" write (wipes the file first!), "a" append.

Step 5: The three kinds of error#

ErrorWhat it isExampleDoes it run?
Syntax errorBreaks the grammar rules of the languageprint("Hi" (missing bracket), if x > 3 (missing colon)No — the translator refuses
Runtime errorThe code is valid but something impossible happens while runningDividing by zero; int("cat"); scores[10] on a 5-item listStarts, then crashes
Logic errorRuns perfectly but gives the wrong answerUsing > instead of >=; average = total / 4 when there are 5 itemsYes — the hardest to spot

How to find logic errors: trace tables (Section 11), adding print lines to show variables, and the debugger (Section 10).

Step 6: Testing — trying to break your own program#

Test with three kinds of data. Suppose a program accepts a test score from 0 to 50:

Test typeMeaningExamplesExpected result
NormalSensible, typical data23, 38Accepted
Boundary (extreme)At the very edges of what's allowed0, 50 (and just outside: −1, 51)0 and 50 accepted; −1 and 51 rejected
Erroneous (invalid)Wrong type or nonsense"hello", 3.7, blankRejected with a helpful message

A test plan is a table written before testing: test number, what's being tested, the data, the expected result — then a column for the actual result and whether it passed.

Step 7: Defensive design — expecting users to do the unexpected#

Users type wrong things, by accident or on purpose. Validation checks input is sensible before using it:

CheckAsksExample
PresenceWas anything entered?Name can't be blank
TypeIs it the right type?Age must be a whole number
RangeIs it between limits?Score from 0 to 50
LengthIs it the right length?Password at least 8 characters
FormatDoes it match a pattern?Postcode like SW1A 1AA; date as DD/MM/YYYY
python
score = int(input("Score (0-50): "))
while score < 0 or score > 50:
    score = int(input("Must be 0-50. Try again: "))

Validation checks data is reasonable, not that it is true — a valid date of birth can still be the wrong one.

Other defensive habits:

  • Authentication — confirm who the user is (passwords, two-factor).
  • Maintainability — meaningful variable names, comments, consistent indentation and subroutines, so you (or someone else) can understand the code in six months.

15. Networks and the internet#

A network is two or more computers connected so they can share data. The internet is a worldwide network of networks; data crosses it chopped into small packets, each labelled with addresses and handled by agreed rules called protocols.

Step 1: Why connect computers?#

  • Share files and information.
  • Share hardware (one printer for a whole office).
  • Share an internet connection.
  • Communicate (email, messages, video calls, online games).
  • Central control: one person can back up and secure everyone's files.

The costs: hardware and setup, and a single fault or virus can spread to everyone.

Step 2: LAN and WAN#

LAN — Local Area NetworkWAN — Wide Area Network
CoversOne small area: a home, school, officeA large area: cities, countries, the world
Owned byUsually whoever uses itOften rented from telecoms companies
ExampleThe school networkA bank linking branches; the internet is the biggest WAN

Step 3: The hardware#

  • NIC (Network Interface Card) — the part inside every device that connects it to a network. Every NIC has a unique MAC address burned in at the factory.
  • Switch — the hub of a wired LAN. It receives data and sends it only to the device it's meant for (it learns which MAC address is on which socket).
  • Router — connects different networks together, e.g. your home LAN to the internet. It reads IP addresses and decides where to send each packet next.
  • WAP (Wireless Access Point) — lets devices join the network by Wi-Fi (radio waves). A home "router" box is really a router, switch and WAP in one.
  • Transmission media — what carries the bits: copper Ethernet cable (electrical pulses), fibre-optic cable (pulses of light — very fast, long distances), or wireless (radio).

Wired vs wireless: wired is faster, more reliable and harder to snoop on; wireless is convenient and needs no cables, but signals weaken through walls and can be intercepted.

Step 4: Topologies — how devices are arranged#

  • Star: every device has its own cable to a central switch. If one cable fails, only that device drops out. Most LANs today. Weakness: if the switch fails, everything fails.
  • Mesh: devices connect to many others, so data has several routes. If one link fails, data goes another way. Expensive with cables, but common for Wi-Fi mesh systems and the internet itself.

Step 5: Addresses — how data knows where to go#

Like posting a letter, data needs an address.

IP address — the address of a device on a network, which can change (like a postal address when you move house).

  • IPv4 looks like 192.168.1.25: four numbers separated by dots.
  • Why does each number stop at 255? Each one is one byte (8 bits), and 8 bits hold 0–255 (Section 2). Four bytes = 32 bits.
  • 32 bits give 2³² ≈ 4.3 billion addresses — not enough for every device on Earth. So IPv6 uses 128 bits, written in hex: e.g. 2001:0db8:85a3::8a2e:0370:7334. That's 2¹²⁸ addresses — more than enough forever.

MAC address — the fixed, unique ID of the network card itself (like your name, which stays the same wherever you live). 48 bits, written as 12 hex digits: 3C:22:FB:7A:1E:90.

Step 6: Packets — why data is chopped up#

A 5 MB photo isn't sent as one lump. It's split into thousands of small packets. Each packet has:

  • a header: sender's IP address, destination IP address, and a sequence number ("packet 37 of 4,000");
  • the payload: its slice of the actual data;
  • a trailer with a check value, so errors can be detected.

Packet switching, step by step:

  1. The sending computer splits the file into numbered packets.
  2. Each packet is sent into the network separately.
  3. Routers read each packet's destination and send it along whatever route is least busy right now. Packets from one file may travel completely different routes.
  4. Packets arrive at different times and out of order.
  5. The receiving computer uses the sequence numbers to put them back in order.
  6. If a packet is missing or damaged, the receiver asks for it again.

Why do it this way? Many people can share the same cables at once; a broken link just means packets take another route; and a lost packet only needs a small resend, not the whole file.

Step 7: Protocols — the agreed rules#

A protocol is a set of rules for how devices communicate — like agreeing to speak the same language and take turns. Important ones:

ProtocolJob
TCPSplits data into packets, numbers them, checks they all arrived, reorders them
IPAddresses packets and routes them across networks
HTTPFetches web pages from web servers
HTTPSHTTP, but encrypted — the padlock in the browser
DNSTurns website names into IP addresses (next step)
SMTPSends email
IMAP / POPCollects email from the server (IMAP keeps it synced on the server; POP downloads it)
FTPTransfers files between computers

Protocols are organised in layers, each doing one job and handing over to the next (the application layer, then transport/TCP, then internet/IP, then the physical link). Each layer can be changed without rewriting the others — Wi-Fi or cable, the web page doesn't care.

Step 8: DNS — the internet's phone book#

Computers find each other by IP address, but people remember names. When you type www.bbc.co.uk:

  1. Your browser asks a DNS server: "What's the IP address for www.bbc.co.uk?"
  2. If that server doesn't know, it asks other DNS servers up a chain until one does.
  3. The IP address comes back to your computer (and is remembered for a while, to be quicker next time).
  4. Your browser now contacts that IP address directly to request the page.

Step 9: The internet is not the web#

  • The internet = the physical network: cables, routers, satellites, all connected.
  • The World Wide Web = one service that runs on the internet: web pages linked together, viewed in a browser. Email, online gaming and video calls also use the internet but aren't the web.

Step 10: Speed — bandwidth and latency#

  • Bandwidth — how much data can pass per second (Mbps). Like how many lanes a motorway has.
  • Latency — how long one piece of data takes to arrive (milliseconds). Like the travel time. Matters most for games and video calls ("lag").

Things that slow a network: many users at once, interference on Wi-Fi, distance, and the type of cable.

Step 11: Client–server vs peer-to-peer#

  • Client–server: one powerful central computer (the server) provides files, websites or games; other devices (clients) request them. Easier to secure and back up; if the server fails, everyone stops.
  • Peer-to-peer (P2P): every computer is equal and shares directly with the others. Cheap and no single point of failure, but harder to manage and secure.

16. The web: URLs, HTML and CSS#

A web page is a text file written in HTML (what's on the page), styled by CSS (how it looks), sometimes with JavaScript (what it does). Your browser requests these files from a web server using a URL, then draws them on your screen.

Step 1: Reading a URL#

A URL (Uniform Resource Locator) is the full address of one thing on the web.

https://www.bbc.co.uk/news/technology?page=2

PartExampleMeaning
Protocolhttps://Which rules to use (Section 15). The s means encrypted
Domain namewww.bbc.co.ukWhich server — turned into an IP address by DNS
Top-level domain.co.ukThe last part: country or type (.uk, .es, .com, .org)
Path/news/technologyWhich page or file on that server, like folders
Query?page=2Extra information sent to the page

Step 2: What happens when you press Enter#

  1. The browser reads the URL and asks DNS for the IP address of www.bbc.co.uk.
  2. It connects to that IP address (the web server) and sends an HTTPS request: "please send /news/technology".
  3. The server finds or builds the page and sends back a response: a status code (200 = OK, 404 = Not Found) plus the HTML file.
  4. The browser reads the HTML and notices it also needs CSS files, images and scripts. It requests each of those too.
  5. The browser renders (draws) the page: HTML for the content, CSS for the layout and colours, JavaScript for anything interactive.

All of this usually takes under a second.

Step 3: HTML — the content and structure#

HTML (HyperText Markup Language) isn't a programming language; it's a markup language. It labels pieces of content so the browser knows what each is. Labels are tags in angle brackets, usually in pairs: an opening <p> and a closing </p> (note the slash). Tag + content + closing tag = an element.

html
<!DOCTYPE html>
<html>
  <head>
    <title>My Game Page</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <h1>Hot Potato</h1>
    <p>A party game for <strong>four</strong> players.</p>
    <img src="potato.png" alt="A cartoon potato">
    <a href="https://example.com">Visit the site</a>
    <ul>
      <li>Fast rounds</li>
      <li>Silly physics</li>
    </ul>
  </body>
</html>

Reading it step by step:

  1. <!DOCTYPE html> tells the browser "this is a modern HTML page".
  2. <html> wraps the whole page.
  3. <head> holds information about the page that isn't shown in it: the <title> (the text on the browser tab) and a link to the CSS file.
  4. <body> holds everything you actually see.
  5. <h1> is the biggest heading (there are <h1> to <h6>). <p> is a paragraph. <strong> makes text important (bold).
  6. <img> shows an image; src says which file, alt describes it for blind users and if the image fails. It has no closing tag.
  7. <a> is a link ("anchor"); href is where it goes. Links are the "hyper" in hypertext — they're what make it a web.
  8. <ul> is a bullet list; each <li> is one item.

The words inside the tag like src="potato.png" are attributes: extra settings for that element. Indenting nested elements is optional but makes the structure readable.

Step 4: CSS — the appearance#

CSS (Cascading Style Sheets) says how elements look. Keeping it in a separate file means one change restyles every page on a site.

css
body {
  background-color: #FFF8E7;
  font-family: Arial, sans-serif;
}

h1 {
  color: #C0392B;
  text-align: center;
}

.highlight {
  background-color: yellow;
}

Each rule has three parts:

  1. A selector — which elements: h1 means every <h1>; .highlight means every element with class="highlight".
  2. A property — what to change: color, font-size, margin.
  3. A value — what to change it to: #C0392B, 24px, center.

Colours are written in hex RGB (Section 5): #C0392B = red C0 (192), green 39 (57), blue 2B (43) — a brick red. "Cascading" means rules can stack, and the more specific rule wins.

Step 5: JavaScript — the behaviour#

JavaScript is a real programming language that runs inside the browser: it responds to clicks, checks forms before sending them (validation, Section 14), and changes the page without reloading it. Everything from Section 13 — variables, if, loops — exists in JavaScript with slightly different spelling.

Step 6: How search engines work#

  1. Crawl — programs called crawlers (spiders) follow links from page to page across the web, downloading what they find.
  2. Index — the words on every page are recorded in a giant index: for each word, which pages contain it.
  3. Rank — when you search, the engine finds matching pages in the index and orders them by how relevant and trustworthy they seem (how many other sites link to them, how well they match your words, how recent they are, and much more).

You're not searching the live web when you search — you're searching the engine's index of it.

17. Cybersecurity#

Cybersecurity protects computers, networks and data from damage, theft and misuse. Most attacks exploit either people (tricking them) or weak systems (unpatched software, poor passwords), so defences target both.

Step 1: What we're protecting — the CIA triad#

LetterStands forMeansBroken when…
CConfidentialityOnly the right people can see the dataYour messages are leaked
IIntegrityData hasn't been changed without permissionSomeone alters your grades
AAvailabilityData and systems work when neededA website is knocked offline

Every attack below breaks at least one of these.

Step 2: Malware — harmful software#

Malware = *mal*icious soft*ware*. The main kinds:

TypeHow it spreads or worksAnalogy
VirusAttaches to a file; spreads when a person opens or shares that fileA cold you catch by touching something
WormCopies itself across networks on its own, no human action neededA cold that walks door to door
TrojanPretends to be something useful (a free game, a "cracked" app) so you install itThe Trojan horse
RansomwareEncrypts your files and demands payment for the keyA kidnapper
Spyware / keyloggerSecretly watches you and records what you type, e.g. passwordsSomeone reading over your shoulder

Step 3: Social engineering — hacking people#

It's often easier to trick a person than to break a system.

  • Phishing — fake emails or messages that look official ("Your account is locked, click here") and lead to a fake login page. Signs: urgency, threats, spelling mistakes, a sender address or link that doesn't quite match the real company, requests for passwords (real companies never ask).
  • Blagging (pretexting) — inventing a believable story to get information: "Hi, I'm from IT, I need your password to fix your account."
  • Shoulder surfing — watching someone type a PIN or password.
  • Baiting — leaving an infected USB stick labelled "Salaries 2026" where someone curious will plug it in.

Defence: training people to be suspicious, and a rule that nobody ever asks for passwords.

Step 4: Technical attacks#

  • Brute force — a program tries every possible password until one works.
  • Denial of Service (DoS) — flooding a server with so many fake requests it can't serve real users. DDoS (distributed) uses thousands of hijacked computers at once.
  • Data interception — reading data as it travels across a network, especially unencrypted public Wi-Fi.
  • SQL injection — typing database commands into a website's form box instead of normal text. If the website doesn't validate input (Section 14), the database may run those commands and reveal or delete data.

Step 5: Why password length matters — the maths#

Number of possible passwords = (number of possible characters) multiplied by itself (length) times. Same idea as 2ⁿ for bits, but with more symbols per position:

Password typeCalculationPossibilities
4-digit PIN10⁴10,000
8 lower-case letters26⁸about 209 billion
8 characters, any keyboard symbol (94 options)94⁸about 6 quadrillion
12 lower-case letters26¹²about 95 quadrillion

A computer guessing a billion passwords a second cracks the PIN instantly and the 8-letter one in minutes. Adding length grows the number far faster than adding symbol types — so a long passphrase ("purple-violin-tuesday-rain") beats a short messy one.

Step 6: Defences#

  • Strong passwords + two-factor authentication (2FA) — something you know (password) plus something you have (a code on your phone). A stolen password alone isn't enough.
  • Lock-outs — after 3–5 wrong tries, block further attempts. Kills brute force.
  • Firewall — software or hardware that checks all traffic going in and out of a network and blocks anything not allowed by its rules.
  • Anti-malware — scans files and downloads for known malware and suspicious behaviour.
  • Updates (patches) — fix security holes the moment they're discovered. Many big attacks used holes that already had a fix nobody had installed.
  • Encryption — scrambles data so stolen or intercepted data is useless (next step).
  • Backups — if ransomware strikes, restore from a backup instead of paying.
  • User access levels — each person can only reach the files they need (a student can't edit the grade database).
  • Input validation — stops SQL injection.
  • Penetration testing — hiring ethical hackers to attack your system with permission and report the weaknesses.
  • Physical security — locked server rooms, CCTV, swipe cards.

Step 7: Encryption basics#

Encryption turns readable data (plaintext) into scrambled data (ciphertext) using a key. Only someone with the right key can turn it back (decrypt it).

The oldest example, the Caesar cipher: shift every letter a fixed number of places along the alphabet. Key = 3:

  1. H → I, J, K
  2. E → F, G, H
  3. L → O
  4. L → O
  5. O → R

HELLO becomes KHOOR. To decrypt, shift back 3. It's easy to break — there are only 25 possible shifts, so try them all — but it shows the idea of a key.

Modern encryption uses keys hundreds of bits long, so trying every key would take longer than the age of the universe (2²⁵⁶ possibilities — that power of 2 again). It protects HTTPS web pages, WhatsApp messages and your phone's storage.

Two kinds (for interest): symmetric — the same key locks and unlocks (fast, but you have to share the key safely); public-key — anyone can lock with your public key, only your private key unlocks. HTTPS uses public-key to agree a shared key, then symmetric for speed.

18. Data, spreadsheets, databases and AI#

Data is raw facts; information is data given meaning. Spreadsheets calculate with data, databases store and search huge amounts of it, and AI systems learn patterns from it.

Step 1: Data vs information#

  • Data: 38, 41, 37, 39. Just numbers — meaningless alone.
  • Information: "Patient's temperature, in °C, over four hours — the 41 is dangerously high." Now it means something and you can act on it.

Computers store data; people (and programs) turn it into information by adding context.

Step 2: Spreadsheets — the grid#

A spreadsheet (Excel, Google Sheets) is a grid of cells. Columns are letters, rows are numbers, so every cell has an address — a cell reference — like B3 (column B, row 3). A cell holds text, a number, or a formula.

Step 3: Formulas and functions#

A formula always starts with =. It calculates from other cells and updates automatically when they change — that's the whole power of a spreadsheet.

FormulaDoesEnglish ExcelSpanish Excel
=B2+C2Adds two cellssamesame
=SUM(B2:B10)Adds every cell from B2 to B10 (the colon means "to")SUMSUMA
=AVERAGE(B2:B10)MeanAVERAGEPROMEDIO
=MAX(B2:B10) / =MIN(…)Biggest / smallestMAX / MINMAX / MIN
=COUNTIF(B2:B10,">=25")How many cells meet a conditionCOUNTIFCONTAR.SI
=IF(B2>=25,"Pass","Retry")Selection — like an if/else (Section 13)IFSI

With Spanish settings, commas between arguments become semicolons: =SI(B2>=25;"Aprobado";"Repetir"), because Spain uses the comma as its decimal point.

Step 4: Copying formulas — relative and absolute references#

  1. Type =B2*C2 in D2 and drag it down to D3.
  2. The spreadsheet automatically changes it to =B3*C3. This is a relative reference: "the cells in the same row as me". Usually exactly what you want.
  3. But suppose every row should be multiplied by a VAT rate stored once in F1. Dragging =B2*F1 down gives =B3*F2 — wrong, F2 is empty.
  4. Fix: write =B2*$F$1. The $ signs lock the column and row. This is an absolute reference: it always points to F1.

Step 5: Charts — choosing the right one#

ChartUse it forExample
Bar / columnComparing separate categoriesVotes per school club
LineChange over timeTemperature each hour
PieParts of one whole (few slices)How you spend 24 hours
ScatterIs there a link between two measurements?Hours of revision vs test score

A good chart has a title, labelled axes with units, and a sensible scale starting at 0 for bars.

Step 6: Databases#

When data gets large (a school's every student, every lesson, every grade), it goes in a database. Data is stored in tables:

StudentIDFirstNameYearHouse
1001Ana8Blue
1002Leo9Red
1003Sara8Red
  • Field = one column (one kind of fact: FirstName).
  • Record = one row (everything about one thing: Leo).
  • Primary key = a field whose value is unique for every record (StudentID). Two students can share a name; never an ID.

SQL (Structured Query Language) asks a database questions:

sql
SELECT FirstName, House
FROM Students
WHERE Year = 8
ORDER BY FirstName;

Read it as English: select these fields, from this table, where this condition is true, ordered by this field. Result: Ana – Blue, Sara – Red.

Why not just use a spreadsheet? Databases handle millions of records, let many people use them at once safely, and link tables together (a Grades table can refer to StudentID instead of copying names everywhere).

Step 7: The data science cycle#

  1. Ask a question ("Do students who sleep more score better?").
  2. Collect data (a survey, sensors, existing records).
  3. Clean it — remove duplicates, fix typos, decide what to do with blanks and impossible values (a student who "sleeps 40 hours").
  4. Analyse — calculate averages, sort, filter, make charts.
  5. Present and conclude — and be honest about limits: a link (correlation) doesn't prove one thing causes the other.

Big data means data sets so large, fast-arriving or messy (every card payment in Spain, every video watched on YouTube) that normal tools can't handle them.

Step 8: AI and machine learning#

Traditional programming: a human writes the rules. "If an email contains 'WIN A PRIZE', mark it as spam."

Machine learning: instead of writing rules, you give the computer thousands of examples with the right answers (emails already labelled spam or not spam). It finds the patterns itself and builds its own rules — a model. Then it can label new emails it has never seen.

  1. Collect training data — labelled examples.
  2. Train — the computer adjusts its model until its guesses on the examples are mostly right.
  3. Test — check it on examples it didn't train on.
  4. Use it on real, new data.

The big catch is bias: a model learns whatever is in its examples, including unfairness. Train a face-recognition system mostly on light-skinned faces and it will be worse at recognising dark-skinned ones. Rubbish or unfair data in → rubbish or unfair decisions out.

Tools like chatbots (including the one writing this guide) are machine-learning models trained on enormous amounts of text. They predict likely next words — which makes them very useful, but also able to state wrong things confidently, so their answers should be checked.

19. Digital citizenship, law and ethics#

Using technology well means protecting yourself and others online, knowing the laws that govern computers and data, and thinking about who technology helps and who it harms.

Step 1: Your digital footprint#

Everything you post, like, search or share leaves a trace — your digital footprint. Screenshots and copies mean deleting something rarely removes it everywhere. Universities and employers do look.

  • Before posting, ask: would I be fine with a teacher, parent or future employer seeing this?
  • Keep private: home address, school, phone number, passwords, daily routine, live location.
  • Remember photo metadata (Section 5): a picture can reveal exactly where it was taken.
  • Set accounts to private and check privacy settings after app updates.

Step 2: Staying safe with people online#

  • People online may not be who they say they are.
  • Never share personal details or images with someone you only know online, and never meet them alone.
  • If anything makes you uncomfortable: stop, block, report in the app, keep evidence (screenshots), and tell a trusted adult.

Cyberbullying is bullying through technology: hurtful messages, sharing embarrassing images, excluding someone from group chats, impersonation. It follows people home, 24 hours a day. The same steps apply — don't reply, keep evidence, block, report, tell someone.

Step 3: Judging information#

Anyone can publish anything. Before believing or sharing:

  1. Who made it? Are they an expert, a news organisation, a stranger, someone selling something?
  2. When? Old news shared as new is common.
  3. Can you find it elsewhere, from independent reliable sources?
  4. Why was it made — to inform, to sell, to make you angry?
  5. Be extra careful with images and videos: they can be edited or generated by AI.

Step 4: UK computing law#

The school follows the English curriculum, so these are the laws in the exam:

Computer Misuse Act 1990 — makes hacking a crime. Three main offences:

  1. Unauthorised access to computer material — e.g. logging in with someone else's password, even "just to look".
  2. Unauthorised access with intent to commit a further crime — e.g. getting in to steal money or blackmail someone.
  3. Unauthorised acts that impair a computer — e.g. creating or spreading malware, a DoS attack, deleting files.

Data Protection Act 2018 and UK GDPR — control how organisations handle personal data (anything that identifies a living person). Organisations must:

  • use data lawfully, fairly and openly (tell people what they're collecting and why);
  • only use it for the stated purpose;
  • collect only what they need;
  • keep it accurate and up to date;
  • not keep it longer than necessary;
  • keep it secure.

People have rights: to see the data held about them, to have mistakes corrected, and in many cases to have it deleted. The UK updated these rules with the Data (Use and Access) Act 2025, which received Royal Assent on 19 June 2025 and amends rather than replaces UK GDPR and the 2018 Act; the core principles above stay the same.

Copyright, Designs and Patents Act 1988 — protects original creative work (music, images, films, books, software, game assets) automatically, without registering. Copying, sharing or selling it without permission is illegal. Copyright usually lasts the creator's lifetime plus 70 years.

Step 5: The Spanish equivalents#

AreaUKSpain
HackingComputer Misuse Act 1990Código Penal (e.g. art. 197 bis on unauthorised access; art. 264 on damaging data and systems)
Personal dataUK GDPR + Data Protection Act 2018EU GDPR + Ley Orgánica 3/2018 (LOPDGDD)
CopyrightCDPA 1988Ley de Propiedad Intelectual

The ideas are the same across both countries; the names and numbers differ.

Step 6: Licences — when you can use other people's work#

  • Proprietary software — you buy a licence to use it, but can't see or change the code (Microsoft Office, most games).
  • Open-source software — the code is published; you may use, study, change and share it, under the licence's conditions (Linux, Firefox, Python itself).
  • Creative Commons — creators choose to let others reuse images, music and text, with conditions such as "credit me" or "non-commercial only". Great for school projects: always credit.

Step 7: Ethical and environmental questions#

Laws say what's allowed; ethics asks what's right. Questions to debate:

  • Privacy vs safety — should governments read messages to catch criminals?
  • Automation and jobs — robots and AI replace some jobs and create others. Who benefits?
  • The digital divide — people without devices, internet or skills fall further behind (older people, poorer families, rural areas).
  • AI bias — automated decisions about loans, jobs or policing can be unfair (Section 18).
  • Environment — data centres use huge amounts of electricity and water; making devices uses rare metals; old devices become toxic e-waste. Positive side: video calls replace travel; smart systems save energy.
  • Wellbeing — apps are designed to keep you scrolling. Notice how much time you spend and how it makes you feel.

Glossary A–Z#

Every key term in this guide, in one line, with the section that explains it.

TermMeaning§
AbstractionIgnoring detail that doesn't matter for the problem11
AlgorithmPrecise, ordered, finite steps to solve a problem11
ALUPart of the CPU that does arithmetic and logic8
AnalogueSmooth and continuous, with infinitely fine values6
AND / OR / NOTBasic logic gates: both / at least one / flip9
Array / listOne name holding many values in order, indexed from 014
ASCII7-bit character set: 128 characters, A = 654
AssignmentStoring a value in a variable (= in Python, ← in pseudocode)13
BandwidthAmount of data a connection can carry per second15
BinaryBase 2: only digits 0 and 13
Binary searchHalve a sorted list each step until the item is found12
BitOne binary digit, 0 or 1; one switch2
Bit depth (sound)Bits per sample; sets how precisely each is measured6
BooleanA value that is only True or False9, 13
Boundary dataTest data at the very edge of what's allowed14
Brute forceTrying every possible password17
Bubble sortSwap neighbours repeatedly until a pass makes no swaps12
Byte8 bits; 256 possible patterns2
CacheSmall, very fast memory on the CPU chip8
CastingConverting a value from one data type to another13
Character setAgreed list of characters and the number for each4
CIA triadConfidentiality, Integrity, Availability17
Clock speedCPU cycles per second, in GHz8
Colour depthBits per pixel; sets how many colours are possible5
CompilerTranslates a whole program into machine code before running10
CompressionMaking files smaller — lossy or lossless7
ConcatenationJoining strings together13
CoreOne complete processing unit inside a CPU8
CPUCentral Processing Unit — the processor8
CSSLanguage that styles how web pages look16
DatabaseOrganised store of records in tables18
DecompositionBreaking a problem into smaller ones11
DenaryBase 10, our everyday number system3
DigitalMade of separate, countable steps6
DNSService that turns domain names into IP addresses15
DriverSmall program letting the OS talk to a device10
Embedded systemSmall computer built into a device for one job8
EncryptionScrambling data so only key-holders can read it17
Erroneous dataInvalid test data that should be rejected14
Fetch–decode–executeThe loop the CPU repeats to run every instruction8
Field / recordA column / a row in a database table18
FirewallChecks network traffic and blocks what isn't allowed17
FunctionSubroutine that returns a value14
HexadecimalBase 16 (0–9, A–F); one digit = 4 bits3
HTMLMarkup language for the content of web pages16
Huffman codingLossless compression giving common characters short codes7
IDEThe program you write and test code in10
IndexPosition of an item in a list, starting at 014
Insertion sortInsert each item into its place in the sorted part12
InterpreterTranslates and runs code one line at a time10
IP addressA device's address on a network (IPv4 = 4 bytes)15
IterationRepeating steps — a loop11, 13
Kibibyte (KiB)1,024 bytes; a kilobyte (KB) is 1,0002
LAN / WANNetwork over a small area / a wide area15
LatencyDelay for data to arrive15
Linear searchCheck every item in turn12
Logic errorProgram runs but gives the wrong result14
MAC addressFixed unique ID of a network card15
Machine codeBinary instructions the CPU actually runs10
Machine learningComputer finds rules itself from labelled examples18
MalwareMalicious software: virus, worm, trojan, ransomware, spyware17
Merge sortSplit into single items, then merge in order12
MetadataData about data, e.g. an image's width and height5
Nibble4 bits; one hex digit2
Operating systemSystem software that manages hardware and runs programs10
OverflowResult too big for the bits available3
PacketSmall numbered chunk of data sent across a network15
ParameterPlaceholder in a subroutine for a value passed in14
PhishingFake messages that trick people into giving details17
PixelSmallest single-colour dot of an image5
Primary keyField with a unique value for every record18
ProcedureSubroutine that does a job but returns nothing14
ProtocolAgreed rules for communication15
PseudocodeCode-like way to write algorithms, ignoring strict rules11
RAM / ROMVolatile working memory / non-volatile start-up memory8
RegisterTiny storage inside the CPU (PC, MAR, MDR, ACC)8
ResolutionNumber of pixels: width × height5
RLERun-length encoding: store count + value for repeats7
RouterConnects networks and forwards packets15
Sample rateSound samples taken per second, in Hz6
SelectionChoosing a path with if / else11, 13
SequenceSteps run in order11, 13
Shift (binary)Move bits left (× 2) or right (÷ 2)3
SQLLanguage for querying databases18
StringText data: characters in quotes13, 14
SwitchConnects devices in a LAN, sends data to the right one15
Syntax errorCode breaks the language's grammar rules14
Trace tableRecords variable values step by step to check logic11
TransistorElectronic switch with no moving parts1
Truth tableLists every input combination and its output9
UnicodeCharacter set for all the world's writing systems4
URLFull web address of a resource16
ValidationChecking input is reasonable before using it14
VariableNamed place in memory holding a value13
Virtual memoryStorage used as extra RAM when RAM is full8
VolatileLoses its contents when the power is off8
← All artifactsEvery page and document brought in from claude.ai.