teach-ict.com logo

THE education site for computer science and ICT

Error detection and correction

2. Checksum

This is a widely used error detection method.

It works my doing some maths on the data to get a single number that represents that particular data set. This number is called the checksum.

The checksum is sent along with the original data. At the other end, the same calculation is done on the incoming data and the result is compared with the checksum. If they are the same, then the data is correct. If they are not the same, then an error has occurred.

The mathematics used is called a 'hashing algorithm' and there are quite a few of them. For example there is an algorithm called 'SHA256'.

Example:

Here are two text files that are almost exactly the same, the difference is that one ends with a full stop and the other ends with an exclamation.

Windows has a built-in checksum application called Get-FileHash. You feed it with a data file and it produces a checksum for that file.

In the screen shot below, it is obvious that the checksum of file1.txt is very different to the checksum of file2.txt even though there is only one character different.

checksum algorithm

Checksum is also very useful to check that a downloaded file has not been deliberately altered (malware for example). The downloaded file is run through the hashing algorithm and the result is compared to the official checksum. If they are the same, then the file has not been altered.