A tarball is a single archive file produced by the tar (tape archive) utility that bundles many files and directories, together with their permissions, ownership and timestamps, into one sequential stream. In software distribution, the word almost always means a compressed tarball such as a .tar.gz file, often called a tar.gz archive, that carries the source code or prebuilt binaries of a release.
Tarballs remain the lowest common denominator of Unix-like distribution: package managers, build systems, container tools and download mirrors all understand them. A project that publishes a versioned source tarball gives packagers and users a fixed, verifiable snapshot of the code that does not depend on access to the version control history.
How a tarball is built from files
A tarball is built in two separate stages: archiving and compression. The tar program first walks a directory tree and writes each file as a 512-byte header block followed by the file contents, padded to a multiple of 512 bytes. The header records the path, mode bits, owner, group, size and modification time, and the archive ends with two blocks of zeros.
The resulting .tar stream is not compressed by itself. A separate compressor such as gzip, bzip2, xz or zstd is then applied to the whole stream, which produces names like project-2.4.1.tar.gz or project-2.4.1.tar.xz. Because compression covers the entire concatenated stream, redundancy across many small files is exploited much better than in formats that compress each file individually.
Several on-disk formats of tar exist, and they differ in how long paths, large files and extended metadata are stored. Modern tools write the POSIX pax format by default or on request, while older archives may use the ustar or GNU variants.
| Format | Defined by | Path length | Notable capability |
|---|---|---|---|
| Original V7 tar | Early Unix | 100 characters | Basic files and links only |
| ustar | POSIX.1-1988 | About 255 characters | Prefix field for longer paths |
| GNU tar format | GNU project | Unlimited via extension | Sparse files and long names |
| pax | POSIX.1-2001 | Unlimited | Extended attributes and precise timestamps |
Compression variants of the tarball
The choice of compressor decides the trade-off between archive size, compression time and decompression speed. Release engineers usually pick one format for the primary download and sometimes offer a second one for compatibility with older systems.
| Extension | Compressor | Relative size | Typical use |
|---|---|---|---|
| .tar.gz or .tgz | gzip (DEFLATE) | Largest of the four | Maximum compatibility, legacy tooling |
| .tar.bz2 | bzip2 | Smaller than gzip | Older source releases, now declining |
| .tar.xz | xz (LZMA2) | Usually the smallest | Linux kernel and many source releases |
| .tar.zst | Zstandard | Close to xz | Fast decompression, Arch Linux packages |
Gzip decompresses quickly and is available everywhere, which explains its persistence. Xz achieves higher ratios at the cost of slow compression and higher memory use, while Zstandard offers tunable levels that combine good ratios with very fast decompression. The difference in size between gzip and xz for a large source tree commonly falls in the range of 20 to 40 percent, depending on the content.
Tarballs compared with other distribution formats
A tarball is a generic container without install logic, which separates it from native package formats. It carries files and metadata, but it does not declare dependencies, run installation scripts or register itself with a package database.
| Format | Dependency metadata | Install scripts | Random access to files |
|---|---|---|---|
| Tarball | None | None | No, sequential stream |
| ZIP archive | None | None | Yes, central directory |
| DEB or RPM package | Yes | Yes | Partial, via package tools |
| Container image layer | Through image manifest | No | No, layers are tarballs |
The sequential design has consequences. Listing or extracting one file from a compressed tarball requires reading the stream from the start, while ZIP can jump to an entry directly. In exchange, tar preserves Unix permissions and symbolic links more faithfully than ZIP, which is why tarballs dominate on Linux and BSD systems. Notably, both DEB packages and OCI container image layers use tar streams internally.
Publishing and verifying a release tarball
A well-published tarball is a release artifact with a stable name and content. Maintainers typically include the project name and version in both the file name and the top-level directory inside the archive, so that extraction creates project-2.4.1/ rather than scattering files into the current directory.
- Publish a checksum file with SHA-256 digests next to every tarball so that downloads from any mirror can be verified.
- Attach a detached signature, for example an OpenPGP
.ascfile or a Sigstore bundle, to prove who produced the archive. - Generate the archive from a tagged commit and record the exact command, which supports reproducible builds.
- Normalize timestamps, ownership and file order so that the same source yields a byte-identical tarball.
Automatically generated archives from code hosting platforms deserve caution. Their bytes can change when the platform updates its compression library, which breaks stored checksums, so serious projects upload their own release tarballs instead of relying on on-the-fly snapshots.
Security risks and common mistakes
Extracting an untrusted tarball is not a neutral operation. Archive entries can contain absolute paths, ../ sequences or symbolic links that point outside the target directory, a class of flaws known as path traversal or tar slip. Current GNU tar and bsdtar strip dangerous prefixes by default, but custom extraction code in applications often does not.
| Symptom | Likely cause | Recommended fix |
|---|---|---|
| Files written outside target | Path traversal entries | Validate paths, use safe extraction filters |
| Checksum mismatch after re-download | Regenerated archive | Publish fixed, uploaded artifacts |
| Wrong owner after extraction as root | Preserved numeric UID | Use options that reset ownership |
| Files spread into current directory | No top-level folder | Archive a single versioned directory |
| Extraction fills the disk | Decompression bomb | Limit size and inspect before extracting |
A further concern is that a source tarball can differ from the repository. The xz backdoor incident of 2024 showed that malicious build files may appear only in the release tarball, not in the public version control tree. Comparing the tarball against the tagged source and favoring reproducible generation reduces this supply-chain risk.
In simple terms
A tarball is like a sealed moving box for files. You put a whole folder, with all its subfolders and labels, into one box, and then you vacuum-pack the box to make it smaller. The person who receives it gets exactly the same folder when they open it.
Software makers use tarballs to hand out a fixed copy of a program at a specific version. A short fingerprint published next to the box lets anyone check that nothing was changed on the way.
A practical example
The maintainers of an open-source image processing library prepare version 3.2.0. Their release script checks out the tagged commit, sets every file timestamp to the commit date, and runs tar with a fixed file order to produce imagelib-3.2.0.tar.xz of about 14 MB, compared with about 19 MB as a gzip archive. The script then writes a SHA-256 checksum file and signs the tarball with the project release key.
A Linux distribution packager downloads the archive from a mirror, verifies the checksum and signature, and builds the package from it. Because the tarball is reproducible, an independent volunteer regenerates it from the same tag and obtains an identical SHA-256 digest, confirming that the published release matches the reviewed source code.