# What is a Checksum?

04/24/2024
5 minutes

If you download an app from the internet, how do you know it’s what it claims to be? Say you find a copy of an e-book or game in an online marketplace and you want to download it. How do you know your download is the intended media, and not a corrupted program stuffed with malware?

This is where checksums often come into play. The term “checksum” refers to a sequence of letters and numbers that you can use to safeguard against data errors (also known as a “hash”). Checksums are often used in scenarios where data integrity is crucial because they allow you to verify a file’s hash against the original.

Checksums help you ensure that files you’ve downloaded are legitimate, complete, and uncorrupted. As a developer, you should know when and how to implement checksum algorithms in the applications you build. Ahead, we’ll take a closer look at checksums, their use, and ways to calculate them.

## How checksum programs work

A checksum is a sequence of letters and numbers that you use to check a file’s validity and integrity. Checksum programs work by running a file through an algorithm that uses aspects of the file to produce the checksum value.

The algorithms used to produce checksums include:

• SHA-1
• SHA-512
• MD5

Each algorithm has its pros and cons, but the best one to use depends on your specific use case.

### How algorithms render checksums

Algorithms use cryptographic hash functions, which are formulas that take an input and output a bunch of letters and numbers. Because the algorithm is relatively complicated, very miniscule differences in two files that are otherwise essentially the same can produce vastly different checksums.

The algorithm analyzes the contents of a file, and each element of the file becomes an input. Because each file contains so many different elements, it’s highly unlikely for two different files to produce the same checksum.

Checksums are standardized, so each file’s checksum contains the same number of digits, and it’s impossible to derive the original file using just the checksum.

For instance, using an online checksum tool, we can upload a file with this blog post, and it’ll produce the following checksum:

4f404820274682dcd6f66290c78b239b

And a document with only the word “the” in it produces this checksum:

fef6e7bcb47ab0764178d7f30e5f5bec

4f404820274682dcd6f66290c78b239b

With only a period added, the checksum for “the” becomes this:

5ee798757e220c1a5b9702b37cd4d611

These were produced using the MD5 checksum algorithm. But different algorithms would produce different checksums for the same file.

## How checksums are used

Because checksums can pick up even very minor variations in a file, they have many uses. While the average person might not encounter checksums in their day-to-day activities, they come up a lot in instances like:

• Checking whether an internet connection was interrupted while transmitting an important file.
• Analyzing data to identify hard drive problems that could have corrupted it.
• Checking a hard disk, thumb drive, or another external disk to see if it has been corrupted.
• Analyzing data being delivered to a recipient to see if a third-party had intercepted, corrupted, or manipulated it.
• Checking for malware installed within a presumably trustworthy file.

### Example of how to use a checksum algorithm

Say you have to download a new version of a game from a site claiming to be the original provider. The site also gives you the checksum of the file. You download the file, and it takes several minutes because it’s huge. Your internet connection seems a little slower than usual, so you walk away for a few minutes while the file finishes downloading.

When you come back, it looks like the download was successful. You then open the file and install the new version of your game. Right away, something doesn’t seem right. Even though the game opens, the user interface lags, and some visual elements seem corrupted.

In this case, you could use a checksum algorithm to check whether there’s a problem with the file. The algorithm used to generate the checksum on the provider’s site will most likely be specified, so all you have to do is copy the checksum and find a checksum generator that uses the same algorithm.

You load the original file you downloaded from the provider’s site, find the algorithm the provider used, and enter the file into the checksum generator. At this point, one of two things will happen:

• The checksums match. This could mean one of the following:
• The provider has been making a corrupted file available to customers, which is unlikely.
• The problem is on your end; your computer isn’t executing the file properly.
• The checksums do not match. This means:
• Your connection wasn’t secure, and a hacker interrupted your transmission and altered the contents of the file using a man-in-the-middle attack.
• You made a mistake when choosing which file to input into the checksum algorithm, perhaps putting in one that you had already altered in some way.

## Where are checksums used?

Checksums are useful when ensuring the quality of downloads and analyzing data for evidence of a cyber-attack. If you want to learn more about algorithms and how they’re generated and used, check out our free course Java: Algorithms. You can also gain a solid understanding of algorithms with Learn Data Structures and Algorithms with Python.

3 courses

7 articles

# What Is CoffeeScript?

08/09/2024
6 minutes

What is CoffeeScript, and is it worth learning? In this article, we explain how it changed the way we write both front-end and back-end JavaScript code.

# Context Switching Is Killing Your Productivity — 6 Tips for Focus

08/09/2024
7 minutes

Context switching doesn’t just affect your productivity, it causes stress and frustration too. Here are some ways to manage interruptions at work.

# 7 Small Wins To Celebrate On Your Journey To Becoming A Professional Developer

08/06/2024
7 minutes

Having an end goal is important, but so is celebrating your progress. Here are some milestones to look forward to as you learn how to code.

08/05/2024
5 minutes

# This Is the Most Popular Programming Language for Learning to Code

07/25/2024
3 minutes

Stack Overflow’s 2024 Developer Survey just dropped, with Python ranking the most popular programming language among people learning to code. […]

# Learn Essential Professional Skills in 70+ New Free Courses

06/26/2024
4 minutes

Improve your soft skills like communication, leadership, and problem solving in these new free courses.

# Cool Job: I’m Duolingo’s Director of Engineering

10/13/2023
5 minutes

Vanessa Jameson leads the engineering team that recently launched Duolingo’s new music and math courses.