What is lzw compression
Last updated: April 1, 2026
Key Facts
- LZW was developed by Terry Welch in 1984 as an improvement over earlier LZ78 compression
- LZW is a dictionary-based algorithm that dynamically builds and updates a code table during compression
- The algorithm initializes with a 256-entry dictionary (for 8-bit data) and expands as it encounters new patterns
- LZW compression is widely used in GIF image format and was the standard compression for TIFF files
- LZW achieves compression ratios of 2:1 to 3:1 on typical text, with better ratios possible on highly repetitive data
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:
- Read symbols from input data
- Find the longest match in the current dictionary
- Output the code for that match
- Add the new sequence to the dictionary
- Continue until all input is processed
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.
More What Is in Daily Life
Also in Daily Life
More "What Is" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- Wikipedia - Lempel-Ziv-WelchCC-BY-SA-4.0
- Wikipedia - GIFCC-BY-SA-4.0