A small number that helps you check if data was changed or damaged.
A checksum is a small number worked out from some data. If the data changes, even a little, the number changes too.
A checksum is a short fingerprint of data. A function reads all the bytes and gives a small fixed-size number. The same data always gives the same number. Different data almost always gives a different number.
| Type | Size | Good for | Safe against attackers? |
|---|---|---|---|
| Simple sum / parity | 1 to 2 bytes | Very basic error checks | No |
| Fletcher, Adler-32 | 2 to 4 bytes | Cheap, quick checks | No |
| CRC32 (cyclic redundancy check) | 4 bytes | Network frames, ZIP, storage, Ethernet | No |
| MD5 | 16 bytes | Spotting accidents, old file checks | No: broken |
| SHA-1 | 20 bytes | Old systems | No: broken |
| SHA-256 | 32 bytes | File downloads, certificates, blockchains | Yes, as a hash |
Data does get damaged. Cables pick up noise. Memory chips flip a bit. Disks go bad. Software has bugs. And a copy of 50 GB cannot be checked by eye.
1011001 have four 1s. With even parity we add a 0. If one bit flips on the way, the count of 1s becomes odd, and the receiver knows something is wrong.# Mac / Linux shasum -a 256 tool.zip # or sha256sum tool.zip # Windows PowerShell Get-FileHash tool.zip -Algorithm SHA256 # Compare the result with the value on the official site
function fletcher16(bytes) {
let s1 = 0, s2 = 0;
for (const b of bytes) {
s1 = (s1 + b) % 255;
s2 = (s2 + s1) % 255;
}
return (s2 << 8) | s1;
}| Term | Meaning in easy words |
|---|---|
| Checksum | A small number worked out from data, used to spot changes |
| Hash function | A function that turns any data into a fixed-size value |
| Cryptographic hash | A hash built so that nobody can create different data with the same value |
| CRC | Cyclic redundancy check. A strong, fast checksum for random errors |
| Parity bit | One extra bit to make the count of 1s even or odd |
| Check digit | A digit added to an ID number to catch typing mistakes |
| Collision | Two different inputs that give the same checksum |
| Bit flip | A single 0 changing to 1 (or the other way) |
| Bit rot | Slow silent damage to stored data |
| Integrity | Data has not changed since it was made |
| Error detection | Finding out that data is wrong |
| Error correction | Finding out AND fixing it (for example ECC memory, erasure codes) |
| Digest | Another word for the output of a hash |
| Choice | We gain | We lose |
|---|---|---|
| Short checksum (16 or 32 bits) | Speed and small size | More chance of a missed error |
| Long hash (SHA-256) | Very low chance of collisions, security | More CPU time, bigger value |
| Check at every step | Find the problem early | More work for each step |
| Check only at the end | Cheaper | You learn late, and cannot tell where it broke |