What is the GZ file format?
A .gz file is a compressed file produced by the GNU zip (gzip) tool. The format was developed by Jean-loup Gailly and Mark Adler for the GNU Project, with the goal of creating a patent-free replacement for the older .Z compression used on UNIX systems. .gz files store useful metadata in their header - the original file name and a modification timestamp - which can be helpful if the file gets renamed during the compression process.
Where is .gz compression used?
Files in the .gz format are commonly encountered in software packages and installers for Unix-based operating systems. Besides installers, the .gz format is also frequently used to compress text resources such as HTML, CSS and JavaScript on web servers, which facilitates faster loading of web pages. Nonetheless, this compression method is also used for regular data archiving, so .gz files can be encountered by Windows and macOS users as well.
Details about .gz compression
The .gz compression method has one important characteristic: an archive may contain only a single file. The standard way to work around this limitation is to first bundle multiple files using the tar archiving tool, then compress the result - producing a .tar.gz or .tgz file. This two-step approach is the de-facto standard for distributing software source code on Linux and macOS.
Security & safety
RISK: LOWThe gzip format is open and safe, and a .gz is just compressed data that can't run on its own. The usual archive caution applies: a .gz/.tar.gz from an untrusted source can contain executables or scripts that are revealed only after extraction, so scan the contents before running anything. Two technical notes: extremely small .gz files can expand to enormous sizes ('decompression bombs') - be wary of suspiciously tiny archives; and a .tar.gz can contain paths with '../' (a path-traversal/'tar slip' risk) - modern extractors guard against this, but extract untrusted tarballs into an empty folder.
Format details
in a nutshellPrograms that open GZ files
gunzip file.gz. Tarball: tar -xzf file.tar.gz. Pre-installed on essentially every Linux/Unix system. Technical details
deep spec| Magic bytes | `1F 8B` at offset 0, followed by `08` (DEFLATE method byte) |
| Compression algorithm | DEFLATE (RFC 1951); method byte `08` is the only value used in practice |
| MIME type | `application/gzip` |
| Files per stream | One - `.gz` compresses a single input file per stream |
| Header metadata | Stores the original filename (FNAME flag) and last-modified timestamp of the source file |
| Integrity check | CRC-32 checksum of the uncompressed data, written to the 8-byte trailer and verified on extraction |
| Size field | 4-byte ISIZE in the trailer holds the original uncompressed size modulo 2³² |
| Compression levels | Nine levels (1 = fastest/least compression, 9 = slowest/best); default is level 6 |
| HTTP content encoding | Used as the `gzip` Content-Encoding in HTTP/1.1 for compressing web responses on the fly |
| Stream concatenation | Multiple `.gz` streams can be concatenated; `gunzip` decompresses them as a single continuous output |
| OS identification | 1-byte OS field in the header (e.g., `03` = Unix, `00` = FAT) identifies the originating system |
| Header flags | Flags byte controls optional fields: FNAME, FCOMMENT, FEXTRA, and FHCRC (header CRC-16 check) |
| Encryption | None built in - the format has no password protection or encryption mechanism |
| Multi-file convention | Use `tar` first to bundle files, then compress: `tar czf archive.tar.gz files/` produces a `.tar.gz` tarball |
| Streaming design | Compresses in a single forward pass; does not require knowing the total input size before starting |
| Released | 1992 (gzip 1.0); format standardized as RFC 1952 (1996) |
| Open standard | Yes · royalty-free |
| Specification | www.rfc-editor.org |
GZ conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about GZ files.
Frequently asked questions
How do I open a GZ file?
gunzip file.gz, or tar -xzf file.tar.gz for a tarball.What's the difference between .gz and .tar.gz?
How do I open a GZ file on Windows?
Can I create a GZ file for free?
gzip/tar built in.Why is my GZ file only one file when I expected many?
How do I extract a .tar.gz in one step?
tar -xzf archive.tar.gz. In a GUI, PeaZip, Keka, Ark and File Roller all unwrap both the gzip and tar layers in a single extract.