> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-parallel-read-in-order-multi-part.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 = "lg", background}) => {
  const normalizedSize = ["sm", "md", "lg"].includes(size) ? size : "lg";
  const backgroundColor = background === "white" ? "white" : background === "black" ? "rgb(31 31 28)" : undefined;
  return <div className={`ch-image-${normalizedSize}`}>
      <Frame>
        <img src={img} alt={alt} style={{
    backgroundColor
  }} />
      </Frame>
    </div>;
};

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/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-parallel-read-in-order-multi-part/b9t4X-bLnM5vyVT7/images/data-compression/ch_compression_block.webp?fit=max&auto=format&n=b9t4X-bLnM5vyVT7&q=85&s=50135d1203dbdcf5d1596ef9b342b306" size="md" alt="Diagram illustrating ClickHouse compression block structure" width="2048" height="602" data-path="images/data-compression/ch_compression_block.webp" />

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.
