---
title: "bzip2"
description: "Burrows-Wheeler transform then move-to-front then Huffman. Slow and small on text with a CRC on every block"
canonical_url: "https://compressions.agntn.dev/formats/bzip2"
---
# bzip2

> Burrows-Wheeler transform then move-to-front then Huffman. Slow and small on text with a CRC on every block

<format-facts name="bzip2">



</format-facts>

bzip2 doesn't look for repeats the way the LZ77 family does. It sorts. Every rotation of a block gets sorted, and the last column of that sort puts similar contexts next to each other. Then move-to-front turns those runs into small numbers, and Huffman codes eat the small numbers. On text it's a beautiful trick. On short input it's mostly overhead:

```ts
compress("bzip2", "hello world!").length;  // 49 bytes, for 12
```

## Levels

`level` is the block size, from 100 kB at 1 to 900 kB at 9, the default. Bigger blocks sort more context together and compress better, and the reader needs more memory. Below the block size the level changes nothing but the `h1`…`h9` in the header, which comes back as `details.level`.

## Checksums

Every block carries the CRC-32/BZIP2 of its output, the MSB-first one, and the stream ends with a CRC combined from all of them. Both get checked. Streams written one after another, the way `pbzip2` writes them, decompress into one output, and `details.streams` counts them when there's more than one.

Randomized blocks, which bzip2 stopped writing before 0.9.5, are an `UnsupportedError`. Nobody has made one in this century.


## Sitemap

See the full [sitemap](https://compressions.agntn.dev/sitemap.md) for all pages.
