Compression Lab
Compare LZ77, Huffman and run-length encoding, inspect their steps and decode the result.
About this tool
Compare repeated substrings, symbol frequencies and long runs in lossless compression. Choose an example to calculate immediately, or enter text and choose Compare / Ctrl/Meta+Enter. After the first calculation, edits update after a short typing pause without moving focus. Invalid edits hide old results. Tabs inspect the same current input. Reset clears text; TXT downloads the exact input text. Data contains examples and TXT.
The comparison uses the UTF-8 input size and simplified bit estimates. Below 100% means smaller, above 100% means larger. Huffman includes its codebook; a short input can grow despite a small payload. These are educational formats, not ZIP, gzip or DEFLATE output.
LZ77 searches the preceding 32 Unicode symbols and looks ahead at most 16. Matches of at least three symbols become distance/length/next-symbol tokens; overlapping copies are allowed. Offsets start at zero. Literals cost 1 flag bit plus UTF-8 bytes; matches cost 11 control bits plus any next symbol.
Huffman repeatedly merges the two least frequent nodes. Edge labels 0 and 1 form the displayed prefix-free codes. A single symbol uses code 0. The estimate adds 32 bits for the codebook entry count and, for each symbol, UTF-8 bytes plus 16 bits of code length. Canonical codes can be rebuilt from these lengths; the displayed tree can use different codewords of the same length. File framing and byte padding are excluded.
RLE combines consecutive equal symbols and estimates 16 bits for each count plus the UTF-8 symbol. ABABABA has LZ77 tokens A, B, then a five-symbol copy from distance two: 29 estimated bits versus 56 input bits. Its seven RLE runs cost 168 bits. Open Decoded text to inspect the actual reconstruction.
At most 1024 Unicode code points and 64 different symbols are allowed. Combining marks count separately. ⎵ means space, \n newline and \t tab; other control symbols appear as U+. Tables and trees scroll locally; small trees grow up to 2× without shrinking node text. Only raw text, example selection, active tab and disclosure preferences are saved (100,000 serialized characters), never computed results or traces. Legacy v1 retains those inputs and discards its computed flag. Reload/new views await an explicit action; mounted pinned views stay in memory. Oversized drafts keep the prior saved copy: download TXT before reload. Computation stays in this browser. The LZ77 window is fixed; Huffman uses a sorted queue for the small alphabet.
Choose a symbol under Symbol path or click its leaf to highlight its bit sequence from the root. With a single symbol, the only node has code 0 and there is no branch to follow.