Search for a tool
LZW Compression

Tool to apply LZW compression. Lempel-Ziv-Welch (LZW) is a lossless data compression algorithm created by Abraham Lempel, Jacob Ziv, et Terry Welch.


LZW Compression -

Tag(s) : Compression

dCode and more

dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!

Feedback and suggestions are welcome so that dCode offers the best 'LZW Compression' tool for free! Thank you!

LZW Compression

LZW Decoder


LZW Encoder


Answers to Questions (FAQ)

What is LZW? (Definition)

LZW is a data compression algorithm that reduces file size by using a variable size dictionary.

How to compress/encrypt using LZW compression?

LZW encoding algorithm first initializes a predefined dictionary, such as 128 ASCII values, and encodes characters with their entry number in the dictionary.

Example: The dictionary is 0:A,1:B,2:C,…,25:Z and the plain text is DECODED which can be written 3,4,2,14,3,4,3 (made of 7 items) in the dictionary.

At each step, look for a substring in the dictionary, if it does not exists, the dictionary evolves and stores a new entry constituted of the last two entries found.

Example: Step 1, look for DE, which is not in the dictionary. Store DE (position 26) and save the position of D (position 3) as output.
Step 2, look for EC, which is not in the dictionary. Store EC (position 27) and save the position of E (position 4) as output. And so on with other steps 3 and 4.
Step 5, look for DE again, this time DE exists in the dictionary, go to step 6.
Step 6, look for DED, which is not in the dictionary. Store DED (position 30) and save the position of DE (position 26).
Dictionary has become 0:A,1:B,…,25:Z,26:DE,27:EC,28:CO,29:OD,DED:30

The ciphertext is made up of numbers saved for output.

Example: The ciphertext is 3,4,2,14,26,3 (made of 6 items, the message have been compressed)

How to decompress/decrypt with LZW compression?

LZW decompression/decoding/decryption requires to know the dictionary used and the sequence of values from the compression.

Example: The cipher text is 3,4,2,14,26,3 and the dictionary be 0:A,1:B,2:C,…,25:Z

For each value, check for the corresponding character in the dictionary.

At each step, the dictionary evolves like in the compression part (see above).

Example: Step 1: 3 corresponds to D
Step 2: 4 corresponds to E, add DE in the dictionary in position 26,
Step 3: 2 corresponds to C, add EC in the dictionary in position 27, the same for step 4
Step 5: 26 corresponds to DE, etc.
The decompressed plain text is DECODED.

How to recognize LZW code?

The ciphered message (generally in binary) is rather short (compressed). The first values are generally simple values of the dictionary (non compressed), usually ASCII.

LZW is used in several file formats like GIF or TIFF.

What are the benefits of LZW?

LZW can significantly reduce the size of text files, which can be useful for saving storage space or for speeding up the transfer of such files over low-bandwidth networks. LZW is also relatively simple to implement and is often used in data compression programs.

What are the disadvantages of LZW?

LZW is less efficient for compressing binary files (like images or audio files) than for text files because they have less repetition.

What are the variants of the LZW?

Many variants exist for LZW improving the compression such as LZ77 and LZ78, LZMA, LZSS, or the algorithm Deflate. It is also interesting to combine this compression with Burrows-Wheeler or Huffman coding.

— LZ77 uses windows of seen text to find repetitions of character sequences in the text to be compressed. When it finds a repetition, it uses a code that indicates the position of the repeated sequence in the window and its length, instead of the sequence itself, in the compressed file.

— LZMA uses a compression approach based on the statistical analysis of the data to be compressed (Markov chain), which makes it possible to find and replace repeated data sequences in a probabilistic way.

What is the stop/null marker?

In practice, to indicate the end of a message, a stop (or null) marker is used. The LZW algorithm can then include it in its dictionary (in first value 0 or in last value).

When LZW was invented?

In 1987 by Abraham Lempel, Jacob Ziv, and Terry Welch

Source code

dCode retains ownership of the "LZW Compression" source code. Except explicit open source licence (indicated Creative Commons / free), the "LZW Compression" algorithm, the applet or snippet (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or the "LZW Compression" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) and all data download, script, or API access for "LZW Compression" are not public, same for offline use on PC, mobile, tablet, iPhone or Android app!
Reminder : dCode is free to use.

Cite dCode

The copy-paste of the page "LZW Compression" or any of its results, is allowed (even for commercial purposes) as long as you credit dCode!
Exporting results as a .csv or .txt file is free by clicking on the export icon
Cite as source (bibliography):
LZW Compression on [online website], retrieved on 2024-06-24,

Need Help ?

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!

Questions / Comments

Feedback and suggestions are welcome so that dCode offers the best 'LZW Compression' tool for free! Thank you!
© 2024 dCode — El 'kit de herramientas' definitivo para resolver todos los juegos/acertijos/geocaching/CTF.