Hashing Explained: MD5, SHA-256 and Why Passwords Need Something Else
What a hash function is, what it is good for, why MD5 is broken for security but fine for checksums, and the right way to store passwords.

Hashing is one of those topics where a small misunderstanding produces a serious security hole. The concept itself is simple; the confusion is almost always about which hash to use for which job.
What a hash function is
A hash function takes input of any size and produces a fixed-size output. The same input always gives the same output. A one-character change gives a completely different output. And crucially, it is designed to be a one-way trip: you cannot reverse the output back into the input.
Three properties define a good cryptographic hash:
- Deterministic — same input, same output, always.
- Preimage resistant — given a hash, you cannot find an input that produces it.
- Collision resistant — you cannot find two different inputs producing the same hash.
Hashing is not encryption
This confusion causes real damage, so it is worth stating plainly. Encryption is reversible — with the key you get the original data back. Hashing is not reversible — there is no key and no way back.
That means you encrypt data you need to read later (a stored document, a message in transit) and you hash data you only ever need to compare (a password, a file fingerprint).
The common algorithms and their status
MD5 produces a 128-bit hash. It is cryptographically broken — collisions can be produced deliberately and cheaply. Never use it for signatures, certificates, security tokens or passwords. It is still perfectly acceptable as a fast non-security checksum: detecting whether a file changed, deduplicating uploads, cache keys.
SHA-1 is also broken for security purposes and is being removed everywhere. Treat it as legacy.
SHA-256 (part of the SHA-2 family) is the current default for general-purpose cryptographic hashing — file integrity, digital signatures, blockchain, content addressing. It has no practical attacks.
SHA-3 and BLAKE3 are modern alternatives. BLAKE3 in particular is extremely fast and worth considering for large-scale integrity checking.
Why passwords need a different kind of hash entirely
Here is the counter-intuitive part. SHA-256 is excellent and you should still not use it for passwords.
The reason is speed. Modern hardware computes billions of SHA-256 hashes per second. If your database leaks, an attacker runs a dictionary of common passwords through the same function and matches them almost instantly. The strength of the algorithm is irrelevant; the problem is that it is fast, and password cracking is a brute-force game.
Password hashing needs functions that are deliberately slow and memory-hungry:
- Argon2id — the current recommendation, resistant to both GPU and side-channel attacks.
- bcrypt — older, extremely well tested, still perfectly acceptable.
- scrypt — memory-hard, a reasonable alternative.
These take a tunable amount of work per hash. Set the cost so a single verification takes something like 100–250 milliseconds on your hardware: unnoticeable to a user logging in, catastrophic for someone trying billions of guesses.
Salt and pepper
A salt is random data, unique per user, stored alongside the hash. It ensures two users with the same password get different hashes and defeats precomputed rainbow tables. Every proper password hashing library generates and embeds a salt automatically — you do not need to manage this yourself, and you should not try.
A pepper is a secret value shared across all passwords, stored outside the database (in an environment variable or secrets manager). It means a database leak alone is not enough to start cracking. Optional, but cheap.
Practical checklist
- Never store passwords in plain text, encrypted, or hashed with a fast algorithm.
- Use a maintained library implementing Argon2id or bcrypt; do not implement it yourself.
- Compare hashes with a constant-time comparison function to avoid timing attacks.
- Use SHA-256 for file integrity and content addressing.
- MD5 is fine for cache keys and change detection, and nowhere else.
- Verify downloads against a published SHA-256 checksum.
- Re-hash a user's password with stronger parameters when they next log in, if you have raised your cost factor.
The rule that covers ninety percent of it: fast hashes for integrity, slow hashes for secrets.


