MD5, SHA-1, SHA-256, SHA-3: Which Hash Should You Use?

Understand the differences between MD5, SHA-1, SHA-256, and SHA-3. Learn which hashes are broken, when to use each, and why you should never hash passwords with plain SHA-256.

· 4 min read

A cryptographic hash function turns any input into a fixed-size fingerprint. Change one bit of the input and the output changes completely. Hashes show up everywhere: file checksums, Git commits, digital signatures, certificate fingerprints, and (misused) password storage.

But "which hash should I use?" has different answers depending on the job. This guide sorts out the options.

What makes a hash secure?

A good cryptographic hash has three properties:

  1. Preimage resistance. Given a hash, you cannot find an input that produces it.
  2. Second-preimage resistance. Given an input, you cannot find a different input with the same hash.
  3. Collision resistance. You cannot find any two inputs with the same hash.

Collision resistance is the one that usually breaks first. An algorithm is considered broken for security once collisions can be produced cheaper than the theoretical bound.

The algorithms

MD5 (128-bit): broken

MD5 collisions have been practical since 2004 and can now be generated in seconds on a laptop. In 2008, researchers used MD5 collisions to forge a rogue CA certificate. In 2012, the Flame malware abused the same weakness.

  • Do not use for signatures, certificates, or integrity against an attacker.
  • Acceptable only for non-adversarial uses: deduplication, cache keys, or matching a checksum a vendor still publishes. Even then, prefer SHA-256.

SHA-1 (160-bit): broken

Google and CWI demonstrated the first practical SHA-1 collision (SHAttered) in 2017, and a cheaper chosen-prefix attack followed in 2020. Browsers and CAs stopped accepting SHA-1 certificates years ago, and NIST has deprecated it.

  • Do not use for new signatures or certificates.
  • Git still uses SHA-1 by default for object IDs, but with collision detection hardening, and it is migrating to SHA-256.

SHA-256 and the SHA-2 family: the default

SHA-2 includes SHA-224, SHA-256, SHA-384, and SHA-512. SHA-256 (256-bit output) is the workhorse of modern security: TLS certificates, Bitcoin, code signing, Subresource Integrity, and JWT HS256/RS256.

  • No practical attacks on collision, preimage, or second-preimage resistance.
  • Length-extension weakness: SHA-256 and SHA-512 output reveals the internal state, so SHA256(secret || message) is not a safe MAC. Use HMAC instead.
  • SHA-512 is often faster than SHA-256 on 64-bit CPUs, and SHA-512/256 gives a 256-bit output with length-extension resistance.

SHA-3 (Keccak): the backup plan

SHA-3 was standardized in 2015 after an open competition. It uses a completely different design (a sponge construction) from SHA-2, so a breakthrough against SHA-2 would not automatically affect it.

  • Immune to length extension, so SHA3-256(key || message) works as a MAC, although HMAC or KMAC is still the recommended construction.
  • Slower in software than SHA-2 on most CPUs without hardware support, and less widely supported in libraries.
  • No known weaknesses. It exists for diversity and for use cases where its design helps, not because SHA-2 is broken.

BLAKE2 and BLAKE3: fast alternatives

BLAKE2 and BLAKE3 are not NIST standards, but they are secure, widely reviewed, and much faster than SHA-2 in software. They suit checksumming large files and content-addressed storage.

Comparison

AlgorithmOutputCollisionsLength extensionUse today
MD5128-bitBrokenYesNon-security checksums only
SHA-1160-bitBrokenYesLegacy compatibility only
SHA-256256-bitNone knownYesDefault choice
SHA-512512-bitNone knownYesGood on 64-bit CPUs
SHA3-256256-bitNone knownNoDiversity, MAC-style uses
BLAKE3256-bit (variable)None knownNoFast bulk hashing

Which hash for which job?

JobUse
File integrity and download checksumsSHA-256
Digital signatures and certificatesSHA-256 or SHA-384
Subresource IntegritySHA-384 (the spec's recommendation)
Message authenticationHMAC-SHA-256
Content-addressed storageSHA-256 or BLAKE3
Cache keys, hash tablesA non-cryptographic hash (xxHash, MurmurHash)
Storing passwordsArgon2id, scrypt, or bcrypt, not a plain hash

Never hash passwords with plain SHA-256

This is the most common hash mistake. Hash functions are designed to be fast, and for passwords, fast is the problem. A modern GPU can compute billions of SHA-256 hashes per second, so an attacker with a leaked database can test enormous dictionaries of guesses in minutes.

Password hashing needs the opposite: algorithms that are deliberately slow and memory-hungry, and that include a per-user salt:

  • Argon2id: the current recommendation (OWASP lists it first).
  • scrypt: memory-hard, widely available.
  • bcrypt: older but still acceptable, with a cost factor of 10 or higher (note the 72-byte input limit).
  • PBKDF2: acceptable when FIPS compliance requires it, with a very high iteration count.

Salting alone does not rescue a fast hash. It only defeats precomputed rainbow tables.

Verifying a download

When a project publishes a SHA-256 checksum, compare it with your file's hash:

shasum -a 256 installer.dmg      # macOS
sha256sum installer.dmg          # Linux

If the checksum and the file come from the same server, the check only catches corruption. It does not protect against a compromised server. For that, you need a signature (GPG, Sigstore) verified against a key you obtained separately.

Key takeaways

  • MD5 and SHA-1 are broken for security. Avoid them in anything new.
  • SHA-256 is the safe default. Use SHA-3 or BLAKE3 when you have a specific reason.
  • For message authentication, use HMAC, not hash(secret + message).
  • For passwords, use Argon2id, scrypt, or bcrypt, never a plain fast hash.

Try the algorithms yourself in the Hash Generator. Paste text or drop in a file, and compare MD5, SHA-1, SHA-2, and SHA-3 digests side by side, all computed locally in your browser.