File Extension File Extension Guide

What is an XZ File?Compressed

A .xz file is a single file squeezed down by XZ Utils using the LZMA2 algorithm. It packs tightly and loses nothing, which is why Linux software and backups lean on it. This page shows how to extract one and how it differs from .gz and .tar.xz.

Compressed file 🗜️ LZMA2 algorithm 📦 Single file, not an archive ✓ Lossless
.XZ

XZ File

Type:Compressed file
Extension:.xz
Tool:XZ Utils
Algorithm:LZMA2, lossless
Holds:One compressed file

🗜️ What is an XZ File?

An XZ file, ending in .xz, is a piece of data that a tool called XZ Utils has shrunk down. It uses a method named LZMA2 to shrink data as much as possible while keeping every byte intact.

Compression means rewriting a file so it takes up less room, and XZ is known for doing this aggressively. The payoff is a noticeably smaller file, which makes an .xz quicker to download, cheaper to store and easier to move around. Because the compression is lossless, unpacking the file gives you back the exact original with nothing changed, so it suits program code, documents and backups where an approximate copy would be useless.

You meet .xz files most often in the Linux world, where a great deal of software is handed out in this form. The format came from the XZ Utils project, which built on an earlier compression method called LZMA to produce something with an even better size reduction. What trips people up is that a plain .xz holds just one file inside it, so the next few sections clear up that point, show how it stacks up against the older .gz format and walk through unpacking one.

💡 In short: An .xz file is one file compressed with XZ Utils and its LZMA2 method. It gets you a small, lossless copy that unpacks back to the original exactly.

📌 XZ File Quick Facts

Full nameXZ compressed file
Made byXZ Utils
MethodLZMA2, short for Lempel-Ziv-Markov chain algorithm 2
CompressionLossless, the original is restored exactly
HoldsA single compressed file, not a folder of files
Common onLinux, for software, packages and backups
Extract withunxz, xz -d, or tar for a .tar.xz

📦 One File, Not an Archive

The most important thing to grasp about .xz is that it compresses a single file and nothing more. It is a squeezer, not a bundler.

Some formats do two jobs at once, gathering many files into one package and shrinking them together. A plain .xz does not work that way. Point it at one file and you get that one file, smaller. It has no concept of folders or of holding several files side by side, so on its own it cannot wrap up a whole project or directory. This is the same limitation the older .gz format has, and it is deliberate, since each tool is built to do one thing well.

So how does software get shipped as a single tidy .xz when it clearly contains many files? The answer is that a second tool does the gathering first. A program called tar collects all the files and folders into one continuous file, and only then does xz compress that. The result carries two extensions, .tar.xz, and the section further down explains exactly how that pairing works. For now the rule to remember is simple, a lone .xz is one compressed file, while anything holding multiple files has been bundled by tar beforehand.

⚠️ Key point: A plain .xz contains exactly one compressed file. To pack many files together you first bundle them with tar, which gives you a .tar.xz.

⚖️ XZ vs GZ

The format people most often weigh against .xz is .gz, produced by the older gzip tool, and picking one over the other is really a question of size against speed.

Both take a single file and compress it losslessly, so in everyday use they feel alike. The difference is in the engine. The LZMA2 method behind xz works harder and squeezes the data further, so an .xz is usually smaller than the same content saved as a .gz. That extra shrinking has a cost, because xz takes longer to compress in the first place. Gzip is the opposite, quicker to compress but leaving a larger file. Unpacking is less of a worry either way, since xz decompresses at a reasonable pace despite the heavier work done up front.

Which one to reach for depends on what you care about. When the goal is the smallest possible download or the tightest backup, and you can spare the time to create it, xz wins on size. When you want something compressed quickly, or you are handling files that change constantly, gzip's speed can matter more. This is why large Linux downloads, where every saved megabyte helps and the file is packed just once, so often arrive as .xz.

AspectXZ (LZMA2)GZ (gzip)
File size SmallerLarger
Compression speedSlower Faster
DecompressionReasonably fastFast
Best whenSize matters mostSpeed matters most

🧩 Understanding tar.xz

Once you know that .xz handles only one file, the double extension .tar.xz makes perfect sense, because it is two tools working in turn.

Reading the name from the inside out tells the story. First tar takes a pile of files and directories and threads them into one long file, traditionally called a tarball, which preserves their names and folder structure but does not make them any smaller. Then xz compresses that single tarball down to size. So a .tar.xz is a bundle of many things that has then been squeezed, which is why it is the natural choice for shipping software or a folder of data as one small download. You may also see the shorter form .txz, which means the same thing.

