Skip to content

checksum

A checksum is a small, fixed-size value computed from a block of data and stored or sent alongside it, so that a later recomputation can reveal whether the data changed by accident.

The sender or writer runs the data through a checksum algorithm and records the result. The receiver or reader runs the same algorithm over the data it got and compares the two values. A mismatch proves the data was altered, while a match only makes corruption unlikely, because many different inputs share each possible checksum value.

Checksum algorithms range from simple arithmetic to polynomial math:

  • Sum checksums: Add up the bytes or words of the data. The Internet checksum used by IP, TCP, and UDP is a one’s complement sum of 16-bit words.
  • Check digits: Append one digit derived from the others. The Luhn algorithm validates credit card numbers, and ISBNs end in a check digit.
  • Cyclic redundancy checks (CRCs): Treat the data as a polynomial and keep the remainder after dividing by a fixed generator polynomial. CRC-32 protects Ethernet frames, ZIP archives, and PNG chunks.

Stronger algorithms catch more error patterns, such as swapped bytes or bursts of flipped bits, at a higher computing cost.

The widget below corrupts a received message and compares a simple byte sum with CRC-32. A single flipped bit trips both checks, but swapping two bytes leaves the sum unchanged while CRC-32 still flags the damage.

Interactive diagram — enable JavaScript to view.

A checksum guards against accidental damage from noisy links, failing disks, or interrupted downloads. It offers no protection against deliberate tampering, because anyone who changes the data can recompute a matching checksum. Detecting malicious edits calls for a cryptographic hash such as SHA-256, often published next to a download, or a keyed message authentication code.

Python exposes CRC-32 and Adler-32 through the zlib module, and cryptographic digests through hashlib.

Build a Hash Table in Python With TDD

Tutorial

Build a Hash Table in Python With TDD

In this step-by-step tutorial, you'll implement the classic hash table data structure using Python. Along the way, you'll learn how to cope with various challenges such as hash code collisions while practicing test-driven development (TDD).

intermediate algorithms data-structures

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Martin Breuss • Updated Nov. 12, 2026