File Hash Verification: SHA-256, MD5 and What a Digest Proves

File Hash Verification: SHA-256, MD5 and What a Digest Proves
Technical Specifications & Compatibility
Digest Lengths MD5 128-bit, SHA-1 160-bit, SHA-256 256-bit, SHA-512 512-bit
Certutil Algorithms MD2, MD4, MD5, SHA1, SHA256, SHA384, SHA512
Verify Flag sha256sum -c reads digest and path per line, two spaces apart
Checksum File Format lowercase hex digest, two spaces, relative path
Filesystems With Data Checksums ZFS, btrfs, ReFS integrity streams
Table of Contents

A file that opens is not a file that arrived intact. Most corruption does not announce itself: an archive missing a few bytes still lists its contents, an installer launches and fails at 87%. A cryptographic digest settles the one question that can be answered mechanically — are these bytes the same bytes — without trusting the network that carried them or the disk that stored them.

A digest identifies bytes, not intentions

A hash function maps an input of any length to an output of fixed length: SHA-256 turns a 4 TB disk image and a twelve-byte text file into 64 hexadecimal characters each. The same bytes give the same digest on Windows, on Linux, on a NAS and ten years from now, provided the implementation follows the standard. Change one bit and roughly half the output bits flip, so there is no near miss between two digests.

That property proves identity of bytes and nothing else. A matching digest says the file you hold is the file the publisher hashed; it does not say whether that file is safe to execute.

A matching SHA-256 proves two byte strings are identical. It does not prove the string is trustworthy. Integrity is a statement about copying; authenticity needs a signature or a channel you already trust.

A digest delivered in the same message as the file adds almost nothing, because both were exposed to the same tampering. A value published on a separate, signed page is a real control.

Why MD5 stopped proving authenticity

MD5 produces a 128-bit digest and was designed in 1991 for speed on 32-bit hardware. It has been broken as a collision-resistant function since 2004, when two different inputs with one digest were shown to be constructible. A collision is that: distinct content, identical hash, and no comparison tells them apart.

The exploitation is documented: in 2008 a collision produced a rogue certificate authority certificate that browsers accepted, and in 2012 the Flame malware carried a payload signed with a forged Microsoft certificate built on a chosen-prefix MD5 collision. SHA-1 followed the same route, with SHAttered in 2017 and affordable chosen-prefix collisions by 2020.

AlgorithmDigestHex charsStatusUse it for
MD5128-bit32Broken for collisionsAccidental corruption, deduplication
SHA-1160-bit40Deprecated, chosen-prefix feasibleReading old checksum files
SHA-256256-bit64No practical collision publishedDownloads, backups, archives
SHA-512512-bit128No practical collision publishedSame role, faster on 64-bit CPUs without SHA extensions

MD5 keeps one narrow use: catching accidental damage, where nobody is trying to deceive you. The moment a hash is supposed to prove that a file is the one its author published, MD5 answers a question it can no longer answer.

One command per platform

Nothing to install: each of these prints the digest:

  1. Windows, Command Prompt: certutil -hashfile "D:\images\disk.img" SHA256
  2. Windows, PowerShell: Get-FileHash -Algorithm SHA256 -Path "D:\images\disk.img"
  3. Linux: sha256sum disk.img
  4. macOS: shasum -a 256 disk.dmg
  5. MD5 for comparison, same three systems: certutil -hashfile disk.img MD5, md5sum disk.img, md5 disk.dmg

certutil accepts MD2, MD4, MD5, SHA1, SHA256, SHA384 and SHA512, and wraps its output into space-separated groups on some builds. Get-FileHash returns an object, so a boolean comparison is trivial:

(Get-FileHash -Algorithm SHA256 .\disk.img).Hash -eq "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"

Hexadecimal is case-insensitive, so normalise to lower case before any diff. One character wrong out of 64 is a complete mismatch, never a rounding difference; there is no partial credit in a digest comparison.

Checking a directory against one checksum file

One digest per file does not scale to a backup set. The convention is a text manifest, one line per file: digest, two spaces, relative path.

sha256sum *.img *.zip > SHA256SUMS
sha256sum -c SHA256SUMS

