GCSE · Computer Science · AQA · Spec 8525
Run-length encoding (RLE)
Read a row of pixels aloud and you say 'five white, three black, two white'. That shortcut is run-length encoding, and it can backfire.
Computer Science · Data compression
Say it out loud: five white, three black, two white
Step along one row of black-and-white pixels (W = white, B = black) and watch the encoder count each run, then write it down as a pair.
Before you reach pixel 6, where the colour changes from W to B: what will the encoder write down at that moment?
1 Read the next pixel2 Same colour as the run we are counting? Add 1 to the run count3 Different colour? Write the finished run out as: frequency, then data4 Start a new run with this pixel (count = 1)5 End of the row? Write out the last run
| Pixel read | Run so far | Pairs written |
|---|---|---|
| 1: W | W x 1 | (none yet) |
Output
Step 1: Pixel 1 is W. There is no run yet, so we start one and count 1.
Press Next to read one pixel at a time. Watch the 'Run so far' column grow, then watch what appears in 'Pairs written' the moment the colour changes.
Predict, then check
Two short pieces of data. Which one will RLE help, and which one might it hurt?
Data 1 is AAAAAABBBB. Data 2 is ABCD. Each is turned into frequency/data pairs. Which prediction is right?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Write down how many, then what, and a long boring row of data shrinks to a few pairs.
What you need to know
- A run is a stretch of the same value repeated one straight after another.
- RLE stores each run as a pair of numbers or symbols: the frequency (how many) first, then the data (what).
- Decoding writes each data value out its frequency number of times, which rebuilds the original data exactly.
- RLE saves space when runs are long, but it can make data bigger when values rarely repeat.
The big picture
Run-length encoding squashes data by replacing each run of identical values with a pair: how many times it repeats (the frequency), then the value itself (the data). Decoding rebuilds the original exactly, so nothing is lost. It saves space when runs are long, and it can make data bigger when nothing repeats.
Key points
Worked example
Problem
Compress the 15 characters KKKKKKQQQQQQQRS using run-length encoding. Then decide whether RLE has saved space by counting the values stored before and after.
⚠ Watch out
Believing compression always makes data smaller. Every run, even a run of one, needs its own frequency, so data with few repeats can grow. Count values, not pairs: one pair is two values.
Memory hook
'How many, then what.' Say it every time you write a pair. And remember ABCD: when nothing repeats, RLE turns 4 values into 8.
Check yourself
A row of 20 pixels is all black. What does RLE store, and what kind of row would stop it helping? (Answer: 20 B, two values for twenty; rows of mostly one- or two-pixel runs.)
Flashcards
(10)What is a 'run' in run-length encoding?
What does a frequency/data pair record?
How do you decode a list of frequency/data pairs?
What does it mean to say RLE is lossless?
When does RLE save the most space?
When can RLE make data bigger?
Why count values, not pairs, when judging an RLE saving?
What happens to a run of 1, a run of 2 and a run of 3 or more?
Does ABABAB shrink under RLE?
What kinds of data can RLE be used on?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 2 October 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.