> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Compression modes

> ClickHouse column compression modes

export const Image = ({img, alt, size}) => {
  return <Frame>
      <img src={img} alt={alt} />
    </Frame>;
};

ClickHouse protocol supports **data blocks** compression with checksums.
Use `LZ4` if not sure what mode to pick.
\`\`

<Tip>
  Learn more about the [column compression codecs](/reference/statements/create/table#column_compression_codec) available and specify them when creating your tables, or afterward.
</Tip>

<h2 id="modes">
  Modes
</h2>

| value  | name               | description                              |
| ------ | ------------------ | ---------------------------------------- |
| `0x02` | [None](#none-mode) | No compression, only checksums           |
| `0x82` | LZ4                | Extremely fast, good compression         |
| `0x90` | ZSTD               | Zstandard, pretty fast, best compression |

Both LZ4 and ZSTD are made by same author, but with different tradeoffs.
From [Facebook benchmarks](https://facebook.github.io/zstd/#benchmarks):

| name              | ratio | encoding | decoding  |
| ----------------- | ----- | -------- | --------- |
| **zstd** 1.4.5 -1 | 2.8   | 500 MB/s | 1660 MB/s |
| **lz4** 1.9.2     | 2.1   | 740 MB/s | 4530 MB/s |

<h2 id="block">
  Block
</h2>

| field            | type    | description                                                                              |
| ---------------- | ------- | ---------------------------------------------------------------------------------------- |
| checksum         | uint128 | [Hash](/resources/develop-contribute/native-protocol/hash) of (header + compressed data) |
| raw\_size        | uint32  | Raw size without header                                                                  |
| data\_size       | uint32  | Uncompressed data size                                                                   |
| mode             | byte    | Compression mode                                                                         |
| compressed\_data | binary  | Block of compressed data                                                                 |

<Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/ddNWBC5mE_w-syUp/images/data-compression/ch_compression_block.png?fit=max&auto=format&n=ddNWBC5mE_w-syUp&q=85&s=07df8605c40448372161213a95cb2e08" size="md" alt="Diagram illustrating ClickHouse compression block structure" width="2048" height="602" data-path="images/data-compression/ch_compression_block.png" />

Header is (raw\_size + data\_size + mode), raw size consists of len(header + compressed\_data).

Checksum is `hash(header + compressed_data)`, using [ClickHouse CityHash](/resources/develop-contribute/native-protocol/hash).

<h2 id="none-mode">
  None mode
</h2>

If *None* mode is used, `compressed_data` is equal to original data.
No compression mode is useful to ensure additional data integrity with checksums, because
hashing overhead is negligible.
