---
title: "LZ4"
description: "Byte-aligned LZ77 with no entropy coding at all. The frame with its XXH32 checks and the legacy frame"
canonical_url: "https://compressions.agntn.dev/formats/lz4"
---
# LZ4

> Byte-aligned LZ77 with no entropy coding at all. The frame with its XXH32 checks and the legacy frame

<format-facts name="lz4">



</format-facts>

LZ4 skips the entropy coding entirely. Every sequence is a token byte, the literals as they are, a two-byte offset and a length. No bits to shuffle, so it reads at close to memory speed, and gives up some size for it.

```ts
compress("lz4", "hello world!");                           // 31 bytes, frame
compress("lz4", "hello world!", { container: "legacy" });  // 21 bytes
```

## Frame

The default. Magic `04 22 4d 18`, a descriptor with its own XXH32 byte, blocks, an end mark, and the XXH32 of the content when `checksum` is on, which it is by default. Turning it off saves four bytes:

```ts
compress("lz4", "hello world!", { checksum: false }).length;  // 27
```

The writer uses 4 MiB independent blocks, the same as `lz4` with defaults. The reader takes linked blocks too, block checksums, a stated content size, and frames in a row. A frame that needs a dictionary is an `UnsupportedError`.

## Legacy

Magic `02 21 4c 18`, then 8 MiB blocks each with its size, and nothing else. No checksum, no end mark. It's what `lz4 -l` writes and what the Linux kernel still boots from when it is built with LZ4.


## Sitemap

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