Convert TAR.GZ to TAR.BZ2 Online (Swapping DEFLATE for a Block-Sorting Algorithm)

Why recompressing the same tar stream with bzip2 usually shrinks it further, and what that trade actually costs in time.

  1. Add a file Choose or drop it here
  2. Pick the format Change it whenever needed
  3. Download the result After conversion completes

Same Tar Stream, Two Entirely Different Compression Approaches

Converting TAR.GZ to TAR.BZ2 changes only the compression algorithm wrapped around an identical tar container; the tar layer itself — 512-byte headers recording each file's name, owner, permissions, and size — passes through completely untouched by either compressor. What changes is what happens to the resulting byte stream. Gzip's DEFLATE, specified in RFC 1951, combines LZ77 back-referencing within a 32 KB sliding window with Huffman coding. Bzip2, released by Julian Seward in 1996, works in a fundamentally different way: it applies the Burrows-Wheeler transform to rearrange a data block so that similar byte sequences cluster together, then runs a move-to-front transform and Huffman coding over the rearranged result.

Converting between the two means fully decompressing gzip's DEFLATE stream back into the plain tar bytes, then feeding that exact same tar data through bzip2's block-sorting pipeline instead. Both compressors operate purely on the byte stream tar hands them; neither one has any concept of individual files, so the recompression step treats a ten-file tar archive and a single large file of equal size identically.

Every bzip2 stream begins with the three ASCII bytes "BZh" followed by a digit from 1 to 9 identifying the block size setting used, a fixed, documented signature that any bzip2-aware tool checks before attempting decompression — a direct parallel to gzip's own fixed 0x1F 0x8B magic bytes at the start of every DEFLATE stream, though the two signatures are structured completely differently and aren't interchangeable in any way.


Bzip2's Block Size Limit Against DEFLATE's Sliding Window

Bzip2 processes data in blocks of up to 900 KB before compression at its maximum -9 setting, sorting each block independently through the Burrows-Wheeler transform rather than scanning continuously the way DEFLATE's 32 KB sliding window does. That larger block size lets bzip2 find and exploit redundancy across a wider span of data than gzip's window can reach, which is a major reason bzip2 typically compresses text-heavy and source-code-heavy content noticeably tighter — commonly cited at roughly 20 to 30 percent smaller than gzip on similar data, though the exact gap depends heavily on the specific content.

That improved ratio comes at a real, measured cost: bzip2 compression runs meaningfully slower than gzip, commonly cited at somewhere between four and twelve times slower depending on the data and settings, because the Burrows-Wheeler transform and its sorting step are considerably more computationally expensive than DEFLATE's simpler LZ77 matching. Decompression speed differs less dramatically between the two, though bzip2 still generally decompresses slower than gzip.

Bzip2's block-based design also produces a real, practical side effect DEFLATE's continuous stream doesn't offer: because each block is compressed independently, a bzip2 stream can sometimes be partially recovered even if a later block is damaged or lost, since undamaged blocks earlier or later in the file don't depend on each other the way DEFLATE's single continuous window does. Gzip has no equivalent partial-recovery property; damage to one part of a gzip stream generally makes everything after that point unreadable.

Backup rotation scripts that run overnight, when spare CPU time is plentiful and the resulting archive is read back only rarely, are a documented example of bzip2's slower compression paying off in practice — the one-time cost of a longer overnight compression run buys a smaller footprint across the entire period the backup sits on disk afterward.


What Switching From DEFLATE to Bzip2 Gains and Costs

  • Gain — a smaller file on text-heavy or source-code content: bzip2's larger block size and Burrows-Wheeler transform typically beat DEFLATE's fixed 32 KB window on this kind of data.
  • Lose — compression speed: bzip2 commonly runs four to twelve times slower than gzip, a real cost on large archives or frequent rebuilds.
  • Gain — some resilience to partial corruption: bzip2's independent block structure means undamaged blocks can sometimes still be recovered even if one block is lost.
  • Lose — near-universal default install status: gzip ships by default on virtually every Unix-like system; bzip2 is common but not guaranteed to already be present everywhere gzip is.
  • Gain or lose, depending on content: already-compressed files like photos or videos see little benefit from either algorithm, since neither has much redundancy left to exploit.
  • Unchanged — the actual file contents and tar-layer metadata: both compressors are lossless, and neither touches tar's own header fields at all.

