Error Detection · Cambridge syllabus 2.2 · Lesson 2 of 5
Checksums
A checksum is calculated from data and sent or stored alongside it. The receiver repeats the calculation and compares results. A mismatch indicates corruption; a match is evidence, not proof, because different data can share a checksum.
By the end, you can
- Understand the purpose of a checksum.
- Explain how a checksum can be calculated from transmitted data.
- Use checksums to identify transmission errors.
Checksum
A checksum checks a whole block of data rather than a single byte. The sender runs an agreed calculation over all the bytes in the block and sends the result along with the data.
The calculation is usually a running total. Add every byte in the block, and if the total exceeds the size of the checksum field, keep only the remainder — for a one-byte checksum, the total modulo 256. Other schemes send the value that would make the total come to zero, so the receiver only has to check for a zero result.
The receiver performs exactly the same calculation on the data that arrived and compares its answer with the checksum it was sent. Equal means the block is almost certainly intact; different means something changed, and the block is requested again.
A checksum takes the values of all the bytes into account, so it catches many errors that parity misses. It still cannot correct anything, and it can be fooled: two changes that happen to leave the total unaltered pass unnoticed.
- checksum = (sum of all data bytes) MOD 256
- A one-byte checksum: total the block, keep the remainder after dividing by 256 so the answer fits in a byte.MOD gives the remainder after division
Worth remembering
- The sender calculates a value from the whole block and transmits it with the data.
- The receiver recalculates and compares; a mismatch means corruption.
- It detects errors but cannot correct them, and errors that cancel out still pass.
Worked example
In a simple sum modulo 256, bytes 10, 20 and 30 produce checksum 60. Changing 20 to 21 changes it to 61.
Practice
Warm-up · not marked
Check your understanding
Answer in your own words, then compare with the worked answer. Nothing here is saved or scored.
Worked answer
Different changes can cancel, such as increasing one byte by 1 and decreasing another by 1.
Check your method, units and explanation against it.
Marked practice
Set 1 of 4 · easiest first · Checked as you go, with the worked answer. Sign in or create a free account to save your progress.