What is the BZ2 file format?
.bz2 is a compressed file format produced by the bzip2 utility. Unlike a full archive, it compresses a single file or data stream - when multiple files need packaging, they are first bundled into a TAR archive and then compressed together, producing the .tar.bz2 (or .tbz2) packages seen across Linux distributions and open-source projects.
What data does a .bz2 file contain?
.bz2 files store data compressed using a pipeline of lossless algorithms:
- Burrows-Wheeler Transform (BWT) - reorganizes data blocks to cluster repeated byte sequences
- Move-to-front transform - exploits the locality produced by BWT
- Run-length encoding (RLE) - collapses long runs of identical bytes
- Huffman coding - entropy-codes the resulting symbol stream
Block sizes range from 100 KB to 900 KB and are selected at compression time; the default bzip2 command uses 900 KB blocks (file signature BZh9). Each block carries its own CRC-32 checksum, and a second stream-level CRC covers the whole file. The bzip2recover utility can salvage intact blocks from a partially damaged archive.
.bz2 on Unix-like systems
.bz2 files are typically found on Linux, macOS, and other Unix-like environments, where bzip2 and bunzip2 are standard CLI tools. The format is widely used for distributing software source code on such platforms.
Windows support
On Windows, .bz2 files are supported by tools such as 7-Zip, WinRAR, and PeaZip. The bzip2 utility itself is also available as an open-source Windows build. Compared to .gz files, .bz2 typically achieves a better compression ratio on text and source code, at the cost of slower compression and decompression. Newer formats such as .xz now often surpass bzip2 in both compression ratio and speed, but .tar.bz2 packages remain widely used in open-source software distribution. .bz2 files can also serve for creating backup copies of various data, such as picture collections or document libraries.
Security & safety
RISK: LOWThe bzip2 format is open and safe, and a .bz2 is just compressed data that can't run on its own. The usual archive cautions apply: a .bz2/.tar.bz2 from an untrusted source can contain executables or scripts revealed only after extraction, so scan the contents before running anything. Two technical notes: a tiny .bz2 can expand enormously ('decompression bomb') - be wary of suspiciously small archives; and a .tar.bz2 can contain '../' paths (path-traversal / 'tar slip'), so extract untrusted tarballs into an empty folder. Modern extractors guard against both.
Format details
in a nutshellPrograms that open BZ2 files
Technical details
deep spec| MIME type | application/x-bzip2 (also application/x-bzip, application/bzip2) |
| Magic bytes | 42 5A 68 ("BZh") at file offset 0, followed by an ASCII digit '1'-'9' encoding the block size (e.g. BZh9 = 900 KB blocks) |
| Encoding | Binary - bit-packed compressed stream |
| Compression pipeline | Burrows-Wheeler Transform → move-to-front → run-length encoding → Huffman coding (all lossless stages) |
| Block size | Selectable from 100 KB (level 1) to 900 KB (level 9); default is 900 KB; larger blocks improve ratio but require more RAM |
| Memory usage | Compression: approximately 10× the block size; decompression: ~3.5 MB regardless of block size chosen |
| Integrity checking | CRC-32 checksum per compressed block plus a combined stream-level CRC verified on decompression |
| Block marker | Each BWT block begins with the 48-bit pi constant 0x314159265359, used by bzip2recover to locate blocks in damaged files |
| Container model | Standalone compressed stream with no internal filename table or directory structure; multiple files need a TAR wrapper |
| Parallel compression | Standard bzip2 is single-threaded; pbzip2 and lbzip2 parallelize block-level compression on multi-core systems |
| Block recovery | bzip2recover scans raw bytes for 48-bit block markers and writes each intact block to a separate recoverable .bz2 file |
| Compression ratio vs. gzip | Typically 10-15% smaller than .gz on text and source code; decompression is 2-6× slower |
| Associated platforms | Linux, macOS, Unix/BSD natively; Windows via 7-Zip, WinRAR, PeaZip; bzip2 CLI available for all major systems |
| Common use cases | Linux/Unix source tarballs (.tar.bz2), software distribution packages, database dumps, and compressed log archives |
| Released | 1996 (bzip 0.21); bzip2 1.0 released 2000 |
| Latest version | bzip2 1.0.8 (2019); format itself unchanged |
| Open standard | Yes · royalty-free |
| Specification | sourceware.org |
BZ2 conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about BZ2 files.