The practical upshot is that the two extensions tell you what you are holding. A file ending in just .xz is a single compressed file that unpacks to one file. A file ending in .tar.xz is a compressed bundle that unpacks first to a tarball and then to all the original files and folders inside. Knowing which you have tells you exactly which command to use, which the next section covers.

📂 How to Extract an XZ File

Unpacking an .xz is quick, and the exact step depends only on whether you have a plain .xz or a .tar.xz, and on your operating system.

On Linux and Mac

These systems usually have the tools built in. For a plain .xz, the unxz command turns file.xz back into file, and xz with the -d flag does the same. Add a -k flag if you want to keep the compressed copy as well as the unpacked one. For a .tar.xz, the tar command handles both steps in one go, decompressing and unbundling together, and modern versions work out the xz part on their own.

Unpacking on Linux or Mac

# Decompress a plain .xz file
$ unxz file.xz
$ xz -d file.xz

# Keep the original .xz as well
$ xz -dk file.xz

# Extract a .tar.xz archive (many files)
$ tar -xf archive.tar.xz

If your system reports that xz support is missing, the small xz-utils package adds it. You install it with sudo apt install xz-utils on Debian or Ubuntu, or sudo dnf install xz on Fedora and Red Hat systems, though on most Linux installations it is already present.

On Windows

Windows does not open .xz on its own, so you use a free tool such as 7-Zip, WinRAR or WinZip. With 7-Zip you right-click the file, hover over the 7-Zip menu and choose Extract Here. One quirk with a .tar.xz is that 7-Zip peels off the .xz layer first, leaving a .tar file, so you simply right-click that .tar and extract it a second time to reach the actual files.

💡 Good to know: A double-click rarely works for .xz on Windows. Install 7-Zip once and extracting these files becomes a quick right-click, with a second extract needed only for the .tar inside a .tar.xz.

🛠️ How to Create an XZ File

Making an .xz is the mirror image of unpacking one, and again the command depends on whether you are squeezing a single file or bundling a folder.

To compress one file, you hand it to the xz command and it replaces the original with a smaller .xz version. If you would rather keep the original alongside the compressed copy, the -k flag does that. To wrap a whole folder into one compressed file, you let tar gather everything and call xz in the same step, which produces the .tar.xz you see so often. The commands below cover both cases.

Creating a compressed file

# Compress one file (original is replaced by file.xz)
$ xz bigfile.log

# Compress but keep the original too
$ xz -k bigfile.log

# Bundle a whole folder into one .tar.xz
$ tar -cJf project.tar.xz project/

In that last command the letters each do a job, with c telling tar to create, J telling it to run the result through xz and f naming the output file. Once you can create and extract these files, the only thing left worth knowing is how to trade compression strength against time, which is the next section.

🎚️ Compression Levels and Speed

By default xz aims for strong compression, but you can dial that up or down, trading how small the file gets against how long it takes to make.

The strength is set by a number from 0 to 9, written as a flag such as -0 or -9. A low number is quick but leaves a bigger file, while -9 squeezes hardest and takes the longest, with -6 being the sensible default that runs if you pick nothing. There is also an -e flag for extreme mode, so -9e wrings out a little more size at the cost of noticeably more time, though the extra saving is usually small. Higher levels also lean on more memory, and -9 can ask for a lot of RAM on a big file.

Since xz is slower than lighter tools, it helps that it can spread the work across processor cores. The -T flag turns on that multithreaded mode, and -T0 tells it to use every core available, which cuts the waiting time on a modern machine considerably. You can also peek at a compressed file without unpacking it, listing its details with -l, checking it is not damaged with -t, or streaming its contents straight to the screen or another program with xzcat.

Tuning and checking

# Fastest, weakest compression
$ xz -0 bigfile.log

# Maximum, with extreme mode, using all cores
$ xz -9e -T0 bigfile.log

# Show stats, test integrity, print contents
$ xz -l bigfile.log.xz
$ xz -t bigfile.log.xz
$ xzcat bigfile.log.xz
💡 Rule of thumb: Level -6 suits most jobs. Reach for -9e only when the very smallest file is worth a long wait, and add -T0 to spread the effort across your processor cores.

📊 XZ vs gzip, bzip2 and zstd

On Linux four compressors show up again and again, gzip, bzip2, xz and zstd (short for Zstandard), and each strikes a different balance, so it is worth knowing where xz sits among them.

Four Linux compressors: size vs speed ← smaller files faster → xz  (LZMA2) Smallest files, slowest to compress · software releases, long-term storage zstd Nearly as small at high levels, fast both ways · the balanced all-rounder gzip Largest files, quick and everywhere · quick jobs and wide compatibility bzip2 Middling size, slow · mostly seen now in older files

