Run-length encoding

Run-length encoding is a method of [[ /lossless compression|lossless compression]] where we replace sequences of repeated data with a single value and a count of how many times it was repeated.

As an example, suppose we had this string of text:

AAAAAAAABBBBBBBCDDDDDDDDDDDDDEEEEEEE

That is:

It would be much better if, instead of storing each individual character, we just stored the character and how many times it was repeated!

While the underlying encoding would be different in reality, run length encoding would essentially turn the string above into something like:

8A 7B 1C 13D 7E

Stored in binary, that’s a lot less data to store than the original string.

Run-length encoding in images

We can do the same with images. For example, if we had a bitmap image that was 10 pixels wide and 10 pixels high, and the top 5 rows were all red and the rest was all blue, we might store that as something like:

50R 50B

Benefits of run-length encoding

Drawbacks of run-length encoding