What is lzw compression

Last updated: April 1, 2026

Quick Answer: LZW (Lempel-Ziv-Welch) is a lossless compression algorithm created by Terry Welch in 1984 that builds a dictionary of repeated patterns to compress data efficiently and is commonly used in GIF images.

Key Facts

Understanding LZW Compression

LZW (Lempel-Ziv-Welch) is a lossless compression algorithm developed by Terry Welch in 1984. Building on earlier Lempel-Ziv work, Welch created an improved version that automatically builds a dictionary during the compression process. This innovation made the algorithm more practical for real-world applications and eliminated the need for predefined code tables.

How LZW Compression Works

LZW uses a dynamic dictionary approach to achieve compression. The algorithm starts with a standard 256-entry dictionary containing all single-byte values (0-255). As it reads input data, it identifies sequences that match dictionary entries and replaces them with shorter codes. When a new sequence is encountered, it's added to the dictionary with a new code, creating a growing vocabulary tailored to the specific data being compressed.

Dictionary Building Process

The compression process works sequentially:

Real-World Applications

LZW gained prominence as the compression standard for GIF images, which made it widely used across the internet. TIFF (Tagged Image File Format) also used LZW compression as a standard option. The algorithm appears in compression utilities, fax machines, and various data storage applications. Its combination of reasonable compression ratios with fast decompression made it practical for these uses.

Advantages and Considerations

LZW offers several benefits: it's lossless, relatively fast to decompress, and adapts to different data types. The main limitation is that compression ratios vary significantly depending on data characteristics. Random data compresses poorly, while highly repetitive data achieves better ratios. Modern alternatives like DEFLATE and LZ4 often provide better performance in specific scenarios.

Related Questions

How does LZW differ from LZ77 and LZ78?

LZ77 uses a sliding window, LZ78 uses explicit dictionaries, and LZW (Welch's improvement) dynamically builds the dictionary during compression without requiring a predefined table, making it more efficient.

Why was LZW used for GIF compression?

LZW offered good compression ratios for images, was relatively fast for decompression, and was efficient for lossless image storage, making it ideal for web graphics before PNG became common.

Is LZW still used today?

LZW remains in use for TIFF images and some legacy systems, but PNG has largely replaced GIF for web use due to better compression and lack of patent concerns in modern browsers.

Sources

  1. Wikipedia - Lempel-Ziv-WelchCC-BY-SA-4.0
  2. Wikipedia - GIFCC-BY-SA-4.0