The way to read the group is as a spread from smallest to fastest. For sheer size, xz leads the pack, producing the tightest files thanks to LZMA2. zstd, a newer arrival, gets close to xz on size at its higher settings while staying much faster to both compress and unpack, which is why many people now treat it as the balanced default. gzip is the old reliable, quick and installed almost everywhere but leaving the largest files, and bzip2 sits in the middle on size while being slow, so these days you mostly meet it in older downloads rather than new ones. All four pair with tar in the same way, so an archive might arrive as .tar.gz, .tar.bz2, .tar.xz or .tar.zst.

The practical takeaway is that xz earns its place wherever the file will be made once and downloaded many times, and a smaller size pays off on every download. When you instead want speed, or a good balance of both, zstd or gzip may serve better, which is exactly why a Linux kernel release ships as .tar.xz while a constantly written log might be squeezed with something quicker.

ToolFile sizeSpeedTypically used for
xz SmallestSlowest to compressSoftware releases, archives
zstdSmall at high levels Fast both waysBalanced, general use
gzipLargestFastCompatibility, quick jobs
bzip2MediumSlowOlder files

🎯 Where XZ Is Used

XZ turns up wherever small file size is the priority and a little extra time to compress is acceptable, which describes a lot of what happens on Linux.

Its biggest home is software distribution. Countless Linux programs, source code releases and packages are handed out as .tar.xz, because the format shaves real space off large downloads and the file is only ever compressed once at the source. Many Linux distributions themselves ship components this way, and the Linux kernel is offered as a .tar.xz download. Beyond software, xz is a common choice for backups and log files, where squeezing archives as tightly as possible saves storage over time, and for moving large files across a network, where a smaller size means a faster transfer. In each of these the appeal is the same, xz trades a bit of compression time for a smaller result, and that is exactly the bargain these jobs want.

🔐 Is XZ Safe? The 2024 Backdoor

If you have read about a security scare involving xz, it is worth being clear about what happened, because the headline is easy to misread.

In March 2024 a developer spotted hidden malicious code that had been slipped into the XZ Utils software itself, in two specific releases numbered 5.6.0 and 5.6.1. It was logged as CVE-2024-3094 and rated at the top of the severity scale, because the planted code could have let an attacker reach affected machines through their remote login service. The important part is that this was tampering with the compression tool during its own build, not anything to do with ordinary .xz files. A normal .xz you download or receive cannot carry this problem, and opening one does not expose you to it.

The story ended quickly and well. Because the bad code only reached test and cutting-edge versions of a few Linux systems rather than the stable releases most people run, and because it was caught within days, the affected package was pulled and reverted almost at once. Everyday users of xz were largely never exposed. The lasting lesson is a general one about software supply chains rather than a reason to distrust the format, and the sensible habits are the same as always, keep your system updated and get software from official sources.

💡 The short version: The 2024 issue was malicious code hidden inside two releases of the xz tool, not a danger in .xz files. Opening or downloading a normal .xz file is safe.

❓ Frequently Asked Questions

.xz vs .tar.xz .xz  (one file) one file ↓  xz file.xz one file, smaller .tar.xz  (a bundle) file file folder ↓  tar bundles tarball (.tar) ↓  xz compresses archive.tar.xz

An XZ file, with the .xz extension, is a file that has been compressed by a tool called XZ Utils using a method named LZMA2. Compressing it makes the file smaller so it downloads faster and takes less storage, and the process is lossless, meaning unpacking it restores the original exactly with nothing lost. A plain .xz holds a single compressed file rather than a group of files. It is most common on Linux, where a lot of software and many backups are distributed in this form because of the tight size it achieves.

It depends on your system and whether the file is a plain .xz or a .tar.xz. On Linux or Mac, a plain .xz unpacks with the unxz command or with xz -d, and adding -k keeps the compressed copy too. A .tar.xz is handled by the tar command, which decompresses and unbundles in one step. On Windows there is no built-in support, so you install a free tool like 7-Zip, then right-click the file and choose Extract. With a .tar.xz in 7-Zip you extract twice, once to get the .tar and once more to reach the files inside it.

A plain .xz is a single compressed file, since xz on its own squeezes one file and does not bundle several together. A .tar.xz is two tools combined, where tar first gathers many files and folders into one tarball and xz then compresses that tarball. So a .xz unpacks to one file, while a .tar.xz unpacks to a whole set of files and directories. The shorter name .txz means the same as .tar.xz. Checking whether the name ends in .xz or .tar.xz tells you at a glance whether you are dealing with one file or a bundle.

