What is Run-length Encoding?

Run-length encoding is a lossless compression method that replaces consecutive repeated values with each value and its run length. Its effectiveness depends on how often long runs occur in the source data.

How Run-length Encoding works

An RLE encoder scans symbols in a defined order and emits pairs or tokens describing a value and how many times it repeats. Decoding expands each token deterministically, so no source information is discarded. The scan order matters for images: horizontal rows may yield long runs in flat artwork but short runs after a different traversal or on noisy photographs. RLE is often embedded as one stage inside bitmap, fax, mask, subtitle, or intermediate-data formats rather than used as a universal standalone file type.

Key facts

  1. An encoder needs an escape or token convention to distinguish literal values from run markers; the exact representation is format-specific, not inherent to the RLE idea.
  2. Worst-case expansion occurs when values change frequently because run metadata is added to very short runs; some formats switch to literal blocks to limit that overhead.
  3. Runs must not cross boundaries forbidden by the enclosing format, such as scan lines or tiles, even when the last value of one unit matches the first of the next.

When Run-length Encoding matters

Choose it for masks, simple graphics, or other data containing long sequences of identical pixels. Noisy or highly varied input can make the encoded form as large as, or larger than, the original.

Turn media knowledge into a working pipeline

Connect uploads, processing, AI, storage, and delivery through one declarative API — with the encoding stack, scaling, and format churn handled for you.

Try Transloadit for free