The GZ (.gz) Format, Explained
iLoveConverter Team 3 min read
On this page
GZ — gzip — is a single-stream compression format. It takes one file’s bytes, compresses them with DEFLATE and wraps the result in a small header. That is the whole concept, and it explains both gzip’s strengths and its most common misunderstanding: a .gz file does not contain a folder of files; it contains one byte stream.
The gzip header
A gzip file starts with a fixed header:
- Magic bytes
1F 8B— how tools identify the format. - Compression method
08— DEFLATE. - Flags — whether an original filename, comment or extra field follows.
- Modification time — a 32-bit Unix timestamp.
- Extra flags and OS — mostly informational.
- CRC32 and original size — stored in the trailer.
After the header comes the DEFLATE stream: a series of blocks using Huffman coding and LZ77-style back-references. The trailer holds a CRC32 of the uncompressed data and its length modulo 2³².
Because the header can carry a filename, gzip file.txt produces file.txt.gz and the original name survives inside. But no directory structure or permissions are stored.
One file at a time
This is the key limitation. To compress a folder, Unix tradition combines TAR and gzip:
tarconcatenates the folder into one stream.gzipcompresses that stream.
The result is .tar.gz or .tgz. gzip itself never sees individual files, so it cannot restore them separately. If you gzip two files, you get two .gz files, not one archive.
There is a lesser-known feature: gzip supports concatenated members. Multiple gzip streams can be joined into one file, and decompression reads them in order. This is how some log rotation tools append compressed chunks, but it is not a substitute for a real archive format.
When gzip is the right tool
- Compressing a single large text file — logs, SQL dumps, JSON exports.
- Pipelines —
mysqldump | gzip > backup.sql.gzavoids an intermediate file. - HTTP transfer — gzip is a standard
Content-Encoding, though Brotli is now preferred where supported. - Kernel and embedded use — gzip is simple and widely implemented.
When it is the wrong tool
- Many files that must stay separate — use ZIP, 7Z or TAR.GZ.
- Already-compressed content — JPEG, MP4, MP3, ZIP and PDF generally do not shrink; gzip can even make them slightly larger.
- Random access — gzip is a stream; you cannot extract one file from the middle.
- Very large archives — 7Z or zstd often compress better.
Compression ratio
For text, gzip typically achieves 2–4× reduction. Source code, logs and JSON compress well because they are repetitive. Binary executables compress less. Media files barely compress at all. The -9 flag increases effort slightly, but the gain over the default -6 is often a few percent.
Decompressing and verifying
gzip -d file.gz
gunzip file.gz
zcat file.gz | less
gzip -t file.gz tests integrity without writing output. If a download is truncated, decompression fails with an “unexpected end of file” error; there is no reliable partial recovery. Always verify the checksum published next to the file when available.
Common problems
- “Not in gzip format” — the file may be a ZIP or TAR renamed to
.gz. - CRC error — data corruption; re-download.
- Filename lost — some tools strip the original name; decompress with
-Nto use the stored one. - Double compression — a
.tar.gzdecompressed once leaves a.tar; that is expected, not a failure.
FAQ
Does GZ store multiple files?
No. A .gz holds one compressed stream. Use TAR.GZ or ZIP for multiple files.
Is GZ the same as ZIP?
No. ZIP is an archive format with per-file entries and a central directory; gzip compresses a single stream and has no file index.
Can I open GZ on Windows?
Yes, with 7-Zip or WinRAR. Windows 11 also handles gzip in some contexts via tar support.
Is GZ lossless?
Yes. Decompressing restores the original bytes exactly, verified by CRC32.
Try it yourself — free, right in your browser
Everything mentioned in this guide runs locally on this site: no upload, no watermark, no sign-up.
Format deep-dives: GZ (.gz) , TAR.GZ (.tar.gz.tgz) , TAR (.tar)