Where Bzip2 Support Is Solid and Where It Isn't Guaranteed

GNU tar supports bzip2 directly through its -j or --bzip2 flag, and its -a / --auto-compress option detects the .tar.bz2 or .tbz2 suffix automatically when creating an archive. Most current Linux distributions and macOS ship bzip2 as part of their base installation or as a near-universal default package, and 7-Zip, WinRAR, and PeaZip all read and write TAR.BZ2 on Windows without extra setup.

The one documented gap worth knowing involves minimal or embedded Linux builds and very old Unix systems, some of which ship gzip by default but omit bzip2 to save space, since bzip2's implementation and memory requirements are larger than gzip's. Someone targeting one of those constrained environments specifically needs to confirm bzip2 is actually installed before assuming a TAR.BZ2 will open the same way a TAR.GZ reliably would.

Bzip2's memory requirements during compression also scale with the block size chosen, and the maximum -9 setting needs roughly 8 times the block size in working memory according to bzip2's own documented design — a genuinely higher resource footprint than DEFLATE's fixed, modest 32 KB window requires, which matters specifically on very constrained hardware even though it's rarely a concern on an ordinary desktop or server.


Real Reasons This Specific Recompression Gets Requested

A common, documented scenario involves distributing source code releases where every extra megabyte matters for download size, and a project maintainer switches from TAR.GZ to TAR.BZ2 specifically because bzip2's tighter compression on source-code-style text produces a meaningfully smaller download for users, even at the cost of the maintainer's own build machine spending more time compressing it once.

A second real pattern involves long-term archival storage, where an archive gets compressed once and read rarely afterward — bzip2's slower compression speed matters far less in that situation than it would for an archive rebuilt frequently, since the one-time cost of tighter compression pays off across years of reduced storage footprint.

A third scenario involves a documented complaint about disappointing results: someone converting a TAR.GZ full of already-compressed media files, expecting bzip2's reputation for better ratios to shrink the archive noticeably, finds almost no size difference at all — both DEFLATE and bzip2 struggle equally against data that's already had its redundancy removed, so the choice of algorithm barely matters for that specific kind of content.

A fourth pattern shows up in package repositories for certain Linux distributions that historically preferred TAR.BZ2 for source packages specifically because of its tighter ratio on the kind of plain-text source code those packages typically contain, even as other distributions and most upstream release pages stayed with the faster, more universally supported TAR.GZ as their own default — a genuine, documented split in convention rather than one format being objectively correct for every use.


DEFLATE's Sliding Window Set Beside Bzip2's Block Sorting

Feature TAR.GZ (DEFLATE) TAR.BZ2 (bzip2)
Core technique LZ77 + Huffman coding Burrows-Wheeler transform + Huffman
Effective search range 32 KB sliding window Up to 900 KB per block
Typical ratio on text Lower Roughly 20-30% smaller
Compression speed Fast 4-12x slower
Partial-corruption recovery Not possible past the damage point Independent blocks sometimes recoverable
Default install base Near-universal Very common, not fully guaranteed

Questions About Recompressing a Gzip Tarball With Bzip2

Will my archive definitely get smaller after converting to TAR.BZ2?
Usually, on text or source-code content, since bzip2's larger block size and Burrows-Wheeler transform generally beat DEFLATE's 32 KB window. Already-compressed data like photos sees little to no improvement either way.

Why does creating a TAR.BZ2 take so much longer than the original TAR.GZ did?
Bzip2's Burrows-Wheeler transform and sorting step are considerably more computationally demanding than DEFLATE's simpler matching, commonly running four to twelve times slower depending on the data.

Is bzip2 installed everywhere gzip is?
Not quite guaranteed. Most current systems have both, but some minimal or embedded Linux builds ship gzip by default while omitting bzip2 to save space.

Can a damaged TAR.BZ2 file still be partially recovered?
Sometimes, because bzip2 compresses independent blocks rather than one continuous stream, so undamaged blocks elsewhere in the file can occasionally still be extracted even if one block is corrupted.

Does this conversion change any of the files inside the archive?
No. Both DEFLATE and bzip2 are lossless compression methods, and neither touches tar's own header structure, so every extracted file matches the original exactly.

Does recompressing with bzip2 take longer on a larger archive?
Yes, roughly proportionally. Since bzip2 sorts data in blocks of up to 900 KB, a larger archive simply means processing more of those blocks, which scales the compression time up accordingly compared with a smaller file.