%3C/text%3E%3C/svg%3E">
💻
💻 Tech & IT

Run-Length Encoding (RLE) Tool

Results update as you type.

Your numbers

Understanding the run-length encoding tool — concept and principle

Run-length encoding (RLE) replaces each run of identical consecutive characters with a count followed by the character. This tool encodes your text and shows the compression ratio. RLE is one of the simplest lossless compression methods and appears in fax transmission, early bitmap formats such as PCX and BMP's RLE modes, and as a stage inside more complex codecs.

Run-length encoding of a row of pixelsWWWWWWBBBWWWW has three runs, stored as 6W3B4W: 13 characters become 6, a ratio of 2.17. Text without runs, like ABAB, doubles in length.Write each run once, with its lengthWWWWWWBBBWWWW13 characters6W3B4W"6W3B4W" = 6 characters13 ÷ 6 = 2.17× smallerNo runs? It grows:ABAB→1A1B1A1B4 → 8 chars
RLE wins on long runs, as in simple black-and-white images, and loses on varied text.

How it is calculated

A ratio above 1 means the output is shorter than the input; below 1 means RLE made it longer. Every run is encoded, including runs of length 1, which become "1x".

The principle

When data contains long stretches of the same value, as in a scanned page that is mostly white or a simple graphic, storing "how many" plus "what" is far shorter than repeating the value. Each run costs a fixed amount (here the digits of the count plus one symbol), so the gain grows with run length. Conversely, text with few repeats, such as normal prose, roughly doubles in size because each single character turns into two.

Worked example

  1. Input: "WWWWWWBBBWWWW", 13 characters.
  2. Runs: 6 × W, 3 × B, 4 × W.
  3. Encoded: 6W3B4W, which is 6 characters.
  4. Ratio: 13 ÷ 6 = 2.166666667.

How to read the result

A ratio of about 2.17 means the encoded text is less than half the original length. Values well above 1 indicate long runs; values near 0.5 indicate almost no repetition. As a rule, RLE in this form only pays off when the average run is longer than two characters.

Common mistakes

Keep in mind: This tool demonstrates the idea on characters and assumes the input has no digits. Real RLE formats work on bytes or pixels, use binary counts and define rules for long runs and literal sequences.

Frequently asked questions

How do you decode RLE?

Read the number, then repeat the next character that many times, and continue to the end. "6W3B4W" gives WWWWWW BBB WWWW.

Is run-length encoding lossless?

Yes, as long as the format is unambiguous, decoding returns exactly the original data.

Where is RLE still used today?

In fax (ITU-T T.4), in some image formats, and as a step in JPEG, where runs of zero coefficients are coded together.

Sources: ITU-T Recommendation T.4, Standardization of Group 3 facsimile terminals · K. Sayood, Introduction to Data Compression, Morgan Kaufmann

Checked 8 Nov 2026. Standard formulas and RFC/IEEE definitions, computed locally in your browser — nothing you type is sent anywhere.

💻 All tech & IT tools →🌍 Calculators by country →