Run-length encoding

Run-length encoding (RLE) is a simple lossless compression method. It shines when data has long runs of the same value.

Practise this lesson free (6 questions)

More tools

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 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.

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.
Worked example

Encode BBBBBBWWWB with RLE.

  1. 6 Bs, then 3 Ws, then 1 B.

Answer: 6B3W1B

Key idea

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.

Key words
Run-length encoding (RLE)
Lossless compression that stores each run of repeated data as a count and a value.
Lossless compression
Makes a file smaller without losing any data, so the original can be rebuilt exactly.
Compression
Making a file smaller, to save storage space and transmission time.
Sequence
Instructions carried out one after another in order.

All GCSE and International GCSE Computer Science key terms and definitions โ†’

Quick check

Try two quick questions

See if it has sunk in. Answers are marked straight away.

Extra practice

2 more questions

Try each one, then tap to check.

  1. Encode AAABBBBBCD using run-length encoding (count then letter, for example 3A).

    Show the answer

    Answer: 3A5B1C1D

    Count each run: 3A 5B 1C 1D. So 3A5B1C1D.

  2. Encode the pixel row BBBBBWWWWWWW using RLE.

    Show the answer

    Answer: 5B7W

    Count each run: 5B 7W. So 5B7W.

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.

Video for this lesson coming soon. Subscribe on YouTube

Sources and references

Facts checked against the sources below, 17 October 2026. Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.

Related lessons