File types · Explainer

The TGZ file (.tar.gz, .tgz)

A TGZ file, usually named .tar.gz, is a folder packed into a tar archive and then compressed with gzip. This guide explains what's inside one, how to extract it on every system, how it compares with ZIP, and has free sample .tar.gz files to download for testing.

At a glance

Full name
gzip-compressed tar archive ("tarball")
Extensions
.tar.gz, .tgz; rarely .taz
MIME type
application/gzip, since the outer layer is gzip; also seen: application/x-gtar, application/x-compressed-tar
Kind
Binary: a tar archive inside one gzip stream; lossless
Standards
tar (POSIX ustar and pax, or GNU) plus gzip (RFC 1952)
First used
Since gzip's release in 1992; before that, tar files were compressed as .tar.Z
Keeps
Folders, Unix permissions, owners, dates, symbolic and hard links
Opens with
tar on Linux, macOS and Windows 10/11; macOS Archive Utility; recent Windows 11 File Explorer; 7-Zip
Magic number
1F 8B 08 (gzip); after decompressing, ustar at offset 257

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.

sample-project.tar.gz (two layers)
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. 11F 8B 08 00

    The gzip header

    The same header as any .gz file. The flag byte is 00: no stored file name. That's normal for tarballs: with tar -czf, the data reaches gzip through a pipe, not from a named file.

  2. 202 FF

    Extra flags and OS

    XFL 2 means maximum compression. OS 255 (unknown) is what Python's gzip module writes; GNU gzip writes 3 for Unix. Nothing reads either value when extracting.

  3. 3ED 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. 4E6 F5 71 83 · 00 50 00 00

    The 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. 5header sample-project/README.md

    The 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. 6sample-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.tgz breaks it on purpose.

  7. 7summary.sh, 755

    Permissions 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

SystemEasiest wayCommand line
Windows 11Recent versions: double-click to browse it in File Explorer, or right-click and choose Extract Alltar -xf file.tar.gz in Command Prompt or PowerShell
Windows 10Install 7-Zip: open the .tar.gz, then the .tar inside it, then extracttar -xf file.tar.gz (built in since version 1803)
macOSDouble-click: Archive Utility extracts it into a folder next to the filetar -xf file.tar.gz in Terminal
LinuxDouble-click in the file manager, or right-click and choose Extract Heretar -xf file.tar.gz
PhoneAn 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.gz lists 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.gz leaves file.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.

LetterLong formMeaning
c--createCreate a new archive
x--extractExtract files from an archive
t--listList the contents
z--gzipCompress or decompress with gzip
v--verbosePrint each file name as it's processed
f--fileThe archive file name follows
C--directoryChange 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 -n leaves 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 project works in a terminal.

Related formats

.tar.gz vs ZIP: which should you use?

.tar.gzZIP
How it compressesThe whole archive as one streamEach file separately
Size of our sample project4,273 bytes5,137 bytes (zip -9)
Get one file outDecompress everything before itJump straight to it via the central directory
List the contentsDecompress the whole fileRead the directory at the end
Damage in the middleEverything after it is usually lostOther files still extract
Unix permissions and linksAlways keptOptional; often lost
Opens without extra softwareLinux, macOS, recent Windows 11Everywhere

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.

NameShort formCreate withNotes
.tar.gz.tgztar -czfFast, universal; the default choice
.tar.bz2.tbz2, .tbztar -cjfSmaller, slow to unpack. See bzip2
.tar.xz.txztar -cJfSmall, quick to unpack, slow to create. See XZ
.tar.zst.tzsttar --zstd -cfZstandard: very fast, good ratio; growing in Linux packaging
.tar.Z.taZtar -cZfThe old Unix compress; rare today

Troubleshooting

Common .tar.gz problems

  • gzip: stdin: not in gzip format and Error is not recoverable: exiting now: the file isn't gzip. Either it's a plain tar with a .tar.gz name (try tar -xf without z), the browser already decompressed it during download, or it's an HTML error page. file name.tar.gz tells 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.tgz is built like that. Extract with -C newfolder to keep things tidy.
  • Paths start with ./: archives made with tar -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 .tar file: 7-Zip unwraps one layer at a time. Open the .tar inside to reach the files.
  • Cannot open: File exists or 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.

sample-project.tar.gz · 4.2 KBDownload

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.

  1. One top-level folder

    Everything is under sample-project/, so it extracts into a single folder.

  2. Readable files

    A Markdown README, a changelog, a 240-row CSV of fictional weather readings and a JSON file, all UTF-8.

  3. A PNG that doesn't shrink

    images/logo.png is already compressed, so gzip gains nothing on it; the text files shrink a lot.

  4. An executable script

    scripts/summary.sh is stored with mode 755. After extracting on Linux or macOS, ./sample-project/scripts/summary.sh counts the readings per station.

  5. 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 ./, as tar -czf x.tgz -C folder . makes them. Uses the short .tgz extension.

    • 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.gz should give one sample-project folder with three subfolders and six files.
  • Permissions: on Linux or macOS, ls -l sample-project/scripts/summary.sh should 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.gz is 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

Last reviewed 27 October 2026.