Adler-32 Explained: 5 Facts About the Checksum in Every Zip

Adler-32 explained in plain terms means understanding the checksum that guards every zip file, a design from 1995 that checks data with two running sums and a prime number. The central question is why a checksum would use two sums when one seems enough, and the answer is that two sums catch errors one sum misses, so Adler-32 gives zlib a check that is both fast and surprisingly sharp, and that balance is the whole point of the design.

Adler-32 is a checksum algorithm written by Mark Adler in 1995, built into the zlib compression library he wrote with Jean-loup Gailly. It turns a stream of bytes into a 32-bit value by keeping two 16-bit sums modulo 65521, and it is built on the idea that a checksum should be cheap enough to run on every byte, which means the design trades strength for speed, and that trade is what makes it unlike the checksums of its era.

This article gives you five facts about Adler-32, explains what it is, how it works, and why it still matters.

Key takeaways

  • Adler-32 is a checksum from 1995, by Mark Adler.
  • It keeps two 16-bit sums, A and B, modulo 65521.
  • It is the integrity check at the end of every zlib stream.
  • It is a modified Fletcher checksum, not a hash.
  • It catches accidents, never deliberate tampering.

What Adler-32 is

The first fact is that Adler-32 is a checksum, which means it detects accidents rather than stopping attackers. A hash function resists deliberate forgery, but Adler-32 only catches random corruption, which means it is a tripwire rather than a lock, and because the job is small, the design can be tiny.

The second fact is that it keeps two sums. Adler-32 tracks A, the sum of all bytes plus one, and B, the running sum of A after each byte, which means the value depends on both the bytes and their order, and because B weights early bytes more heavily, a swapped pair changes the result.

The third fact is that its modulus is prime. Adler-32 reduces both sums modulo 65521, the largest prime below 65536, which means the values spread evenly instead of clumping, and because the modulus is prime, the checksum catches more errors than the 65535 its ancestor used.

The fourth fact is that it lives at the end of every zlib stream. A zlib stream is a two-byte header, DEFLATE-compressed data, and a four-byte Adler-32 trailer, which means every zip file and every PNG image carries one, and because the trailer is checked on decompression, a damaged file is caught before it is used.

The fifth fact is that it is weak on short inputs, and it never pretends otherwise. Adler-32 is a poor check for very short strings, which means it must never be the only guard on small data, and that honesty is the reason it is the first example engineers meet when they learn the line between a checksum and a hash.

Our guide to hashing explains what a hash function does in the first place, and our guide to SeaHash explains the fast hash built for tables and checksums.

How Adler-32 works

Everything starts with one and zero, which are the initial sums. Adler-32 sets A to 1 and B to 0 before reading any input, which means the empty message still has a checksum, and because A starts at one instead of zero, the checksum depends on the data length.

Each step begins with a byte, which is added to A. Adler-32 takes the next byte and adds it to the running sum, which means fresh data arrives at every step, and because the add is modulo 65521, the sum never grows past the prime.

The second sum is what makes the design work as a whole. After each byte updates A, the new A is added into B, which means B is a weighted sum where earlier bytes count more times, and because the weighting depends on position, the order of the bytes matters as much as their values.

The modulo spreads the effect further. Both sums are reduced modulo 65521, which means the values stay inside 16 bits, and because the modulus is prime, the reduction spreads the sums evenly instead of bunching them.

The combination is what turns the sums into a checksum. Adler-32 packs B into the high 16 bits and A into the low 16 bits, which means the result is a single 32-bit word, and because the packing is fixed, the same data always gives the same checksum.

The result comes from the packed sums, read out as a 32-bit number. Adler-32 outputs B times 65536 plus A, which means the checksum of the word Wikipedia is 0x11E60398, and that value is exactly what a decompressor needs to check its data.

A dark office desk with a laptop showing a glowing green cipher diagram, a brass key and a notebook beside it
A dark office desk with a laptop showing a glowing green cipher diagram, a brass key and a notebook beside it, shows how Adler-32 works: bytes take turns adding to the two running sums, byte after byte, until a checksum emerges.

Comparing Adler-32 with other checksums

