Productivity and Utilities

Run Length Encoding Tool

Choose encode or decode, then paste your text to see the result and the size ratio.

Up to 200,000 characters. Nothing is uploaded.

Run length coding replaces each run of the same character with the length of the run and the character. WWWWB becomes 4W1B with the count first, or W4B1 with the character first. It saves space when the text has long runs, such as simple images or padded fields, and makes text longer when runs are short. Because the counts are digits, text that contains digits cannot be encoded without confusion, so the tool asks for text without digits. Decoding reads each count and character pair and rejects text that does not follow the format. Counts above 1,000,000 are rejected. Nothing is uploaded from this page.

Next step

How to use the run length encoding tool

  1. Paste the text to encode, or the coded text to decode.
  2. Choose Encode or Decode.
  3. Choose whether the count comes before the character or after it.
  4. Copy the result or download it as a text file.

Formula

Encode: replace each run of the same character with its length and the character

Decode: repeat each character as many times as its count says

Count first: 4W. Character first: W4

The size drops only when runs are long. Single characters become two characters, so mixed text can grow.

A row of pixels

The sample string has 67 characters: 12 W, 1 B, 12 W, 3 B, 24 W, 1 B and 14 W. Run length coding writes it as 12W1B12W3B24W1B14W, which is 18 characters. Decoding that text gives back the original exactly.

In the character first style the same text is W12B1W12B3W24B1W14. A line such as abcd is turned into 1a1b1c1d, which is twice as long, so the method is only worth using on data with long runs.

Where run length coding fits

It is one of the oldest and simplest forms of compression. It works well on simple images, fax data, padded fixed width fields and any text where the same value repeats. It is lossless, which means decoding always returns exactly what was encoded.

It does less well on ordinary prose, since few letters repeat in a row. General compressors combine it with other methods. Some formats use a marker byte for runs so that short runs are not expanded.

Digits in the text

Counts are written as digits, so a text that has digits in it would be ambiguous. The tool refuses to encode text with digits and tells you so, and it encodes one line at a time. When decoding, it reads the digits before a character as the count and reports text that does not follow the pattern. To see another compression method step by step, try the LZW Compression Stepper, and for the size of text in different encodings the Text Byte Size Calculator. The Base64 Encoder and Decoder and the Binary Translator show other ways to represent data as text.

Assumptions and limits

  • Runs are counted per character, so upper and lower case letters are different.
  • Counts are written in decimal digits with no separator.
  • The sample is an example. Use your own text.
  • Everything is processed in your browser and nothing is uploaded.

Formulas reviewed October 10, 2026. See the calculation methodology for how SumPanda rounds, tests and sources its formulas.

Frequently asked questions

Why did my text get longer?

If most characters appear once in a row, each one is replaced by a count of 1 and the character, which doubles the length.

Is decoding always exact?

Yes for text this tool encoded. Text with digits is refused when encoding, because the digits could be mistaken for counts.

Can it handle several lines?

Encode one line at a time. Text with line breaks is refused so that a break is never mistaken for a repeated character.

Which style should I pick?

Count first is the common form in textbooks. Use character first if the receiving program expects it.