The basics
What is a TGZ or .tar.gz file?
A .tar.gz file is a folder (or several files) turned into a single file in two steps. First tar bundles everything into one uncompressed archive, keeping names, folders, permissions and dates. Then gzip compresses that archive as one stream. .tgz is the same thing with a shorter name, from the days when MS-DOS allowed only three-letter extensions.
It's often called a tarball, and it's the standard way to ship source code, Linux software, server backups and data sets. Programming language packages often use it too: npm packages and Python source distributions are .tgz and .tar.gz files.
Because the whole archive is compressed as one stream, it usually ends up smaller than a ZIP of the same files. The cost is that there's no index: to get at the last file, everything before it has to be decompressed.
Anatomy
What's inside a TGZ file
A .tar.gz file has two layers, and each tool only knows about its own. gzip sees one stream of bytes to compress. Inside that stream is a complete tar file with a header in front of every file. Here are both layers of sample-project.tar.gz.
offset bytes part
layer 1: the gzip file, 4,273 bytes
0 1F 8B 08 00 gzip signature, Deflate, no flags
4 40 92 E0 6A date: 27 Oct 2026 12:00 UTC
8 02 FF XFL 2 (-9), OS 255 (unknown)
10 ED 5C 7B 94 15 C5 … 4,255 bytes of Deflate data
4265 E6 F5 71 83 CRC-32 of the whole tar
4269 00 50 00 00 ISIZE = 20,480, the tar's size
layer 2: the tar inside, 20,480 bytes
0 header sample-project/ type 5, folder
512 header sample-project/README.md 712 bytes
2048 header sample-project/CHANGELOG.txt 194 bytes
3072 header sample-project/data/ type 5
3584 header sample-project/data/readings.csv 9,265 bytes
13824 header sample-project/data/stations.json 564 bytes
15360 header sample-project/images/ type 5
15872 header sample-project/images/logo.png 846 bytes
17408 header sample-project/scripts/ type 5
17920 header sample-project/scripts/summary.sh 314 bytes, 755
18944 00 × 1,024 end of archive
19968 00 × 512 padding to 20,480- 1
1F 8B 08 00The gzip header
The same header as any .gz file. The flag byte is
00: no stored file name. That's normal for tarballs: withtar -czf, the data reaches gzip through a pipe, not from a named file. - 2
02 FFExtra flags and OS
XFL 2 means maximum compression. OS 255 (unknown) is what Python's
gzipmodule writes; GNU gzip writes 3 for Unix. Nothing reads either value when extracting. - 3
ED 5C 7B 94 …One Deflate stream for everything
All 20,480 bytes of the tar, headers and padding included, are compressed together. Patterns shared between files are found across file boundaries, and the long runs of zeros in tar padding cost almost nothing.
- 4
E6 F5 71 83 · 00 50 00 00The gzip trailer
A CRC-32 of the whole tar and its size, 20,480 bytes. gzip checks the archive as a whole; tar itself has no checksums on file contents.
- 5
header sample-project/README.mdThe tar layer
Inside is an ordinary 20,480-byte ustar file: 512-byte headers with name, size, permissions and owner, then the data. The TAR page takes one header apart field by field.
- 6
sample-project/ …A single top-level folder
Every path starts with
sample-project/, so extracting creates one folder. That's the convention for tarballs;sample-no-top-folder.tgzbreaks it on purpose. - 7
summary.sh, 755Permissions travel along
The script is stored as executable. Extract on Linux or macOS and it still runs, which a ZIP made on Windows usually can't promise.
How to
How to extract a .tar.gz file on Windows, macOS and Linux
| System | Easiest way | Command line |
|---|---|---|
| Windows 11 | Recent versions: double-click to browse it in File Explorer, or right-click and choose Extract All | tar -xf file.tar.gz in Command Prompt or PowerShell |
| Windows 10 | Install 7-Zip: open the .tar.gz, then the .tar inside it, then extract | tar -xf file.tar.gz (built in since version 1803) |
| macOS | Double-click: Archive Utility extracts it into a folder next to the file | tar -xf file.tar.gz in Terminal |
| Linux | Double-click in the file manager, or right-click and choose Extract Here | tar -xf file.tar.gz |
| Phone | An archive app that supports tar and gzip; built-in file apps vary |
A few commands cover nearly every need:
- Look before you extract:
tar -tzf file.tar.gzlists every path. Check that they all start with one folder name and that none start with/or contain... - Extract into a specific folder:
mkdir out && tar -xzf file.tar.gz -C out. - Extract one file:
tar -xzf file.tar.gz sample-project/README.md, using the path exactly as the listing shows it. - Decompress only, keeping the tar:
gunzip file.tar.gzleavesfile.tar.
Do I need the z?
Not when extracting. GNU tar and bsdtar (macOS and Windows) recognise gzip, bzip2 and xz compression from the data, so tar -xf works for all of them. You do need it, or -a, when creating an archive.
The command
What tar -xzvf and tar -czvf mean
The famous incantation is just single-letter options run together. The order doesn't matter, except that f must come last because the file name follows it.
| Letter | Long form | Meaning |
|---|---|---|
c | --create | Create a new archive |
x | --extract | Extract files from an archive |
t | --list | List the contents |
z | --gzip | Compress or decompress with gzip |
v | --verbose | Print each file name as it's processed |
f | --file | The archive file name follows |
C | --directory | Change to this folder first |
So tar -czvf project.tar.gz project/ means create, gzip, verbose, into the file project.tar.gz, from the folder project/. And tar -xzvf project.tar.gz means extract, gunzip, verbose, from project.tar.gz.
How to
How to make a good .tar.gz file
- Basic:
tar -czf project.tar.gz project/. Name the folder, not its contents, so the archive extracts into one folder. - Leave things out:
tar -czf project.tar.gz --exclude=node_modules --exclude=.git project/. - Smaller: tar runs gzip at its default level 6. For
-9, pipe it:tar -cf - project/ | gzip -9 > project.tar.gz. - Faster:
tar -I pigz -cf project.tar.gz project/uses pigz, a parallel gzip by Mark Adler that uses every CPU core and writes ordinary gzip files. - Without macOS extras:
COPYFILE_DISABLE=1 tar -czf …stops macOS adding._files for Finder metadata. - Reproducible (same input, same bytes): with GNU tar,
tar --sort=name --mtime=@0 --owner=0 --group=0 --numeric-owner -cf - project/ | gzip -n > project.tar.gz.gzip -nleaves the date out of the gzip header. - On Windows 11: right-click a folder, Compress to, then TAR File or Additional options for gzip. On any recent Windows,
tar -czf project.tar.gz projectworks in a terminal.
Related formats
.tar.gz vs ZIP: which should you use?
| .tar.gz | ZIP | |
|---|---|---|
| How it compresses | The whole archive as one stream | Each file separately |
| Size of our sample project | 4,273 bytes | 5,137 bytes (zip -9) |
| Get one file out | Decompress everything before it | Jump straight to it via the central directory |
| List the contents | Decompress the whole file | Read the directory at the end |
| Damage in the middle | Everything after it is usually lost | Other files still extract |
| Unix permissions and links | Always kept | Optional; often lost |
| Opens without extra software | Linux, macOS, recent Windows 11 | Everywhere |
Use .tar.gz for software, source code and anything going to Linux or macOS servers, where permissions matter. Use ZIP when sending files to people whose computers you don't know, especially on Windows.
Variants
Other compressed tar files
Swap gzip for another compressor and you get the other tarball types. The tar inside is identical; only the outer layer changes.
| Name | Short form | Create with | Notes |
|---|---|---|---|
.tar.gz | .tgz | tar -czf | Fast, universal; the default choice |
.tar.bz2 | .tbz2, .tbz | tar -cjf | Smaller, slow to unpack. See bzip2 |
.tar.xz | .txz | tar -cJf | Small, quick to unpack, slow to create. See XZ |
.tar.zst | .tzst | tar --zstd -cf | Zstandard: very fast, good ratio; growing in Linux packaging |
.tar.Z | .taZ | tar -cZf | The old Unix compress; rare today |
Troubleshooting
Common .tar.gz problems
gzip: stdin: not in gzip formatandError is not recoverable: exiting now: the file isn't gzip. Either it's a plain tar with a.tar.gzname (trytar -xfwithoutz), the browser already decompressed it during download, or it's an HTML error page.file name.tar.gztells you which.Unexpected EOF in archive: the download was cut short. Files before the break are usually extracted fine; download it again for the rest.- Files spill into the current folder: the archive has no top-level folder.
sample-no-top-folder.tgzis built like that. Extract with-C newfolderto keep things tidy. - Paths start with
./: archives made withtar -czf x.tgz -C folder .store names such as./README.md. That's harmless, but to extract one file you must type the./too. - 7-Zip shows a single
.tarfile: 7-Zip unwraps one layer at a time. Open the.tarinside to reach the files. Cannot open: File existsor permission errors: a file with that name is already there and read-only, or you're extracting over a folder you don't own. Extract into a new folder instead.
Security
Is it safe to extract a .tar.gz file?
A .tar.gz carries the risks of both its layers. From tar: entry names with ../ or absolute paths, and symbolic links that redirect later files outside the target folder; the TAR page explains them. From gzip: a small file that expands to an enormous one; see the GZ page. Current GNU tar and bsdtar block the path tricks by default.
For an archive from someone you don't know: list it first with tar -tzvf, extract as a normal user (never with sudo) into a new empty folder, and don't run anything from it until you've looked at what it is.
Free downloads
Sample TGZ files to download
Free sample .tar.gz and .tgz files for testing extraction, upload checks and archive libraries. Each one passes gzip -t, lists with GNU tar and opens with Python's tarfile. The tar inside is POSIX ustar, every entry dated 27 October 2026, 12:00 UTC.
Browsers can't show this kind of file in a page. Download it to open it in the app it belongs to.
What's inside sample-project.tar.gz
A small made-up project folder, packed the way most tarballs are: one top-level folder, a mix of text and binary files, and Unix permissions.
One top-level folder
Everything is under
sample-project/, so it extracts into a single folder.Readable files
A Markdown README, a changelog, a 240-row CSV of fictional weather readings and a JSON file, all UTF-8.
A PNG that doesn't shrink
images/logo.pngis already compressed, so gzip gains nothing on it; the text files shrink a lot.An executable script
scripts/summary.shis stored with mode 755. After extracting on Linux or macOS,./sample-project/scripts/summary.shcounts the readings per station.Compression ratio
The 20,480-byte tar compresses to 4,273 bytes, 21% of its size.
All sample TGZ files
Project folder as .tar.gz
sample-project.tar.gz · 4.2 KB (4,273 bytes)
10 entries under one top-level folder: README, changelog, CSV, JSON, a PNG and an executable shell script, compressed with gzip
-9.- Testing extraction on Windows, macOS and Linux
- Checking permissions survive a round trip
Files at the root, .tgz extension
sample-no-top-folder.tgz · 4.2 KB (4,264 bytes)
The same files with no top-level folder and names starting
./, astar -czf x.tgz -C folder .makes them. Uses the short.tgzextension.- Checking a tool recognises `.tgz`
- Testing code that expects (or must not expect) a top-level folder
100 KB .tar.gz file
sample-100kb.tar.gz · 100 KB (102,400 bytes)
Exactly 102,400 bytes: a README and a file of pseudo-random data, which can't be compressed, sized to hit the exact total.
- Upload and size-limit tests
- Download and progress-bar tests
Ways to test with them
- Extraction on each system:
sample-project.tar.gzshould give onesample-projectfolder with three subfolders and six files. - Permissions: on Linux or macOS,
ls -l sample-project/scripts/summary.shshould show-rwxr-xr-x. - Archives without a top folder: a tool that assumes one (for example to name the output folder) will misbehave on
sample-no-top-folder.tgz. - Upload limits:
sample-100kb.tar.gzis exactly 102,400 bytes, for testing a limit at the boundary.
Free to use for testing, teaching and demos, commercially or not, with no attribution needed. A link back to this page is always appreciated.
Put it online
Have a .tar.gz file? Give it a link.
Drop a .tar.gz or .tgz on 99helpers and it gets its own download link, handy for sharing a release, a backup or a data set without attachment limits. Anyone with the link downloads the archive exactly as you uploaded it.
Questions
TGZ files, frequently asked
What is a .tar.gz file?
A folder or set of files bundled with tar and then compressed with gzip. Extracting it gives back every file with its folder structure, permissions and dates.
Is .tgz the same as .tar.gz?
Yes. .tgz is a short form of .tar.gz from the days of three-letter extensions. The contents are identical, and you can rename one to the other.
How do I open a .tar.gz file on Windows?
In recent Windows 11, double-click it or right-click and choose Extract All. On Windows 10 and 11 you can also run tar -xf file.tar.gz in Command Prompt. On any version, 7-Zip works: open the .tar.gz, then the .tar inside.
How do I extract a .tar.gz file on a Mac?
Double-click it and Archive Utility extracts it next to the file. In Terminal, tar -xf file.tar.gz does the same.
How do I extract a .tar.gz file in Linux?
tar -xzf file.tar.gz, or just tar -xf file.tar.gz, since GNU tar detects the compression. Add -C folder to extract somewhere else.
What does tar -xzvf mean?
Extract (x), using gzip (z), listing each file (v), from the file named next (f).
Is .tar.gz better than ZIP?
It usually compresses better and keeps Unix permissions, so it's preferred for software and servers. ZIP opens on every computer without extra software and lets you take out one file quickly.
Can I extract just one file from a .tar.gz?
Yes: tar -xzf archive.tar.gz path/inside/archive.txt. tar still has to decompress the archive to find it, so it can take a while on big archives.
Related formats
Other file types explained
Keep going
Related
Sources
- GNU tar manual: Creating and reading compressed archives
- RFC 1952: GZIP file format specification version 4.3
- Microsoft Learn: tar on Windows
- Pureinfotech: Windows 11 can now extract RAR, 7z and TAR archives
- GNU tar manual: Controlling the archive format
Last reviewed 27 October 2026.