Skip to content
GEEKnodes

Computing

What Is a SHA-256 Hash and How to Verify a Download

What a hash function is, why MD5 and SHA-1 are no longer secure, and how to check the SHA-256 of a download on Windows, macOS and Linux with one command.

You download a 5 GB ISO, write it to a USB drive and the installer fails halfway through. Was the download corrupted, or is it something else? Many downloads come with a long string of letters and numbers next to them: the hash. This guide shows you what it is, why MD5 no longer counts as secure, and how to check it on Windows, macOS and Linux with a single command.

In short

  • A hash is a file’s fingerprint: change a single bit and the whole hash changes.
  • Use SHA-256 to check integrity; MD5 and SHA-1 are broken against deliberate attacks.
  • A hash only protects you if you get it from a trustworthy source; otherwise, the real guarantee is a digital signature.

What a hash function is

A hash function takes data of any size (a text, a photo, a multi-gigabyte ISO) and returns a result of fixed length. With SHA-256 it is always 256 bits, written as 64 hexadecimal characters.

A hash function turns a file of any size into a 64-character fingerprint; changing one letter changes the entire result
Input of any size, fixed-length output and the avalanche effect

It has four properties that make it useful:

  1. Deterministic: the same file always gives the same hash, on any computer and operating system.
  2. Avalanche effect: changing one bit produces a completely different hash, not a similar one.
  3. One-way: you cannot rebuild the file from its hash.
  4. Collision resistant: finding two different files with the same hash should be practically impossible.

Look at the avalanche effect with two texts that differ in just one letter:

SHA-256("hola") = b221d9dbb083a7f33428d7c2a3c3198ae925614d70210e28716ccaa7cd4ddb79
SHA-256("Hola") = e633f4fc79badea1dc5db970cf397c8248bac47cc3acf9915ba60b5d76b0e88f

They look nothing alike. That is why comparing a few characters at the start and end is enough to spot that something changed, although the correct way is to compare the whole hash.

A hash is not encryption. Encryption can be reversed with the key; a hash cannot be “decrypted”. It is not compression either: 64 characters cannot hold a 5 GB file.

Common algorithms

AlgorithmLengthHex charactersSecure today?Reasonable use
MD5128 bits32No (collisions since 2004)Detecting accidental corruption, caches
SHA-1160 bits40No (practical collision in 2017)Legacy systems, compatibility
SHA-256256 bits64YesVerifying downloads, signatures, certificates
SHA-512512 bits128YesSame as SHA-256

The length of a published hash tells you which algorithm it is: 32 characters is almost certainly MD5, 64 is SHA-256.

Why MD5 and SHA-1 are no longer secure

In 2004 a team of researchers showed how to craft MD5 collisions: two different files with the same hash. Today a laptop can generate them in seconds. In 2012 the Flame malware used an MD5 collision to forge a certificate and pose as legitimate software.

SHA-1 held out longer, but in 2017 the first practical collision was published: two different PDFs with an identical SHA-1. Browsers and certificate authorities have since retired it.

What does this mean in practice?

  • Against accidental corruption (a network drop, a disk with bad sectors), MD5 still catches the error. Random faults do not create collisions.
  • Against deliberate tampering, MD5 and SHA-1 guarantee nothing. An attacker could prepare a malicious version with the same hash.

If a project publishes several hashes, always use SHA-256 or SHA-512.

How to calculate the hash on each system

Windows (PowerShell)

PowerShell includes Get-FileHash, which uses SHA-256 by default:

Get-FileHash .\ubuntu.iso
Get-FileHash .\ubuntu.iso -Algorithm SHA512

Instead of comparing by eye, let PowerShell do it for you. The -eq operator is case-insensitive, so it does not matter how the published hash is written:

(Get-FileHash .\ubuntu.iso).Hash -eq "paste_published_hash_here"

It returns True if they match.

Windows (Command Prompt)

If you prefer the classic console, certutil does the same:

certutil -hashfile ubuntu.iso SHA256

It accepts MD5, SHA1, SHA256, SHA384 and SHA512. Type it in uppercase to avoid surprises on older versions.

macOS

shasum -a 256 ~/Downloads/ubuntu.iso

You can also use shasum -a 512, or md5 if the project only publishes MD5.

Linux

sha256sum ubuntu.iso
sha512sum ubuntu.iso
md5sum ubuntu.iso

Command summary

SystemSHA-256Check against a file
Windows PowerShellGet-FileHash fileCompare with -eq
Windows CMDcertutil -hashfile file SHA256Manual
macOSshasum -a 256 fileshasum -a 256 -c file.sha256
Linuxsha256sum filesha256sum -c file.sha256

Checking with a .sha256 or SHA256SUMS file

Many projects do not put the hash on the web page but in a text file: ubuntu.iso.sha256, SHA256SUMS or similar. The format is simple: the hash, two spaces and the file name.

Verification steps: download the ISO and its .sha256 file into the same folder, run the check and get OK or FAILED
File and .sha256 in the same folder, one command and an OK or FAILED result
3f1a9c...e07b  ubuntu.iso

Steps:

  1. Download the file and its .sha256 into the same folder.
  2. Open a terminal in that folder.
  3. Run the check:
sha256sum -c ubuntu.iso.sha256

On macOS, shasum -a 256 -c ubuntu.iso.sha256. If all goes well you will see ubuntu.iso: OK. If it says FAILED, the file does not match.

When SHA256SUMS lists many files and you downloaded only one, add --ignore-missing so it does not complain about the rest:

sha256sum -c --ignore-missing SHA256SUMS

The limits of a hash: when it is not enough

This is what almost nobody explains. A hash proves your file is identical to the one that produced that hash. It does not prove who produced it.

If the download site is attacked, the ISO and the hash can both be swapped; a signature made with the project's key detects it
A hash from the same site does not protect you if the site is compromised; a digital signature does

If an attacker compromises the download site, they can change the ISO and also the hash published on the same page. Your check will pass perfectly and you will have installed the tampered version. It has happened in real cases of compromised servers.

Ways to reduce that risk:

  • Get the hash through another channel: the official site over HTTPS when the download comes from a mirror, the project’s announcement, its code repository.
  • Verify the digital signature when there is one. The project signs the hash file with its private key and you check it with its public key, which does not live on the same server:
gpg --verify SHA256SUMS.gpg SHA256SUMS

If the signature is valid and the key is the project’s official one, the hash file is authentic, and so is the ISO. On Windows, signed executables show the verified publisher under Properties › Digital Signatures.

What you checkDetects corruptionDetects tampering
MD5 / SHA-1YesNo
SHA-256 from the same siteYesOnly if the site is not compromised
SHA-256 through another channelYesYes, in practice
Verified digital signatureYesYes

Common mistakes

  • Hashing the wrong file: the browser renames it to ubuntu (1).iso if one already existed. Check the exact name.
  • Comparing different algorithms: you calculate SHA-256 and compare it with a published MD5. They will never match. Look at the length.
  • Download not finished yet: the hash of a half-downloaded file is useless. Wait until it completes.
  • The .sha256 file in another folder: -c looks for the file by the name listed inside, in the current directory.
  • Windows line endings: a .sha256 edited on Windows can show FAILED on Linux because of the trailing carriage return. Download it again instead of editing it.
  • Assuming a correct hash means a safe program: it only guarantees it is the published file. If the original author included something malicious, the hash “certifies” that too.

Accessibility preferences

Quick profiles

Text and reading

Text size
Default
Line height
Default
Letter spacing
Default
Word spacing
Default

Colour

Motion and orientation

Cursor