-c recomputes every entry and prints OK or FAILED per line, exiting non-zero on failure. --quiet shows only failures, --ignore-missing skips absent files, and --status suppresses output when a script only needs the exit code. macOS reads the same manifest with shasum -a 256 -c SHA256SUMS. On Windows, generate it in PowerShell and check it from WSL or Git Bash:

Get-FileHash -Algorithm SHA256 .\* | ForEach-Object { "$($_.Hash.ToLower())  $($_.Path)" } | Out-File -Encoding ascii checksums.txt

Store the manifest outside the volume it describes: a failing disk takes its own checksum file with it.

Where silent corruption comes from

Consumer filesystems do not protect data at the byte level. NTFS and ext4 checksum metadata and journals, not file contents, so the OS cannot tell you that a photograph changed. chkdsk and fsck verify structural consistency; a file can pass both and still be wrong. ZFS, btrfs and ReFS with integrity streams keep a checksum per block and can detect, and in mirrors repair, a bad read. Everything else needs an external list of digests.

The usual sources are unglamorous: a failing sector on a years-old drive, a marginal SATA or USB cable, faulty RAM during a large write, a sync client that truncates when the connection dies, or a copy stopped by a full destination volume that the file manager still reports as complete.

That is why the check belongs after the copy, not only after the download. A write to a NAS or external drive passes through a second cache, controller and filesystem. Comparing digests at both ends covers the path. rsync -c compares by checksum instead of size and timestamp, and rclone check remote:path ./local --checksum does the same across cloud storage.

The browser route when nothing can be installed

On a locked-down workstation, where installing a utility needs an approval nobody wants to chase, the calculation can still be done. Open the checksum verifier, drop the file into the page and read the four digests: SHA-256, SHA-1 and MD5. The file is read through the browser's File API and is not uploaded; the arithmetic happens in the tab.

Paste the publisher's value into the comparison field and the page marks a match or a mismatch. That is the same operation as sha256sum, with the same limits: it confirms identity of bytes, and the value compared has to arrive through a channel you trust. For the compression side of the same problem, see how to repair damaged archives; for the transfer side, large uploads that survive interruptions.

A digest costs seconds of CPU for a file that took an hour to transfer. Running it at the source, at the destination and against the published value is the whole discipline, and the only part of a transfer that gives a definite answer.

Troubleshooting Common Issues

Error / Issue Technical Cause Step-by-Step Fix
SHA256 hash does not match the published value The transfer truncated, the source serves a rebuilt file, or the copy on disk was modified. Re-download once on a different network, hash again, and treat a second mismatch as a different object rather than a damaged one.
certutil prints the digest split across several lines Older Windows builds wrap the output of certutil -hashfile into fixed-width groups separated by spaces. Join the groups and remove the spaces before comparing, or use Get-FileHash, which returns the bare 64-character string.
sha256sum -c reports FAILED for a file that exists The path in the checksum file is relative to a different working directory, or the file was edited after hashing. Run the check from the directory the manifest was generated in, or rewrite the paths as relative to the manifest itself.
Get-FileHash is not recognised as a command The session runs in cmd.exe, or Windows PowerShell 2.0 on an unpatched system. Open PowerShell instead of Command Prompt, or fall back to certutil -hashfile with the same algorithm name.

Frequently Asked Questions

Is SHA-256 more secure than MD5?

It is harder to fake, which is not the same thing. Both detect accidental corruption equally well. SHA-256 resists deliberately constructed collisions that MD5 has allowed since 2004, so only SHA-256 can back a claim that nobody substituted the file.

Can a matching hash still mean the file is unsafe?

Yes. A digest proves the bytes are identical to the ones hashed, not that those bytes are harmless. Malware distributed with its own correct checksum passes verification. Only a signature from a key you trust separates authenticity from mere integrity.

Does hashing upload the file anywhere?

No when you use a local command, and no with a browser tool that reads the file through the File API. The bytes are read on your machine and never leave it unless the page explicitly sends them, which a well-built verifier does not do.

Why verify again after copying to a NAS?

Because the copy is a new write on different hardware with its own cache, cabling and firmware. A copy that completes without an error message can still land truncated. Comparing source and destination digests is the only check that covers the write path.

Related Technical Guides