TOPICS
Search

LZ77


LZ77 is a lossless compression algorithm introduced by Ziv and Lempel (1977). It parses an input string from left to right, using a bounded window of recent symbols as a dictionary. In the original scheme, both encoder and decoder start with the same prescribed dictionary. At each step the encoder finds a longest prefix of the remaining input that can be copied from a position in the window, subject to a phrase length limit and leaving room for a following symbol. It encodes the starting position, the number of symbols to copy, and that following literal symbol. An empty match encodes only one input symbol, with copy length zero.

In distance notation, if the next output position is i and the copy starts d>0 positions back, a copy of length l appends x_(i+j)=x_(i+j-d) for j=0,...,l-1 in order. The next symbol is the literal. Because i+j-d<i+j, every source symbol is known when it is copied, even if the source and destination ranges overlap. For example, if the decoded output ends in ab, a copy of length 5 at distance 2 appends ababa. Copying and then appending the literal reproduces each encoded phrase, so the entire input is recovered by induction over the phrases.

In compressed DEFLATE blocks, an LZ77 variant uses literals and length-distance pairs as data tokens. Huffman coding encodes literal values and classes of lengths and distances, with extra bits for some lengths and distances (Deutsch 1996).


See also

Huffman Coding, String

Explore with Wolfram|Alpha

References

Deutsch, L. P. "DEFLATE Compressed Data Format Specification Version 1.3." RFC 1951, 1996. https://www.rfc-editor.org/rfc/rfc1951.Veritasium. "The Internet Was Weeks Away from Disaster and No One Knew." Feb. 25, 2026. https://www.youtube.com/watch?v=aoag03mSuXQ.Ziv, J. and Lempel, A. "A Universal Algorithm for Sequential Data Compression." IEEE Trans. Inform. Theory 23, 337-343, 1977. https://doi.org/10.1109/TIT.1977.1055714.

Cite this as:

Weisstein, Eric W. "LZ77." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/LZ77.html

Subject classifications