gzip vs ZIP: they are not the same tool
People say “gzip it” and “zip it” as if they were synonyms. They share an algorithm, but they are built for different jobs.
Side by side
| ZIP | gzip | tar.gz | |
|---|---|---|---|
| How many files? | Many, with folders | One stream | Many (tar first), then one stream |
| Typical extension | .zip | .gz | .tar.gz or .tgz |
| Algorithm | Usually Deflate, per file | Deflate, on the whole stream | Deflate, on the whole tarball |
| Extract one file? | Yes, without reading the others | You get the one file back | You can seek inside modern tar.gz, but it is clunkier than ZIP |
| Windows double-click | Built in | Needs extra software (7-Zip, WinRAR) | Same as gzip, or tar on Windows 10+ |
| Preserves Unix permissions? | Not really (optional extras) | n/a | Yes, that is why backups use it |
Same family, different container
Under the hood, everyday ZIP and gzip both speak Deflate (the same “find a repeated phrase, write a short pointer” method). gzip wraps one Deflate stream in a 10-byte header and an 8-byte footer with a checksum. ZIP wraps each file in its own header and keeps a table of contents at the end of the archive so you can jump to only-this.txt without inflating everything else.
Because ZIP compresses files one at a time, it cannot share a dictionary between them. tar first lays every file end to end, then gzip sees the whole concatenation — so a folder of many similar small text files often shrinks a bit more as .tar.gz than as .zip. For a handful of large files the difference is small.
What about Brotli and zstd?
Newer lossless packers (Brotli, Zstandard) usually beat Deflate on text, which is why websites send Content-Encoding: br or zstd when the browser supports it. You still do not save a .zip: the browser inflates the page into memory and shows it. That on-the-wire trick is related to gzip, not to “right-click, compress folder”.
When to use which
- Sending a folder to someone on Windows or a phone: ZIP. Everyone can open it.
- A backup or source tree on Linux or macOS:
tar -czf project.tar.gz project/so permissions and empty directories survive. - One log file:
gzip app.logproducesapp.log.gzand deletes the original (usegzip -kto keep it). There is no folder list to maintain. - A website: let the server negotiate gzip or Brotli. That is automatic; you do not email anyone a
.gz. - A folder of photos: neither gzip nor ZIP will shrink them much — see why zipping photos does not make them smaller and the packing lesson. Resize and re-encode first.
A few commands
# ZIP a folder (Linux, macOS, Windows with tar)
zip -r photos.zip photos/
tar -a -cf photos.zip photos/ # tar on modern Windows / bsdtar
# gzip a single file (keeps permissions on the original’s metadata, not a directory)
gzip -k report.csv # writes report.csv.gz
# The usual Unix archive
tar -czf project.tar.gz project/
# Peek without extracting
unzip -l photos.zip
gzip -l report.csv.gz
tar -tzf project.tar.gz
Related
Lossless vs lossy compression · Why a ZIP can be larger than the originals · CRC failed / unexpected end of archive · Why zipping photos barely makes them smaller (interactive lesson) · Why zipping photos does not make them smaller · Compress many photos at once · Compress an image without uploading it · Image compressor
Questions
What is the difference between gzip and ZIP?
ZIP holds many named files and folders in one archive, each compressed separately. gzip compresses a single stream and has no directory of names. Pair gzip with tar when you want many files (file.tar.gz).
Is .tgz the same as .tar.gz?
Yes. .tgz is just a shorter extension for a tarball that has been gzip-compressed.
Can Windows open a .gz file?
Not with the built-in compressed-folder support, which understands ZIP. Use tar (included in Windows 10 and later), 7-Zip, or another archiver. A .zip you email will open everywhere.
Can I gzip a whole folder?
Not directly. gzip wants one stream. Use tar -czf folder.tar.gz folder/ to pack the folder first, or create a ZIP if the recipient is on Windows.
Does a website that uses gzip send me a ZIP file?
No. Content-Encoding: gzip (or br) is a transfer trick: the browser inflates the page and displays it. You do not get a downloadable archive.
Published .