Home / Learn Embedded C / Checksums and CRC Basics

Checksums and CRC Basics

Adding a small check value to detect data corruption during transmission.

Quick summaryAdding a small check value to detect data corruption during transmission.

How to think about this

In plain terms

A checksum (or more robust CRC — Cyclic Redundancy Check) is a small value computed from a message's bytes and sent along with it, letting the receiver detect whether the data was corrupted in transit.

Why we use it

Serial links (especially longer or noisier ones) can introduce bit errors; a checksum/CRC lets a receiver reject corrupted data instead of silently acting on wrong values — essential for any protocol where correctness matters.

Under the hood

A simple checksum (like a sum or XOR of all bytes) is cheap to compute but can miss certain error patterns; a CRC uses polynomial division and catches a much broader range of common error patterns, at a higher computational cost.

Real-world use

  • Protocol error detection
  • Firmware image validation
  • Reliable serial data transfer

Try it

A simple XOR checksum over a short messageC: edit and run

A real CRC is more robust than a simple XOR checksum but follows the same basic idea: compute a check value, send it along, and verify on receipt.

Try it: detecting corruption by recomputing the checksum on receipt

Comparing a received checksum against a freshly computed oneC: edit and run

One corrupted byte (0x99 instead of the original 0x56) makes the recomputed checksum disagree with the one that was sent, revealing the corruption.

Quick quiz

1. What does adding a checksum or CRC to a transmitted message let the receiver do?