Developer & Network Tools

Checksums and File Verification

Verify downloads with SHA-256 on Windows, macOS and Linux, and learn what a matching checksum does and does not prove.

Key takeaways

  • A cryptographic hash turns a file of any size into a fixed-length fingerprint, and changing one bit changes the result completely.
  • Use SHA-256 or stronger; MD5 and SHA-1 are no longer safe against deliberate tampering.
  • A checksum from the same server as the file mainly detects accidents, because an intruder could replace both.
  • Digital signatures add proof of who published the file.
  • If values don't match, don't run the file; download it again from the official source.

A checksum is a short value calculated from a file's contents. If two copies of a file produce the same checksum with a strong method such as SHA-256, you can be confident they're identical. If the values differ, something changed: a broken download, a damaged disk or a replaced file.

To verify a download, calculate its SHA-256 value on your computer and compare it with the one the publisher lists. This guide gives the commands and explains where that comparison protects you and where it doesn't.

What a hash function does

A hash function reads all the bytes of a file and produces a value of fixed length. SHA-256 always yields 256 bits, usually written as 64 hexadecimal characters, whether the input is a one-line note or a large disk image.

The same input always gives the same output. A tiny change in the input gives an output that looks unrelated. For a strong cryptographic hash, it is also impractical to construct a different file with the same value, or to work backward from the value to the contents.

File names and dates aren't part of the calculation. Renaming a file leaves its hash unchanged.

Hashing is different from encryption: there's no key and nothing to decrypt. Hashing, encryption and encoding sorts out the three.

Verifying a downloaded file
1 Get the published value Copy it from the publisher's official page 2 Download the file From the official source or a listed mirror 3 Hash your copy Run SHA-256 on your own computer 4 Compare Every character must match 5 Decide Match: proceed. Mismatch: delete and retry Get the published value Copy it from the publisher's official page 1 Download the file From the official source or a listed mirror 2 Hash your copy Run SHA-256 on your own computer 3 Compare Every character must match 4 Decide Match: proceed. Mismatch: delete and retry 5

Calculate a checksum

Windows (PowerShell):

Get-FileHash .\installer.exe -Algorithm SHA256

macOS:

shasum -a 256 installer.dmg

Linux:

sha256sum image.iso

The older Windows command certutil -hashfile installer.exe SHA256 also works. Uppercase and lowercase hexadecimal mean the same thing, so a difference in letter case is not a mismatch.

You can also use a browser-based file hash generator when you don't want to open a terminal.

A worked example

Say you're downloading a Linux installation image to make a bootable USB drive. The project's download page links to several mirrors and also offers a SHA256SUMS file and a signature.

  1. Download the image from a nearby mirror.
  2. Get SHA256SUMS from the project's own site over HTTPS, not from the mirror.
  3. Put both files in the same folder and open a terminal there.
  4. Run the hash command for your system and compare the result with the line that carries your image's exact file name.
  5. If the project publishes a signature, verify it as well before writing the drive.

Large files take a little while, since every byte is read. If the value differs, the mirror may be out of date, the download may have been cut short, or something worse may be going on. In every case the next step is the same: don't write that image to a drive.

Note what this process doesn't cover. After you write the USB drive, a faulty stick can still corrupt the copy. Many installers include a media check option that reads the drive back, which is worth running before you wipe a computer.

Compare without fooling yourself

Checking only the first and last few characters is a habit worth dropping. Let the computer compare the whole string.

In PowerShell, put the published value in the comparison:

(Get-FileHash .\installer.exe).Hash -eq "PASTE_PUBLISHED_VALUE_HERE"

It prints True or False. SHA256 is the default algorithm for this command.

Publishers often supply a file named something like SHA256SUMS, listing values and file names. On Linux, run it from the folder with the downloads:

sha256sum --check --ignore-missing SHA256SUMS

On macOS, shasum -a 256 -c SHA256SUMS performs the same kind of check, and reports files in the list that you didn't download as missing.

Make sure the algorithms match. A 64-character value suggests SHA-256, 128 characters SHA-512, 40 characters SHA-1 and 32 characters MD5. The hash generator and recognizer can help identify an unlabeled value.

Choose an algorithm

