Gzip is two things with one name. It's a file format for lossless compression, defined in RFC 1952 in 1996, and it's the program that creates and opens those files, usually ending in .gz. Inside, the data is packed with the DEFLATE method, and a checksum (CRC-32) lets the receiver detect damage. Lossless means what you unpack matches the original byte for byte.
Jean-loup Gailly and Mark Adler wrote the gzip program to replace the older Unix compress tool. Today you mostly meet gzip in two places: on web servers and on the command line.
How gzip makes web pages faster
Text repeats itself a lot, so it shrinks well. The GNU gzip manual says text such as source code or English is typically reduced by 60 to 70 percent. Smaller files take less time to download, which matters most for the HTML document that everything else waits on.
Browser and server agree on compression with two HTTP headers:
- The browser says which formats it can unpack, in
Accept-Encoding. - The server compresses the response with one of them and names it in
Content-Encoding. - The browser unpacks the response before using it.
GET /blog/ HTTP/1.1
Accept-Encoding: gzip, br, zstd
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Vary: Accept-Encoding
The Vary: Accept-Encoding header tells caches that the response depends on what the browser asked for, so a cache doesn't hand a compressed file to a client that can't read it. MDN
What to compress and what to skip
Compress text: HTML, CSS, JavaScript, JSON, XML, SVG and plain text. Skip files that are already compressed, such as images, audio, video and ZIP archives. Compressing them again saves little or nothing and can even make them larger.
Gzip, Brotli and Zstandard
Gzip is the oldest of the three formats browsers commonly use. Brotli usually saves more bytes on the same text.
| Format | Content-Encoding |
Defined in |
|---|---|---|
| Gzip | gzip |
RFC 1952 (1996) |
| Brotli | br |
RFC 7932 |
| Zstandard | zstd |
RFC 8878 |
As of 22 October 2026, W3Techs finds compression on 93.4% of websites. Among those, 46.8% use gzip, 41.1% Brotli and 13.6% Zstandard; one site can use more than one. W3Techs
You don't have to pick only one. A server can offer Brotli or Zstandard to browsers that ask for them and fall back to gzip for everyone else. Keep gzip available: Google's crawlers list gzip, deflate and Brotli as the encodings they support.
How to check whether a page uses gzip
In the browser. Open developer tools, go to the Network panel, reload the page and select the document. Look for
content-encodingin the response headers.On the command line. Ask for gzip and print the headers:
curl -s -o /dev/null -D - -H "Accept-Encoding: gzip" https://example.com/ | grep -i content-encodingIn Lighthouse. Since Lighthouse 13, the old "Enable text compression" audit is gone. The "Document request latency" insight now flags an uncompressed HTML document.
If you see no content-encoding header on a text file, it was sent uncompressed.
How to turn gzip on
Check the headers first: your host or CDN may already compress for you. If not, compression is a server setting. Apache uses mod_deflate, IIS the <httpCompression> element, and Nginx its gzip module. In Nginx, gzip is off by default and only HTML is compressed until you add more types:
gzip on;
gzip_vary on;
gzip_types text/css application/javascript application/json image/svg+xml;
After the change, run the check above again to confirm the header appears. For other ways to load pages faster, see page speed.
Gzip on the command line
On Linux and other Unix-like systems, gzip compresses a file and replaces it with a .gz version:
gzip report.csv # creates report.csv.gz, removes report.csv
gzip -k report.csv # keeps the original
gunzip report.csv.gz # unpacks it (same as gzip -d)
Levels run from -1 (fastest) to -9 (smallest), and the default is -6.
Gzip compresses one file or stream; it doesn't bundle several files the way ZIP does. To pack a folder, people combine it with tar, which gives the familiar .tar.gz or .tgz files. For the bigger picture of how compression works, see data compression.