NetSecTools

Home / Guides / How to verify a downloaded file with a checksum (SHA-256)

How to verify a downloaded file with a checksum (SHA-256)

ยท 8 min read

When you download an operating system image, an installer or a firmware update, how do you know the file arrived intact, and that it is the one the publisher released? The usual answer is a checksum: a short fingerprint that you can recalculate and compare.

What a hash is

A cryptographic hash function turns any amount of data into a fixed-length value:

SHA-256("hello")  = 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
SHA-256("hellp")  = a mixture that looks completely unrelated

A good hash function has these properties:

  • Deterministic. The same input always gives the same output.
  • Fixed size. SHA-256 always gives 256 bits (64 hexadecimal characters), whether the input is one byte or a 10 GB file.
  • Avalanche effect. Changing one bit of the input changes the output beyond recognition.
  • One way. You cannot recover the input from the hash.
  • Collision resistant. It is practically impossible to find two different inputs with the same hash.

Which algorithm to use

Algorithm Output size Status
MD5 128 bits Broken for security. Collisions can be created easily
SHA-1 160 bits Broken. The first practical collision was demonstrated in 2017
SHA-256 256 bits Good, and the most widely published
SHA-384, SHA-512 384, 512 bits Good

MD5 and SHA-1 still work to detect accidental corruption, but they should not be trusted to prove that a file was not deliberately replaced.

Step by step: verify a download

  1. Find the official checksum. The publisher usually lists it on the download page, in a file called SHA256SUMS or checksums.txt, or in the release notes.
  2. Calculate the checksum of your file with one of the commands below, or with our Hash Generator.
  3. Compare the two values. They must be identical, character for character.

Windows (PowerShell)

Get-FileHash .\ubuntu.iso -Algorithm SHA256

or with the older tool:

certutil -hashfile ubuntu.iso SHA256

macOS

shasum -a 256 ubuntu.iso

Linux

sha256sum ubuntu.iso

If the publisher gives you a checksums file, Linux can compare automatically:

sha256sum -c SHA256SUMS

In the browser

Open the Hash Generator, choose your file and compare the SHA-256 line. The file is read by your browser and is never uploaded.

What a match tells you, and what it does not

A matching checksum tells you the file you have is identical to the one that was hashed. That detects:

  • a download that was cut short or corrupted,
  • a damaged storage device.

It does not prove the file is safe or genuine unless the checksum itself came from a trustworthy place. If an attacker can replace the file on the download page, they can usually replace the checksum next to it as well. Weigh the source:

  • A checksum published on an HTTPS page of the project, separate from the download mirror, is good.
  • A checksum on the same mirror as the file proves little against a hacked mirror.
  • A digital signature is stronger. Many projects sign their checksum file with a PGP key, and you can verify it with gpg --verify. Package managers do this for you automatically.

Hashes versus encryption and encoding

People often confuse these three tools:

  • Hashing produces a fingerprint. It is one way and has no key.
  • Encryption hides data and can be reversed with the right key. You can try it with our Text Encrypt / Decrypt tool.
  • Encoding such as Base64 changes the representation and is reversible by anyone. See the Base64, URL & Hex Encoder.

For a deeper comparison, read encoding vs encryption vs hashing.

Hashes and passwords

Do not store passwords as plain SHA-256. Fast hashes can be tried billions of times per second on a graphics card. Password storage needs a deliberately slow, salted algorithm such as Argon2id, bcrypt or scrypt.

A related tool is HMAC, a hash combined with a secret key. It proves that a message came from someone who knows the key and was not changed. It is used in API signatures, in JSON Web Tokens and in one-time codes.

A quick checklist

  1. Download over HTTPS.
  2. Get the checksum from the official project page, ideally a different source from the file.
  3. Use SHA-256 or stronger.
  4. Compare the whole string, not just the first and last characters.
  5. If the project signs releases, verify the signature as well.
  6. If the values differ, delete the file and download it again. If it still fails, do not install it.