1 Introduction
A file hash is like a fingerprint for a file. Just as every person has a unique fingerprint, every file produces its own hash: a short string of hexadecimal characters (0–9, a–f) that identifies it with near-perfect accuracy. If you change even a single byte in the file, the fingerprint changes completely. This property makes hashes essential in cybersecurity, both to check that a file has not been altered and to recognize files already known to be malicious.
4
Common algorithms (MD5, SHA-1, SHA-256, SHA-512)
2256
Possible values for a SHA-256 hash
0
Known collisions on SHA-256 to date (MD5 and SHA-1 are broken)
2 How It Works
Use the calculator below to see how hashing works. Enter some text or select a file, and watch how the slightest change produces a completely different hash. This is called the avalanche effect: a tiny modification produces a radically different result.
The process in 3 steps
The hashing algorithm reads the entire file, byte by byte
The data is mixed through one-way mathematical operations
The result is a fixed-length string, whatever the file size: the hash
3 Detailed Analysis
What happens if you change a single byte?
Imagine a file whose SHA-256 hash starts with a7f3b2c1....
If you change just one character in that file, even adding a single space, the new hash
will look something like 9e4d8f0a....
No resemblance at all. It is as if two completely different people had left their fingerprints.
Fundamental properties
Deterministic
The same file always produces the same hash, on any computer, every time. The file name and date do not matter: only the content counts.
One-way
You cannot rebuild the original file from its hash. A hash identifies a file; it does not contain it.
Collision resistant
With a modern algorithm such as SHA-256, it is practically impossible to create two different files with the same hash. This is no longer true for MD5 and SHA-1, for which collisions have been demonstrated publicly.
Which algorithm should you trust?
MD5 and SHA-1: identification only
Still widely used to look up files in threat databases, but broken for security: an attacker can craft two different files with the same MD5 or SHA-1 hash. Never rely on them alone to prove a file is genuine.
SHA-256 (and SHA-512, SHA-3): the current standard
SHA-256 is the reference today for checking downloads and sharing indicators of compromise. Learn more in Understanding Hashes.
Practical example: verifying a download
When you download software such as Ubuntu Linux, the official site publishes the SHA-256 hash of the file. Once the download is complete, you compute the hash of your copy and compare the two. If they match, your file is intact. If they differ, the file is corrupted or was modified along the way, possibly by an attacker. Your system can compute the hash without installing anything:
# Windows (PowerShell)
Get-FileHash .\ubuntu.iso -Algorithm SHA256
# macOS
shasum -a 256 ubuntu.iso
# Linux
sha256sum ubuntu.iso
# Hash displayed on the official site:
sha256: a1b2c3d4e5f6...abc123
# Hash computed on your file:
sha256: a1b2c3d4e5f6...abc123 ✓ Match!
Compare the whole string, not just the first few characters. A hash also works the other way round: searching the hash of a suspicious attachment in a threat database tells you whether that exact file has already been reported as malicious, without ever opening it (see Malicious File).
Try it on mlab.sh
Generate MD5, SHA-1 and SHA-256 hashes for any text or file instantly. Practice computing and comparing hashes with the same algorithms you just learned about.
Generate hashes on mlab.sh4 Red Flags
The hash does not match
If the hash of your download differs from the one on the official site, the file is corrupted or has been tampered with. Do not open it: delete it and download it again from the official source.
No hash or signature for sensitive software
Many ordinary sites do not publish hashes, but serious projects distributing operating systems, security tools or wallets usually do, often together with a digital signature. If an unofficial mirror offers neither, prefer the official source.
Only an MD5 or SHA-1 hash is provided
Both algorithms are vulnerable to collisions. They still detect accidental corruption, but not a deliberate forgery. Look for a SHA-256 hash or a signed checksum file.
The hash is known as malicious
Services such as VirusTotal catalog the hashes of malicious files. A match is a major red flag. The reverse is not true: an unknown hash does not prove a file is safe, since attackers change their files constantly.
The hash and the file come from the same place
If an attacker controls the server, they can replace both the file and the displayed hash. When possible, check the hash on another channel or verify the publisher's digital signature (GPG, code signing), which an attacker cannot forge without the publisher's private key.
Related Modules
Source: mlab Academy — Cybersecurity Awareness Platform
URL: https://academy.mlab.sh//page/file-hash
Module: What is a file hash? — Fundamentals
Disclaimer: This content is for awareness purposes only.