LZ77 Compression Tool
LZ77 compresses by pointing backwards: instead of repeating text it has already emitted, it says go back this far and copy this many characters. It is the idea underneath zip, gzip and PNG. The detail worth seeing is that a back-reference may legitimately be longer than its own offset — the copy catches up with itself as it runs, which is how a long run of one character costs almost nothing.
What this generator does
Scans your text and, at each position, looks back through the window for the longest match already emitted, producing a token of offset, length and the following character. It then decodes the whole token list back and compares it against your input before displaying anything.
How to use this tool
- Enter some text with repetition in it.
- Choose how far back a match may reach — that is the sliding window.
- Read the tokens: offset, length, then the next character.
- Try a run like 'aaaaaaaa' and look for a match longer than its own offset.
Understanding the controls
- Your text
- Between 4 and 200 characters. Repeated words and phrases produce far more interesting token lists than random characters.
- Window size
- How far back a match may reach, from 4 to 64 characters. A larger window finds more matches but costs more to encode in a real compressor.
Common use cases
- Understanding the compression step behind zip, gzip and PNG
- Teaching sliding-window compression with visible tokens
- Showing how window size changes what can be matched
- Checking an LZ77 implementation against worked output
- Demonstrating the overlapping-match case that trips up naive decoders
How this generator works
The decoder copies matched characters one at a time rather than in a block, and that is not an implementation detail — it is what makes overlapping matches work. When a match is longer than its offset, the copy reads characters the same loop is still writing, so a run of eight identical characters can be encoded as a single back-reference of length seven. Copying as a block would produce the wrong output, which is why the round-trip check is the one that matters.
Randomness and fairness
No randomness at all. The tokens are fully determined by your text and the window size you choose.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- Up to 200 characters, and a window up to 64 — real compressors use windows of tens of kilobytes.
- The token list is not entropy-coded, so this shows the structure rather than an actual byte saving.
- Greedy matching only: it always takes the longest match available, which is not always optimal overall.
- Every token carries a following character, which is the original LZ77 form rather than the LZSS refinement used in practice.
Privacy and your data
Encoding and decoding both happen in your browser. Your text is never transmitted, and analytics receives only a character count, never any content.
Related generators
- Burrows-Wheeler Transform ToolThe Burrows-Wheeler transform of your text with every sorted rotation shown, checked by decoding it back to the original exactly.
- Huffman Code GeneratorBuilds an optimal prefix code for your text, shows every character's bit pattern, and decodes the bits back to prove it works.
- Text Statistics GeneratorCounts words, sentences and distinct vocabulary in a passage, with every figure re-derived from the text and the ratios kept honest.
- Text Diff GeneratorCompares two texts line by line and shows the smallest set of changes, checked by applying them back to the original.