Skip to main content

MD5 vs SHA-256 — Which Hash Function Should You Use?

Compare MD5 and SHA-256 cryptographic hash functions. Understand security vulnerabilities, speed differences, and which to use for passwords, files, and checksums.

Output Length
MD5128 bits (32 hex chars)
SHA-256256 bits (64 hex chars)
Collision Resistance
MD5Broken — practical attacks exist
SHA-256No known practical attacks
Relative Speed
MD5Very fast
SHA-256Fast (slower than MD5)
Password Hashing
MD5Never use
SHA-256Not ideal alone — use bcrypt/Argon2
File Checksums
MD5Acceptable for corruption detection
SHA-256Preferred for security
Digital Signatures
MD5Not acceptable
SHA-256Standard choice
TLS Certificates
MD5Deprecated, rejected
SHA-256Current standard
Compliance
MD5Not compliant
SHA-256NIST, FIPS approved

Verdict

SHA-256 is the correct choice for any security-sensitive operation. MD5 is only acceptable for fast non-security checksums (detecting accidental file corruption in trusted environments). For password hashing, use neither — use bcrypt, scrypt, or Argon2 which are designed to be slow and have work factors.

The MD5 Collision Attack Explained

A collision attack means finding two different inputs M1 and M2 such that hash(M1) = hash(M2). For MD5, this became computationally feasible in 2004 and has been progressively cheaper since. In 2008, a team demonstrated creating two X.509 SSL certificates with different content but identical MD5 signatures, allowing them to forge a certificate authority signature. This real-world attack on certificate infrastructure is why all major browsers and CAs stopped accepting MD5-signed certificates years ago. Today, birthday attacks against MD5 can be performed in seconds on consumer hardware. For anything requiring collision resistance, MD5 is simply broken.

Why 'Fast' Is Bad for Password Hashing

MD5 and SHA-256 are both optimized to be fast. A modern NVIDIA GPU can compute 10-20 billion MD5 hashes per second and 4-8 billion SHA-256 hashes per second. This is catastrophic for password security: if an attacker steals a database of SHA-256 hashed passwords, they can attempt hundreds of millions of common passwords per second until they find matches. bcrypt was designed in 1999 specifically to be slow and configurable. Argon2, the 2015 Password Hashing Competition winner, adds memory-hardness (requiring gigabytes of RAM), making parallel GPU attacks economically infeasible. Always use these purpose-built algorithms for password storage.

Modern Hashing in Practice

Understanding which algorithm to use in practice: for TLS certificates and PKI, SHA-256 is the current standard (SHA-1 was deprecated in 2017 and SHA-384 is used for some high-assurance certificates). For digital code signing, SHA-256. For file integrity verification in software distribution (verifying you downloaded the right file), SHA-256. For data deduplication in storage systems where adversarial collision attacks are not relevant, SHA-1 or even MD5 may still appear in legacy systems. For API HMAC authentication, HMAC-SHA-256. For password storage: Argon2id (modern default), bcrypt (proven, widely supported), or scrypt. The answer is almost never plain SHA-256 for passwords.

Frequently Asked Questions

Related Tools