---
title: "CRC-32"
description: "The error-detection checksum in every ZIP and PNG and gzip, and unreflected in bzip2. Four bytes and useless against an attacker"
canonical_url: "https://hashes.agntn.dev/algorithms/crc32"
---
# CRC-32

> The error-detection checksum in every ZIP and PNG and gzip, and unreflected in bzip2. Four bytes and useless against an attacker

<algorithm-facts name="crc32">



</algorithm-facts>

The IEEE CRC-32, the one in ZIP, PNG, gzip and Ethernet. It catches accidental bit flips and nothing else. Anyone can forge a CRC-32 in microseconds, since it's linear.

```ts
create("crc32").hash("123456789").digest; // "cbf43926", the standard check value
create("crc32").hash("The quick brown fox jumps over the lazy dog").digest; // "414fa339"
create("crc32").hash("123456789", { variant: "bzip2" }).digest; // "fc891918"
```

The avalanche panel on the landing makes the linearity visible. Flip one input bit and the CRC changes by a pattern that depends only on where that bit sat, not on the rest of the input. A real hash moves a random half. Printed big-endian, as `crc32` tools write it.

## Variants

`variant` picks which CRC-32. The names come from the CRC catalogue.

<table>
<thead>
  <tr>
    <th>
      <code>
        variant
      </code>
    </th>
    
    <th>
      Who uses it
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        iso-hdlc
      </code>
      
       (default)
    </td>
    
    <td>
      zlib, gzip, ZIP, PNG, Ethernet
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bzip2
      </code>
    </td>
    
    <td>
      bzip2, after every block and once more for the stream
    </td>
  </tr>
</tbody>
</table>

Same polynomial, same all-ones start and finish. bzip2 just reads the bits the other way round, so the answer is different. A checksum from a `.bz2` file that matches neither is usually the stream CRC, which rotates the running value left by one bit before each block's CRC goes in. One block and the two agree.


## Sitemap

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