Adler-32 is one of several checksums built for integrity, and each was built with a different emphasis. Fletcher-32 is the older checksum built on 16-bit words modulo 65535, CRC-32 is the polynomial checksum built for error detection, and Adler-32 is the one built for speed in zlib, while each approach trades something for something else.

The table below sets out the main contrasts between the leading approaches.

Aspect Adler-32 Fletcher-32 CRC-32
Output size 32 bits 32 bits 32 bits
Modulus 65521, prime 65535 Polynomial
Speed Very fast Fast Slower in software
Year 1995 1970s 1961
Best for zlib streams Simple checksums Error detection

The practical result is that Adler-32 is the right choice for zlib streams, Fletcher-32 suits simple checksums, and CRC-32 fits error detection instead.

Where Adler-32 is used

zlib uses it as its integrity check. Every zlib stream ends with a four-byte Adler-32 of the uncompressed data, because a decompressor must know its output matches the original, and that check is the reason Adler-32 runs in real software rather than only in papers.

PNG images use it inside their compressed data. A PNG file stores its pixels with zlib compression, because the format needs a fast check on every image, and that trailer is the reason Adler-32 appears in every picture on the web.

Zip tools use it to verify archives. A zip reader checks the Adler-32 of each entry, because a damaged archive must be caught before it is unpacked, and that verification is the reason Adler-32 earns its keep in file tools.

Network code uses it to check streams quickly. A protocol that moves compressed data wants a check that costs almost nothing, because a slow check becomes the bottleneck, and that speed is the reason Adler-32 appears in data pipelines.

Teaching uses it as the two-sum example. Courses introduce Adler-32 when they explain that a checksum can use position as well as value, because it is the clearest case of the idea in a real design, and a student who understands Adler-32 understands why two sums beat one.

Strengths and limits

The greatest strength of Adler-32 is its speed. A checksum that needs only two additions per byte gives programs a nearly free integrity check, and that strength is real, measured in the thirty years it has guarded zlib streams and confirmed by the formats that rely on it.

It is also a strength that the design is trivial to explain. Two sums and a prime modulus is a design anyone can describe, and that simplicity is worth more than cleverness in a field where a checksum nobody can audit is a checksum nobody trusts.

The limits are real, though, and the biggest is that it is not cryptographic. Adler-32 was never designed to resist an attacker, which means it must never guard anything an attacker can influence, and a system that needs tamper evidence must use a cryptographic hash instead.

Adler-32 checklist

  • Use Adler-32 for integrity checks, never for security.
  • Remember it outputs 32 bits from two 16-bit sums.
  • Note the modulus is 65521, the largest prime below 65536.
  • Compare it with Fletcher-32 to see two kinds of checksum.
  • Study the second sum, which is what catches reordering.
  • Check the length, since short inputs weaken the check.
  • Keep real digests behind cryptographic hashes for signatures.
  • Read RFC 1950 to see how the zlib format uses it.
  • Choose CRC-32 when stronger error detection is needed.

Frequently asked questions

What is Adler-32 in simple terms?

It is a 1995 checksum that turns any stream of bytes into a 32-bit value using two running sums modulo 65521.

Who created Adler-32?

Mark Adler, who wrote it for the zlib library he built with Jean-loup Gailly.

How is Adler-32 different from Fletcher-32?

Both use two sums, but Adler-32 works on bytes modulo a prime while Fletcher-32 works on 16-bit words modulo 65535.

Is Adler-32 still secure?

It is fast and widely used, but it is a checksum rather than a hash, so it must never guard secrets or detect tampering.

Where is Adler-32 used?

In zlib streams, in PNG images, in zip archives, in network code, and in teaching about checksums.

When should I use Adler-32?

When you need a fast integrity check, when you work with zlib data, or when you study two-sum checksum design.

The bottom line

Adler-32 explained in one line is this: the two-sum checksum, a 1995 design of running totals and a prime modulus that guards every zip file and taught the field that two sums beat one.

It is proof that simple can be enough, and the reason it still matters is that every checksum designed since has been judged partly by the lesson Adler-32 taught.

This article is general information about how Adler-32 works, not advice about choosing encryption for a particular device or system.

Latest articles

Scroll to Top