What Is a Hash? Checksums, MD5 and SHA-256 Explained
- What a hash function does
- The four properties that make hashes useful
- Deterministic
- Fixed output length
- The avalanche effect
- One-way
- What hashes are used for
- Verifying a download
- Detecting duplicates and changes
- Passwords — with an important caveat
- Why MD5 and SHA-1 are called "broken"
- Why MD5 is still fine for spotting corruption
- Frequently asked questions
- Can two different files have the same hash?
- Does a matching checksum prove a download is safe?
- Is hashing the same as encryption?
On this page
- What a hash function does
- The four properties that make hashes useful
- Deterministic
- Fixed output length
- The avalanche effect
- One-way
- What hashes are used for
- Verifying a download
- Detecting duplicates and changes
- Passwords — with an important caveat
- Why MD5 and SHA-1 are called "broken"
- Why MD5 is still fine for spotting corruption
- Frequently asked questions
- Can two different files have the same hash?
- Does a matching checksum prove a download is safe?
- Is hashing the same as encryption?
You've probably seen a long string of letters and numbers next to a software download, labelled SHA-256 or MD5, and scrolled straight past it. That string is a hash — a fingerprint of the file — and it's one of the most widely used building blocks in computing. Hashes verify downloads, deduplicate storage, power Git's commit history, sign certificates and sit underneath password systems.
The idea is easy to state and slightly counter-intuitive to absorb: a hash function takes input of any size and produces a short, fixed-length output that identifies it, in a way that can't be run backwards.
What a hash function does
A hash function is a one-way transformation. You feed it any data — a single word, a 4 GB video, an empty string — and it returns a fixed-size value called a hash, digest or checksum. That value is usually shown in hexadecimal, where each character represents 4 bits.
- MD5: 128 bits, shown as 32 hex characters.
- SHA-1: 160 bits, shown as 40 hex characters.
- SHA-256: 256 bits, shown as 64 hex characters.
- SHA-512: 512 bits, shown as 128 hex characters.
So the MD5 of "hello" is 5d41402abc4b2a76b9719d911017c592, and its SHA-256 is 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824. The SHA-256 of an entire operating system image is also exactly 64 characters.
The four properties that make hashes useful
Deterministic
The same input always produces the same output, on any machine, in any language, forever. That's what makes a hash usable as a fingerprint: you can compute it today, someone else can compute it next year on a different operating system, and if the inputs match, the hashes will too.
Fixed output length
The output size depends only on the algorithm, never on the input. This is why hashes are convenient to store, compare and display — but it also means there must be collisions somewhere, since infinitely many possible inputs map onto a finite number of outputs. A good hash function just makes finding one practically impossible.
The avalanche effect
Changing even one bit of input changes the output completely and unpredictably. Hashes aren't "close" for similar inputs, so you can't tell from two hashes whether the underlying data was nearly the same or entirely different.
- SHA-256 of "hello": 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
- SHA-256 of "Hello": 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969
- One capital letter changed, and the two outputs share no visible pattern at all.
One-way
There's no function that turns a hash back into its input. A hash discards information — it's a 64-character summary of what might be gigabytes — so the original can't be reconstructed. The only way to "reverse" a hash is to guess inputs, hash each guess and compare, which is only feasible when the input is short or predictable.
What hashes are used for
Verifying a download
This is the most common everyday use. A publisher lists the SHA-256 checksum of a file on their download page. After downloading, you hash your copy and compare. If the two strings match exactly, your file is byte-for-byte identical to the one they published; if even one character differs, the file was corrupted in transit or isn't the file you think it is.
- macOS or Linux: shasum -a 256 filename (or sha256sum filename on most Linux systems).
- Windows PowerShell: Get-FileHash filename -Algorithm SHA256.
- Compare the full string, not just the first and last few characters — and compare it against the value from the official source.
Detecting duplicates and changes
Two files with the same hash are, for practical purposes, the same file. Backup tools, cloud storage and photo libraries use this to avoid storing identical files twice, and build systems use it to tell whether a file has changed since the last run. Git identifies every commit and file by its hash.
Passwords — with an important caveat
Systems don't store your password; they store something derived from it and compare on login. But a plain MD5 or SHA-256 hash is the wrong tool for that job. These algorithms are designed to be fast, and fast is exactly what an attacker wants: modern hardware can test billions of SHA-256 guesses per second against a leaked database.
Watch out
Never store passwords as plain MD5, SHA-1 or SHA-256 hashes. Use a purpose-built, deliberately slow password hashing algorithm — Argon2id, bcrypt, scrypt or PBKDF2 — which adds a unique random salt per password and makes each guess expensive. A general-purpose hash generator is for checksums and fingerprints, not password storage.
Why MD5 and SHA-1 are called "broken"
For security purposes, a hash function must be collision-resistant: it should be infeasible to find two different inputs that produce the same hash. MD5 lost that property in 2004, when researchers demonstrated practical collisions, and attacks have since become fast enough to run on a laptop. MD5 collisions were used in the real world, most famously by the Flame malware in 2012 to forge a code-signing certificate. SHA-1 followed in 2017, when Google and CWI Amsterdam published two different PDF files with the same SHA-1 hash.
That's why neither algorithm should be used for digital signatures, certificates or anywhere an attacker might craft a malicious file to match a trusted hash. For those uses, SHA-256 or stronger is the standard.
Why MD5 is still fine for spotting corruption
Collision attacks require someone deliberately constructing two files to collide. Random corruption — a flaky network, a failing disk, a truncated transfer — doesn't do that. An accidental MD5 match between a good file and a corrupted one is astronomically unlikely, so MD5 remains a perfectly reasonable, fast checksum for catching accidental damage, where nobody is trying to fool you.
Tip
Ask one question when choosing an algorithm: could anyone benefit from making two different inputs look the same? If yes — signatures, security checks, anything adversarial — use SHA-256 or better. If you're only guarding against accidents, MD5 is fine, though SHA-256 is fast enough that most people just use it everywhere.
Frequently asked questions
Can two different files have the same hash?
Mathematically, yes — collisions must exist because the output is fixed-length. With a secure algorithm like SHA-256, though, no one has ever found one, and the chance of it happening by accident is so small it can be ignored. With MD5 and SHA-1, collisions can be manufactured deliberately.
Does a matching checksum prove a download is safe?
It proves your file matches the one the publisher listed — nothing more. If an attacker compromised the download page, they could replace both the file and its checksum. That's why many projects also publish cryptographic signatures, which verify the file came from the publisher's key rather than just from their website.
Is hashing the same as encryption?
No. Encryption is designed to be reversed by anyone holding the key; hashing is designed never to be reversed at all. You encrypt data you need to read again later, and hash data you only need to compare or verify.
A hash is a fixed-length fingerprint: deterministic, one-way, and completely different for even slightly different inputs. Use SHA-256 for anything security-related, feel free to use MD5 for catching accidental corruption, and leave password storage to algorithms built specifically to be slow.
Ready to put this into practice?
Generate a Hash Free