Skip to content
100% local

LZW compression

Compress text into LZW dictionary codes, or decompress a code stream back to text.

Input
Output

LZW compression

LZW (Lempel-Ziv-Welch) is the dictionary-based compression algorithm behind classic GIF images and Unix compress. Paste a passage and this tool builds a dictionary of repeated substrings on the fly, replacing each repeated chunk with a shorter numeric code. Paste a code stream back in and it rebuilds the original text from the same rules. It's a good way to see dictionary compression working step by step, or to shrink small, repetitive chunks of text or data before storing them.

Direction switches between compressing (encode) and decompressing (decode); its swap button also moves the current output into the input so a result round-trips immediately. Input format and output format choose how the non-code side reads — plain text, a hex byte string, or comma-separated byte values — so you can compress raw hex dumps as easily as sentences. Keep zero-padding fixes every code or byte to a constant width for easy reading in a table; turning it off gives a shorter, variable-width result. Wrap output at N characters breaks a long result into fixed-width lines for copying.

Compression works on raw bytes, so accented letters, Cyrillic and emoji round-trip correctly through UTF-8. Short or non-repetitive input can come out longer than it went in, since a code needs enough bits to beat a single character — that's true of every real LZW implementation. The dictionary caps at 65,536 entries, matching production compressors, and the live tally reports bytes in, codes out, and how many entries it built.

Everything runs locally in your browser — nothing you paste here is uploaded. Copy the result, download it as a .txt file, or send it back into the input to try the reverse direction.

FAQ

Why is the compressed output sometimes longer than the input?
LZW saves space by replacing repeated phrases with shorter codes, so short or highly varied text — where nothing repeats yet — can come out longer, especially with padded hex or byte output. Try it on a longer, more repetitive passage to see real compression.
Do I need to match the options I used to compress when I decompress?
Yes. Input/output format and the padding setting describe exactly how the code stream is written, so decoding needs the same format and padding choice used when it was created.
What's the difference between the hex and byte value formats?
Hex renders each code or byte as hexadecimal digits; byte values render the same data as plain decimal numbers separated by spaces or commas. Both are lossless — pick whichever is easier to paste into your own tools.
Is there a limit to how much text I can compress?
The dictionary caps at 65,536 entries, after which it stops growing but compression still works correctly using the entries already built. Output is capped at 10 MB to keep the page responsive.
Is my text uploaded anywhere?
No. Compression and decompression run entirely in your browser using JavaScript — your text never leaves your device.