- Home
- Lessons
- GCSE & IGCSE Computer Science
- Run-length encoding
Run-length encoding
🎬 The doodle video for this lesson is coming soon. Subscribe on YouTube to see it first.
Run-length encoding (RLE) is a simple lossless compression method. It shines when data has long runs of the same value.
How RLE works
A run is a sequence of the same value repeated.
RLE stores each run as a count and the value, instead of every item.
AAAABBBCCD becomes 4A3B2C1D.
RLE stores each run as a count and the value, instead of every item.
AAAABBBCCD becomes 4A3B2C1D.
RLE for images
A row of pixels in a simple black (B) and white (W) image:
WWWWWBBBWW (10 pixels) becomes 5W3B2W.
The image can be rebuilt exactly, so RLE is lossless.
WWWWWBBBWW (10 pixels) becomes 5W3B2W.
The image can be rebuilt exactly, so RLE is lossless.
When it works well
RLE works best with long runs: simple graphics, icons, cartoons and faxes.
With lots of changes, such as photos or ordinary text, it can make files bigger: ABCD becomes 1A1B1C1D.
With lots of changes, such as photos or ordinary text, it can make files bigger: ABCD becomes 1A1B1C1D.
Encode BBBBBBWWWB with RLE.
- 6 Bs, then 3 Ws, then 1 B.
Answer: 6B3W1B
RLE stores each run of repeated data as a count and a value. It is lossless and works well with long runs, but can make data with few repeats bigger.
Check you have got it
Answer 6 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.