File Hashes: MD5, SHA-1, SHA-256 and How to Verify Downloads
A file hash is a fixed-length value calculated from a file’s contents, commonly used to compare a downloaded file with a reference copy. The same bytes and algorithm produce the same result, but different files can theoretically share a hash. For routine file verification, prefer SHA-256 when the publisher provides it, and check where the reference value came from.
What does a file hash represent?
A hash function calculates a summary called a hash value or digest. MD5, SHA-1, and SHA-256 each have a fixed output length: a small document and a large installer produce equally long digests when you use the same algorithm. A digest is not a compressed copy from which you can reconstruct the file. NIST’s overview of hash functions explains these properties and the relevant security requirements.
Ordinary file-hashing tools read the bytes inside a file, rather than its name or folder location. Renaming a file without changing its contents leaves the hash unchanged. Conversely, two documents that display the same text may contain different bytes because of line endings, character encoding, or metadata stored inside the file.
A hash can be described as a fingerprint, but it is not an absolutely unique identifier. A collision occurs when different inputs produce the same digest. A secure cryptographic hash is designed to make finding such inputs impractical. MD5 and SHA-1 no longer meet the security requirements for collision-resistant applications.
MD5 vs SHA-1 vs SHA-256
MD5 stands for Message-Digest Algorithm 5; SHA stands for Secure Hash Algorithm. SHA-256 belongs to the SHA-2 family and produces 256 bits. Tools commonly display the result as hexadecimal text. Each hexadecimal character represents four bits, giving the following lengths:
| Algorithm | Digest size | Hexadecimal length | Choice for file verification |
|---|---|---|---|
| MD5 | 128 bits · 16 bytes | 32 characters | May be needed to compare a legacy checksum, but should not establish protection against malicious tampering. |
| SHA-1 | 160 bits · 20 bytes | 40 characters | Can be compared with legacy references; avoid choosing it for new security applications. |
| SHA-256 | 256 bits · 32 bytes | 64 characters | A practical choice for routine download integrity checks when the publisher supplies a SHA-256 value. |
The MD5 size and collision-resistance limitations are discussed in RFC 6151’s MD5 security considerations. The SHA specifications appear in NIST’s Secure Hash Standard. Detecting an accidental transmission error and defending against an attacker who can alter a file are different requirements.
Always compare hashes from the same algorithm. A locally calculated SHA-256 value cannot be checked against a published MD5 value. Also, a 256-bit output does not imply 256-bit strength against every type of attack. See NIST’s algorithm and security-strength guidance for SHA-1 limitations and the distinctions between attack types.
What happens when one character changes?
This Python example calculates SHA-256 for the ASCII bytes abc and abC. Only the final character changes, and neither input includes a trailing newline. The output shown was checked with Python 3.12; both digests contain 64 hexadecimal characters.
import hashlib
for data in (b"abc", b"abC"):
print(data.decode("ascii") + ": " + hashlib.sha256(data).hexdigest())
Output:
abc: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad abC: 0a2432a1e349d8fdb9bfca91bba9e9f2836990fe937193d84deef26c6f3b8f76
These similar-looking inputs produce very different digests. The example does not prove that every pair of different inputs must have different hashes. Deterministic output for the same input, possible collisions, and resistance to deliberate attacks are separate properties.
How to verify a downloaded file
Integrity verification checks whether data differs from a reference. Calculating a new digest alone is not a verification: you need a trusted reference hash to compare with it.
- Obtain the reference hash from the publisher’s official download page or another trusted distribution channel.
- Confirm that the operating system, CPU architecture, version, and filename match the download. Check which algorithm the reference uses.
- Wait for the download to finish, then calculate its hash with the same algorithm. Do not modify or overwrite the file while it is being read.
- For SHA-256, compare all 64 hexadecimal characters, rather than just the beginning. Uppercase and lowercase hexadecimal letters represent the same values.
- If the values differ, do not run or install the file. Recheck the comparison target, then download it again from the official channel and repeat the verification.
If an attacker can replace both a file and its reference hash, matching values do not establish who supplied it. A match is a comparison with the reference data, not proof that a file is free of malware. When signed checksums or digital signatures are provided, follow the publisher’s instructions and verify them using a trusted public key.
SHA-256 commands for Windows, Linux, and macOS
example.iso below is an illustrative filename. Replace it and the path with your actual download, and quote paths containing spaces. These commands read the file to calculate its digest; they do not change its contents.
Windows: Get-FileHash in PowerShell
Open PowerShell from the Start menu and run the following command. -LiteralPath treats the path literally rather than interpreting wildcard characters. -Algorithm SHA256 explicitly selects the algorithm.
Get-FileHash -LiteralPath 'C:\Downloads\example.iso' -Algorithm SHA256 | Format-List
Check the Algorithm, Hash, and Path fields. SHA-256 is the default, but specifying it makes the comparison clearer. Microsoft’s Get-FileHash documentation describes the supported algorithms and output. If the file cannot be found, check its actual path and extension in File Explorer.
Linux: sha256sum
In an environment with GNU Coreutils sha256sum installed, open a terminal and run this command. The usual output includes the digest followed by the filename.
sha256sum "/home/user/Downloads/example.iso"
If the publisher provides a GNU-format SHA256SUMS file, place it alongside the files to verify, open a terminal in that folder, and check the list with the command below. The paths named in the list must exist. A complete list may report missing files if you downloaded only some of its entries.
sha256sum --check SHA256SUMS
Matching entries are reported as OK; mismatches are reported as failures. The checksum list itself must also come from a trusted source. Consult the GNU SHA-2 utilities manual for the command and check options. If the command is missing, check whether Coreutils is installed for your distribution.
macOS: shasum
If shasum is available in your terminal, explicitly select SHA-256 with -a 256. Without that option, shasum defaults to SHA-1, which can cause an algorithm mismatch.
shasum -a 256 "/Users/user/Downloads/example.iso"
For a compatible checksum list, use shasum -a 256 -c SHA256SUMS. The shasum maintainer’s documentation explains algorithm selection and -c. These macOS instructions are based on the tool’s documentation rather than an execution on macOS; the Python method below is an alternative when the tool is unavailable.
Calculate a large file’s SHA-256 with Python
With Python 3 installed, you can use the standard-library hashlib module. Save this code as hash-file.py. It opens the file in binary mode, rb, and reads one mebibyte (MiB) at a time instead of loading the entire file into memory. Its assignment-expression syntax requires Python 3.8 or later.
import hashlib
import sys
if len(sys.argv) != 2:
raise SystemExit("Usage: python hash-file.py FILE")
digest = hashlib.sha256()
with open(sys.argv[1], "rb") as file:
while chunk := file.read(1024 * 1024):
digest.update(chunk)
print(digest.hexdigest())
From the script’s folder, pass the path of your actual file as follows. If your Python 3 command is python3 or py, use that command in place of python.
python hash-file.py "example.iso"
The output is a 64-character hexadecimal SHA-256 digest. Identical bytes give the same result as PowerShell and other tools, although letter case may differ. The official Python hashlib documentation explains update() and hexdigest(). Small, empty, and multi-chunk files were checked with Python 3.12.14 and PowerShell 7.6.5 on Windows to confirm matching results.
What to check when hashes do not match
- Different release files: check for x64 versus ARM64, installers versus archives, or different versions.
- Different algorithms: MD5, SHA-1, and SHA-256 produce different digests. Recheck the algorithm names.
- Incomplete downloads: confirm that the download finished and that the download tool reported no errors.
- Extraction or conversion: an archive’s reference hash does not apply to a file extracted from it. Saving in an editor, converting line endings, and recompressing images can change the bytes.
- Path or copying mistakes: check the file actually read by the command and the entire reference value. Avoid a truncated digest or one copied from a different file.
Do not replace an unexplained reference value with your own calculated value to force a match. Confirm the distribution channel and target first. If a fresh download still differs, check the publisher’s instructions or whether the release has been corrected.
What hashes can and cannot do
| Use | Role of hashing | Additional requirements |
|---|---|---|
| File integrity | Compare current file contents with a reference digest. | The reference source and algorithm must be appropriate. |
| Duplicate detection | Group files with matching hashes as duplicate candidates. | Allow for collisions and compare bytes when exact equality is essential. |
| Digital signatures | A signature scheme may use a digest of the data. | Calculating a hash alone does not create a signature or authenticate the author. |
| Password storage | Password verification also uses hash-based mechanisms. | Use a dedicated password-storage method instead of plain file-hashing SHA-256. |
Hashing is not encryption. Encryption is intended to allow recovery of plaintext with the appropriate key; a hash is not a format for reconstructing its input. However, short or predictable inputs can be guessed and their hashes compared, so merely hashing something does not guarantee secrecy.
For passwords, choose a trusted implementation of a dedicated password-hashing scheme such as Argon2id, with an appropriate cost and a unique salt, instead of plain MD5, SHA-1, or SHA-256. A salt is a per-password value that makes precomputed guessing attacks less useful. The OWASP Password Storage Cheat Sheet explains why password storage and file hashing need different designs. For download checks, the essential steps are calculating SHA-256, obtaining a trusted reference, and comparing the complete digest.





