MD5 vs SHA-256: which hash function should you use? Written on . Posted in Tutorials.

MD5 vs SHA-256: which hash function should you use?
Advertisement

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.

Advertisement

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)

AlgorithmSpeedOutput sizeSecurity status
MD5~600 MB/s128 bitsBroken for crypto
SHA-1~400 MB/s160 bitsBroken for crypto
SHA-256~250 MB/s256 bitsSecure ✓
SHA-3-256~150 MB/s256 bitsSecure ✓
BLAKE3~3,000 MB/s256 bitsSecure ✓

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.

Open SHA-256 Hash Generator →

Advertisement

Comments

Sign in or create an account to leave a comment.

No comments yet

Be the first to share your thoughts!