A .bz2 file is a single file compressed with bzip2. It is not an archive: there is exactly one file inside, and if that file is a TAR archive, the result is the familiar .tar.bz2 (or .tbz2). You find bz2 in Linux source packages, older distribution mirrors, scientific and log data, and in large public data dumps; Wikimedia, for example, publishes its database dumps as .xml.bz2.
History
bzip2 was written by the British developer Julian Seward. The first public version appeared in 1996, version 1.0 in 2000, and the current stable release is 1.0.8 from 2019, today maintained at Sourceware. It replaced Seward's earlier program bzip, which used arithmetic coding; because of patent concerns bzip2 switched to Huffman coding, and the two formats are incompatible (see BZ). bzip2 is free software under a BSD-style licence. For many years it was the "better gzip" of the Unix world, until xz and zstd took over most new uses after 2010.
How bzip2 compresses
The data is split into blocks of 100 to 900 kB (switch -1 to -9, default 900 kB). Each block goes through the Burrows–Wheeler transform, which sorts the text so that identical characters end up next to each other, then move-to-front coding, run-length encoding and finally Huffman coding.
- Ratio: on text, source code and logs typically clearly better than gzip, usually somewhat worse than xz.
- Speed: compression and especially decompression are several times slower than gzip and much slower than zstd. Parallel versions (pbzip2, lbzip2) use all CPU cores.
- Independent blocks: damage affects only the block it is in. The included tool
bzip2recoverextracts the intact blocks from a damaged file. - No file name: bzip2 does not store the original name or folder structure. The name is derived from the .bz2 file name by removing the extension, so renaming the .bz2 renames the result.
Opening BZ2 files
Linux and macOS: bunzip2 file.bz2 (or bzip2 -dk to keep the original); tar -xf file.tar.bz2 unpacks archives directly. On macOS a double-click in Finder also works. Windows: 7-Zip opens .bz2; for a .tar.bz2 it first shows the inner .tar, which you open again. Windows 11 (version 23H2 and newer) extracts .tar.bz2 in File Explorer, and the tar command is available in Windows 10 and 11. Phones need a third-party archiver app.
Common problems
"bzip2: Data integrity error when decompressing"
The file is damaged or incomplete, typically a broken download. Download again and compare with the published checksum. If that is not possible, bzip2recover saves at least the undamaged blocks.
After extraction the file has no extension
The .bz2 file was named without the inner extension (for example report.bz2 instead of report.csv.bz2). Add the right extension by hand.
Decompression takes very long
bzip2 is single-threaded. For large files use lbzip2 or pbzip2, which decompress in parallel.
Converting BZ2
Typical reasons: BZ2 to ZIP for Windows users and phones, BZ2 to gz, xz or zst for tools that do not read bzip2 or for faster decompression. Our converter decompresses the file (unpacked size up to 2 GB, uploads up to 100 MB). If the content is a TAR archive, it is unpacked and its files are packed into the new format. If it is a single plain file, keep in mind that bzip2 does not remember the name: in a ZIP or 7z the file will be called data and you rename it after extracting. Conversions between single-file compressors (bz2 to gz, xz, zst) simply recompress the content. In the other direction, when you convert a multi-file archive to BZ2, we pack the files into TAR first, so the result is really a tar.bz2; choose the TBZ2 target if you want the correct extension right away.
| BZ2 in brief | |
|---|---|
| Developer | Julian Seward |
| First release | 1996; current version 1.0.8 (2019) |
| Type | compression of a single file (no archive) |
| Compression | Burrows–Wheeler transform, move-to-front, Huffman; blocks of 100–900 kB |
| Signature | BZh |
| MIME type | application/x-bzip2 |
| Typical use | tar.bz2 packages, data dumps, log archives |
More: bzip2 project page and bzip2 (Library of Congress).