Skip to content
Techniques & Technology

Run-Length Encoding

Simple compression

Run-length encoding compressed data by storing repeated values as count-value pairs, dramatically reducing storage for graphics with large uniform areas.

C64zx-spectrumAmigaNES compressiondatatechnique 1967–present

Overview

Why store “AAAAAABBBBCC” when you can store “6A4B2C”? Run-length encoding replaced sequences of identical values with a count and single value. For graphics with large uniform areas—backgrounds, simple sprites, text screens—RLE achieved significant compression with minimal decoding overhead.

The algorithm

OriginalEncoded
AAAAAAA7A
BBBBB5B
CC2C
AAAAAABBBBBC6A5B1C

Implementation

Encoding:
- Read input byte
- Count consecutive identical bytes
- Output count, then byte value
- Repeat until end

Decoding:
- Read count
- Read value
- Output value 'count' times
- Repeat until end

Ideal use cases

ContentCompression ratio
Solid backgroundsExcellent (90%+)
Simple spritesGood (50-70%)
Text screensVery good (70-80%)
Detailed imagesPoor (may expand)

Variations

VariantFeature
PackBitsEscape byte for literals
PCX formatRLE for image rows
ILBMAmiga bitmap format
Vertical RLEColumn-wise encoding

Platform examples

ZX Spectrum

Screen loading with RLE:

  • 6912 bytes uncompressed
  • Often 2-4KB compressed
  • Fast decompression

C64

Character/colour data:

  • Screen memory (1000 bytes)
  • Colour memory (1000 bytes)
  • Significant savings

NES

Tile and nametable compression:

  • ROM space critical
  • Simple decoder in 6502

Limitations

IssueCause
Random data expandsNo runs to compress
OverheadCount byte per run
Fixed ratioNo adaptive compression
Horizontal biasWorks best row-by-row

See also