Homeβ€ΊStudy Resourcesβ€ΊComputer Scienceβ€Ί
How does run length encoding (RLE) work?
Computer Science
GCSE

How does run length encoding (RLE) work?

Run length encoding (RLE) is a lossless compression method. It replaces each run of identical data values with a frequency/data pair: how many times the value repeats, followed by the value itself. RLE works best when data contains long runs of the same value, such as simple bitmap images. Example: Compress the bitmap row 1111000000110000 using RLE. Runs: four 1s, six 0s, two 1s, four 0s. Answer: 4 1 6 0 2 1 4 0

AQA GCSE Computer Science (8525) expects you to explain how RLE reduces the amount of data stored and to represent data as frequency/data pairs. Because no data is lost, the original can be rebuilt exactly, so RLE is lossless. It can make files larger if the data has few repeated values.

Worked example

Represent the bitmap row 1111000000110000 using RLE frequency/data pairs.

  1. Split the row into runs of identical bits: 1111 | 000000 | 11 | 0000.
  2. Count each run: 4, 6, 2 and 4 (total 16 bits, matching the original).
  3. Write each run as a frequency/data pair: 4 1, 6 0, 2 1, 4 0.
  4. Check by decoding: 4 ones, 6 zeros, 2 ones, 4 zeros gives the original row.

Answer: 4 1 6 0 2 1 4 0

Want one-to-one help? Find an online Computer Science tutor with ExpertTutor.

Reviewed by

Want one-to-one support?

One-to-one online tuition can help you build confidence in your subject. Find a tutor who teaches your course.

Find a Tutor

Learn face to face in Glasgow

Prefer in-person lessons? Visit the ExpertTutor Glasgow Southside centre.

See the centre