What is a GZ file?
GZ (GNU Zip) is a file compression format based on the DEFLATE algorithm, created by Jean-loup Gailly and Mark Adler in 1992 as a free replacement for the proprietary compress format on Unix systems. Unlike ZIP, GZ compresses a single file or data stream without bundling multiple files — for multi-file archives, GZ is combined with TAR, producing the ubiquitous .tar.gz (also written .tgz) format.
GZ is deeply embedded in Unix/Linux infrastructure: log rotation, web server content encoding, software distribution, and database backups all rely on it. The format is lossless and patent-free, making it universally available.
How to open GZ files
- gunzip / gzip -d (macOS, Linux) — Built-in CLI:
gunzip file.gz - tar (macOS, Linux) — Extract
.tar.gzin one step:tar -xzf archive.tar.gz - 7-Zip (Windows) — Free, open-source
- WinRAR (Windows) — Built-in GZ support
- The Unarchiver (macOS) — Free, handles
.gzand.tar.gz - PeaZip (Windows, Linux) — Free alternative
Technical specifications
| Property | Value |
|---|---|
| Algorithm | DEFLATE (LZ77 + Huffman coding) |
| Single-file | Compresses one file or stream |
| Checksum | CRC-32 for integrity verification |
| Concatenation | Multiple GZ streams can be concatenated |
| Common pairs | .tar.gz / .tgz, .sql.gz, .log.gz |
| Magic bytes | 1F 8B |
| MIME type | application/gzip |
Common use cases
- Web compression: HTTP
Content-Encoding: gzipheader compresses text responses (HTML, CSS, JS, JSON) for faster transfer — typically 60-80% smaller - Log file rotation:
logrotateon Linux compresses old log files with gzip to save disk space - Source code distribution:
.tar.gztarballs are the standard format for open-source software releases - Database backups:
mysqldump | gzip > backup.sql.gzcreates compressed SQL dumps - Pipeline compression: GZ can compress data streams in real-time (piped between processes)
GZ vs other compression formats
| Format | Algorithm | Ratio | Speed | Single-file |
|---|---|---|---|---|
| GZ | DEFLATE | Good | Fast | ✅ |
| BZ2 | BWT + Huffman | Better | Slower | ✅ |
| XZ | LZMA2 | Best | Slowest | ✅ |
| ZIP | DEFLATE | Good | Fast | ❌ (multi-file) |
| Zstandard | zstd | Very good | Very fast | ✅ |
For most use cases, GZ offers the best balance of speed and compression. XZ is preferred when maximum compression matters more than time. Zstandard (.zst) is increasingly replacing GZ in high-performance scenarios.
Working with GZ on the command line
# Compress a file (replaces original with .gz)
gzip file.sql
# Compress while keeping the original
gzip -k file.sql
# Decompress
gunzip file.sql.gz
# or
gzip -d file.sql.gz
# Create .tar.gz archive
tar -czf archive.tar.gz /path/to/folder/
# Extract .tar.gz archive
tar -xzf archive.tar.gz
# View compressed file without extracting
zcat file.txt.gz | head -20
HTTP gzip compression
Web servers enable gzip compression for text-based responses to reduce bandwidth and improve load times. In Nginx: gzip on; gzip_types text/html text/css application/javascript;. In Apache: enable mod_deflate. Browsers advertise support via the Accept-Encoding: gzip, deflate, br request header, and servers respond with Content-Encoding: gzip when they compress the body. This is transparent to the end user but significantly reduces page load times on slow connections.
Integrity verification
GZ files include a CRC-32 checksum and the uncompressed file size. If a GZ file is truncated or corrupted during transfer, gunzip will report an error. Verify integrity with gzip -t file.gz (test mode) before depending on the contents.