---
title: "LZMA"
description: "LZ77 with a range coder that learns every bit. The xz container with its checks and filters and the older .lzma"
canonical_url: "https://compressions.agntn.dev/formats/lzma"
---
# LZMA

> LZ77 with a range coder that learns every bit. The xz container with its checks and filters and the older .lzma

<format-facts name="lzma">



</format-facts>

LZMA doesn't write Huffman codes. It keeps a probability for every decision, a literal or a match, which length, which distance, and a range coder spends a fraction of a bit on each one it guessed right. Those probabilities learn as the stream goes, and that's where the size comes from.

```ts
compress("lzma", "hello world!");                       // 30 bytes, .lzma
compress("lzma", "hello world!", { container: "xz" });  // 68 bytes, fd377a585a00…
```

## .lzma

The `alone` container, the default: thirteen header bytes with the `lc`, `lp`, `pb` properties, the dictionary size and the unpacked size, then one LZMA stream. No checksum. It's what LZMA Utils wrote before xz existed, and what plenty of embedded firmware still ships.

```ts
decompress("lzma", compress("lzma", "hello world!")).details;
// { properties: "lc=3 lp=0 pb=2", dictionary: 8388608 }
```

## xz

LZMA2 inside blocks, an index of every block, CRC-32 on every header and a check of your choosing on the data. `check` takes `none`, `crc32`, `crc64` (the default) or `sha256`. On `"hello world!"` that's 60, 64, 68 and 92 bytes.

LZMA2 cuts the stream into chunks, so a chunk that won't compress gets stored as it is instead of growing. Concatenated streams and the padding between them decompress into one output, as `xz -d` reads them.

Filters on the read side: delta and x86 BCJ, mirrored from xz 5.8. ARM, PowerPC, SPARC, IA-64 and RISC-V filters are an `UnsupportedError` that names the filter. The writer uses no filters.

## Levels

`level` from 0 to 9, 6 by default, sets the dictionary and how hard the match finder looks, the same way the xz presets do. The writer is honest and not fast: about 10% bigger than xz on binaries, close on text.


## Sitemap

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