MD5 vs SHA-256: which hash function should you use? Written on . Posted in Tutorials.
MD5 is broken — stop using it for security
MD5 was deprecated for cryptographic use in 2004 when researchers demonstrated collision attacks. Today, MD5 collisions can be computed in seconds on consumer hardware. SHA-1 was broken in 2017 (Google's SHAttered attack). Neither should be used for any security-sensitive purpose.
The hash function decision tree
Hashing passwords?
Never use a general-purpose hash function (MD5, SHA-256, SHA-3) for passwords. Use a password hashing function designed to be slow:
- Argon2id — winner of the Password Hashing Competition (2015), recommended today
- bcrypt — solid, widely supported, limited to 72-byte inputs
- scrypt — memory-hard, good for high-value targets
// PHP — Laravel default
Hash::make('password'); // uses bcrypt or argon2 depending on config
// Node.js
const hash = await argon2.hash('password', { type: argon2.argon2id });
File integrity / checksums?
Use SHA-256. It is fast enough for file hashing, not yet broken, and universally supported. SHA-512 is slightly slower but adds a safety margin. Use these for verifying download integrity, deduplication, and caching keys.
Digital signatures / certificates?
Use SHA-256 (RSA-SHA256 or ECDSA with P-256). CAs stopped issuing SHA-1 certificates in 2017. Never request a SHA-1 certificate.
Non-security use cases (deduplication, ETags, caching)?
MD5 and SHA-1 are acceptable here because you only care about speed and uniqueness, not collision resistance. Many CDNs still use MD5 for ETags. That is fine — an attacker cannot exploit an ETag collision for anything meaningful.
Performance comparison (hashing a 1MB file)
| Algorithm | Speed | Output size | Security status |
|---|---|---|---|
| MD5 | ~600 MB/s | 128 bits | Broken for crypto |
| SHA-1 | ~400 MB/s | 160 bits | Broken for crypto |
| SHA-256 | ~250 MB/s | 256 bits | Secure ✓ |
| SHA-3-256 | ~150 MB/s | 256 bits | Secure ✓ |
| BLAKE3 | ~3,000 MB/s | 256 bits | Secure ✓ |
BLAKE3 is the modern choice when you need maximum speed with strong security — it is 10× faster than SHA-256 and passes all security requirements. Not yet in browser SubtleCrypto but available in Rust, Go, Python, and Node (via blake3 package).
Generate a hash instantly
We have separate, free generators for MD5, SHA-1, SHA-256, and SHA-512 — no signup, runs in your browser. Start with SHA-256, the practical default for file integrity checks.