gzip (DEFLATE)
See how gzip shrinks text: repeats become short copies, and Huffman codes give frequent symbols fewer bits.
- Window: 32 KB
- Copies: 3-258 bytes
- Codes: up to 15 bits
- gzip frame: 18 bytes
What do these mean?
- Literal: a character written as itself, because no repeat of 3 or more characters starts at its position.
- Copy: a length and a distance meaning "take this many characters from this far back". It may overlap the text it produces.
- Window: how far back the compressor may look for a repeat. 32 KB in gzip, up to 16 MB in Brotli.
- Huffman code: a code of bits for each symbol, shorter for frequent symbols, built from a tree that joins the two rarest symbols again and again.
- Prefix-free: no code is the start of another, so a stream of codes can be read back without separators.
The text has 23 characters, 184 bits uncompressed. The compressor reads it from left to right and asks at every position whether what comes next appeared before.
Space: play or pause. Left and right arrows: step. Home and End: jump.
Try this: Type the same letter many times. A single copy with distance 1 covers all of them, because a copy may overlap the text it produces.
How it works
gzip runs DEFLATE in two stages. LZ77 walks through the text and, at each position, looks for the longest run of bytes that already appeared in the last 32 KB; instead of repeating them it writes a pair: how many bytes to copy (3-258) and how far back they are. Whatever is left, the literals and those pairs, is then written with Huffman codes, where frequent symbols get short codes and rare ones long codes. gzip wraps the result in a 10-byte header and an 8-byte trailer with a CRC-32 checksum.
When it is a good choice
gzip compresses text that repeats itself: HTML, CSS, JavaScript, JSON, logs, CSV. Every browser and server understands it, it is fast at every level, and it is the safe default for compressing responses on the fly. Data that is already compressed, such as JPEG, PNG, WOFF2 or ZIP, has no repeats left, so gzip only adds its frame.
On your own text
The same two stages, done by real gzip (level 6) on a longer text. Paste your own, or bring one from the Gzip & Brotli Compression tool.