Neither is simply better, they make different trade-offs. The LZMA2 method behind xz compresses harder, so an .xz is usually smaller than the same content as a .gz, but it takes longer to create. Gzip is faster to compress yet leaves a larger file. For a big download that is packed once at the source and fetched many times, the smaller .xz is the sensible pick. For files that change often or need compressing quickly, gzip's speed can be the better bargain. Both are lossless and both unpack cleanly, so the decision really rests on whether size or speed matters more for the job.

Usually not on Linux or Mac, where the tools tend to be present already. If a Linux system reports that xz support is missing, you add the small xz-utils package, using sudo apt install xz-utils on Debian or Ubuntu and sudo dnf install xz on Fedora or Red Hat. On Windows there is nothing built in, so you install a free archiver such as 7-Zip, WinRAR or WinZip once, after which extracting an .xz becomes a simple right-click. Some cloud storage services also unpack these files for you automatically when you download them.

Because the format is built for exactly this situation. A software release is compressed just once at the source and then downloaded by huge numbers of people, so spending extra time to make the file as small as possible pays off every time someone fetches it. The tight size xz achieves means smaller downloads and less bandwidth for everyone. That is why source code, packages, many Linux distributions and even the Linux kernel are commonly offered as .tar.xz. The trade of slower compression for a smaller file fits software distribution almost perfectly.

For a single file you run xz followed by the file name, and it replaces the original with a smaller .xz copy. Add the -k flag if you want to keep the original as well as the compressed version. To pack a whole folder into one compressed file you let tar do the gathering and call xz in the same command, with tar -cJf project.tar.xz project/, which produces the familiar .tar.xz. In that command c means create, J routes the bundle through xz and f names the file you end up with. So a lone file becomes a .xz, while a folder becomes a .tar.xz.

They set how hard xz works, on a scale written as -0 through -9. A low number compresses quickly but leaves a larger file, while -9 squeezes the hardest and takes the longest, and -6 is the default that runs when you choose nothing. Adding an e, as in -9e, turns on extreme mode for a little more shrinking at the cost of noticeably more time, though the extra saving tends to be small. Higher levels also use more memory. For most jobs the default is fine, and -9e is worth it only when the smallest possible file really matters.

Yes, and it makes a real difference given that xz is on the slow side. The -T flag switches on parallel compression, and -T0 tells xz to use every processor core the machine has, which cuts the waiting time on a modern multi-core system by a wide margin. You can also name a specific number, such as -T4, to leave some cores free for other work. This threading is available in xz version 5.2 and later, which covers most current systems, so combining it with a high level like -9e -T0 gives strong compression without the full time penalty.

It comes down to what you value. xz produces the smallest files of the common tools, so it wins when a release is compressed once and downloaded many times and every saved megabyte counts. zstd is newer and gets close to xz on size at its higher settings while being much quicker to compress and unpack, which makes it a strong all-round choice, especially for things like backups and logs that are created constantly. A rough guide is to pick xz when the absolute smallest size matters most and you can spare the time, and zstd when you want a fast tool that is still very space-efficient.

xz has a few options for looking without extracting. Running xz -l on a compressed file lists details such as its sizes and compression ratio. Running xz -t tests the file to confirm it is not damaged, which is handy after a download before you rely on it. If you want to read the contents without writing an unpacked copy to disk, xzcat streams them straight to the screen or on to another program, and for a .tar.xz the command tar -tJf lists the files inside without unpacking any of them. These checks are quick and leave the compressed file untouched.

Yes. The 2024 incident, tracked as CVE-2024-3094, was malicious code hidden inside two specific releases of the XZ Utils software, versions 5.6.0 and 5.6.1, not a flaw in .xz files themselves. It affected the tool during its own build and could have exposed some systems through their remote login service, but it only reached test and cutting-edge versions of a few Linux distributions and was caught and reverted within days. Opening or downloading an ordinary .xz file does not put you at risk from it. As always, the sensible habits are to keep your system updated and get software from official sources.

Key Takeaways

An .xz file is a single file compressed by XZ Utils with the LZMA2 method, giving a small, lossless copy that unpacks back to the original exactly.

A plain .xz holds just one file, so to pack many files together you bundle them with tar first, which produces a .tar.xz.

You extract a plain .xz with unxz or xz -d on Linux and Mac, a .tar.xz with tar, and a free tool like 7-Zip on Windows, choosing .xz over .gz when a smaller file matters more than compression speed.