Origins

Run-length encoding

Run-length encoding compresses repeated values by storing the value once with a count.

What it is

Run-length encoding, often shortened to RLE, is one of the simplest compression ideas. If the same value appears many times in a row, do not write it again and again. Write the value and how many times it repeats.

Example

AAAAAABBBBCC
becomes
6A 4B 2C

This is lossless because the original sequence can be reconstructed exactly.

When it works

RLE works well when data contains long repeated runs: simple graphics, flat-color images, masks, subtitles, fax-like documents, or intermediate data produced by another compression step.

When it fails

RLE is poor for noisy or highly varied data. If values change constantly, the counts add overhead instead of saving space.