Method Output length in hex Suitable for
CRC32 8 Detecting accidental errors only
MD5 32 Legacy accident detection; broken for security
SHA-1 40 Legacy use; practical collisions have been shown
SHA-256 64 General verification
SHA-512 128 General verification

A collision means two different inputs with the same hash. Once attackers can create collisions, a matching value no longer guarantees that you have the file you think. That's why MD5 and SHA-1 shouldn't be trusted against tampering, even though they still reveal a garbled download.

Network protocols and storage systems use fast checks such as CRCs to catch transmission noise. Those are built for random errors, and anyone can adjust data to keep a CRC the same.

What a check can catch
CRC, accident Usually detected, which is its job CRC, deliberate change Easily forged; no protection SHA-256, same-site list Catches damage; fails if the site is taken over Signature, trusted key Detects changes and confirms the signer CRC, accident Usually detected, which is its job CRC, deliberate change Easily forged; no protection SHA-256, same-site list Catches damage; fails if the site is taken over Signature, trusted key Detects changes and confirms the signer

What a match does not prove

A matching checksum says your file equals the file whose value you were given. The strength of that statement depends on where the value came from.

If the download and the checksum sit on the same compromised web server, an intruder can change both. The comparison helps more when the file comes from a mirror or third party and the value comes from the publisher's own HTTPS page or a separate announcement.

It also says nothing about whether the software is safe. A malicious program has a perfectly consistent hash. Keep your system updated, use trusted sources and read the guidance on handling downloads and attachments. For why a trustworthy publisher can still ship tampered code, see supply chain attacks.

Signatures and code signing

A digital signature is made with the publisher's private key and checked with the matching public key. Someone who controls only the download server can't produce a valid signature.

Many open source projects sign their checksum file with GnuPG. The check looks like this:

gpg --verify SHA256SUMS.asc SHA256SUMS
sha256sum --check --ignore-missing SHA256SUMS

The first command checks the signature, the second the files. The important step is obtaining the correct public key: compare its fingerprint with one published through independent channels. A "good signature" from a key you fetched from the attacker means nothing.

Operating systems automate much of this for signed applications and packages. Windows shows a publisher name under a file's digital signature properties, Get-AuthenticodeSignature reports it in PowerShell, and macOS checks signing and notarization when you open downloaded apps. Linux package managers verify repository signatures. Don't switch these checks off to get past a warning. Digital signatures explains the mathematics at a high level.

Other everyday uses

Hashes are handy well beyond downloads.

  • Confirm a copy or backup. Hash the original and the copy, or generate a list for a whole folder and check it later.
  • Find duplicates. Files with identical hashes have identical contents.
  • Notice silent damage. Keep a hash list with an archive and re-check periodically. A change in a file you never edited signals a problem while another good copy may still exist.
  • Show a file hasn't changed. Recording a hash at a known time lets you demonstrate later that the contents are the same, provided the record itself is trustworthy.

To make a list on Linux:

find photos -type f -exec sha256sum {} + > photos.sha256
sha256sum --check --quiet photos.sha256

The --quiet option shows only problems.

When the values don't match

Work through the simple causes first. Did the download finish? Compare the file size. Are you looking at the value for the exact version and platform you fetched? Did you copy the whole string without a stray space? Did a text transfer convert line endings?

Download again, preferably from the primary source. If the mismatch persists, don't open the file. Tell the publisher through their official contact; you may have found an outdated page or a real compromise.

Checksums inside tools you already use

Much verification happens without your involvement. Package managers record expected hashes in repository metadata or lock files and refuse a package that doesn't match. Git identifies every commit and file by its hash, so altered history gets new identifiers, as Git basics describes. Browsers can check a script loaded from another server against a hash written into your page, a feature called Subresource Integrity.

Cloud storage and backup tools often compare checksums to decide what needs uploading and to confirm that a transfer arrived intact. Be aware that some services use their own methods, or compute a value over chunks of a large file, so the number they display may not equal a plain SHA-256 of the whole thing. Read the service's documentation before treating a difference as damage.

Common questions

Can I recover a file from its hash?

No. A 64-character value can't hold the contents of a large file, and strong hashes are designed to be one-way.

Is a plain SHA-256 suitable for storing passwords?

No. Password storage needs a deliberately slow, salted method, as described in password hashing and salting.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in Developer & Network Tools →

Latest news on this topic