DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

What Is Run-Length Encoding (RLE)? Definition and Examples

Run-length encoding represents consecutive repetitions as values and counts. Learn how RLE works, when it saves space, and how real implementations differ.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run-length encoding (RLE) is a lossless method that represents consecutive repetitions of the same value as a value and its run length. A sequence such as AAAAA can be represented conceptually as (A, 5); decoding repeats the value five times to restore the original sequence. The pair is an illustration, not a universal byte format: each RLE format defines its own counts, literals, boundaries, and limits.

How run-length encoding works

An encoder scans an ordered sequence and groups each maximal adjacent stretch of identical values into a run. For example, AAAABBCCCCC contains three runs: (A, 4), (B, 2), and (C, 5). The decoder uses the values and counts to reconstruct the sequence without losing information.

As an Amazon Associate I earn from qualifying purchases.

Real encodings must also represent values that do not repeat. Many formats handle these as literal segments: they store the values directly, rather than expressing them as repetitions. Microsoft describes its NSCodec stream as segments of runs and literals, while DICOM defines separate replicate-run and literal-run encodings (Microsoft Learn: NSCodec Run-Length Encoding; DICOM PS3.5, 2019a, section G.3).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A notation such as 4A2B5C can help illustrate the idea, but it is not a safe general-purpose format: if the input itself contains digits, the notation may be ambiguous unless values are escaped or otherwise defined. A real file or protocol needs precise rules for encoding counts and values.

When RLE saves space—and when it does not

RLE is most useful when identical values occur in long adjacent stretches, such as uniform areas in an image. It only combines neighboring repetitions; values that recur in separate parts of the sequence are not combined unless another transformation or technique is used.

If values alternate or runs are short, the counts and control information can offset any savings or make the result larger. Microsoft’s NSCodec documentation gives examples of encoding that expands the data and says the original stream is sent instead in that case. NVIDIA notes that its value-and-run representation can double data when every run has length one; that example describes that representation, not every RLE format.

Why RLE does not have one universal format

RLE names a family of related encodings, not a single byte-level standard. Implementations differ in what counts as a value, how they encode literal data, the maximum run length, and whether runs may cross boundaries. These differences matter when reading or exchanging compressed data.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Implementation How it handles data Specific rules
DICOM RLE Byte-oriented replicate runs and literal runs. The DICOM Standards Committee’s 2019a PS3.5 section G.3 specifies replicate runs of 2–128 bytes and literal runs of 1–128 bytes. Each image row is encoded separately; a run must not cross a row boundary. Segments are padded to an even number of bytes when needed.
Windows bitmap RLE BI_RLE8 for 8-bit bitmaps and BI_RLE4 for 4-bit bitmaps; includes encoded and absolute modes. Escape pairs signal events such as end of line, end of bitmap, and delta movement. See Microsoft’s bitmap compression documentation.
Microsoft NSCodec Processes an image stream as runs and literals. Its documentation includes cases where encoding expands the data and the original stream is sent instead. See Microsoft Learn: NSCodec Run-Length Encoding.
R’s rle() function Returns vectors of run lengths and corresponding values; inverse.rle() reconstructs the input. This is behavior of R’s base-language functions, not a file format. R documents that missing values are treated as unequal to the preceding value, even if it is also missing. See R documentation: Run Length Encoding.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What to check before using or decoding an RLE stream

The label “RLE” alone does not establish compatibility. Check the specific format or protocol for these details:

  • What is treated as a value: a bit, byte, pixel, or another unit?
  • How are literal segments and run counts represented?
  • What are the minimum and maximum run lengths?
  • Are there row, block, or segment boundaries that a run cannot cross?
  • Do escape codes have special meanings, such as marking the end of a line or image?
  • What does the encoder do if the encoded data is larger than the original?

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.