Skip to content

MD5 vs SHA-1 vs SHA-256 vs SHA-512: Which Hash to Use

Last updated Published by Hyperdusk Ltd

The short answer

MD5 and SHA-1 are broken for collision resistance: different inputs with the same digest have been produced for both. SHA-256 and SHA-512 are NIST-approved, with 128 and 256 bits of collision resistance. Use SHA-256 for checksums and signatures. Use none of the four to store passwords, which needs a slow function such as Argon2id or bcrypt.

Generate an MD5, SHA-1, SHA-256 or SHA-512 hash →

Key differences

MD5, SHA-1, SHA-256 and SHA-512 side by side
MD5SHA-1SHA-256SHA-512
Digest size128 bits160 bits256 bits512 bits
Length as hex32 characters40 characters64 characters128 characters
Specified inRFC 1321FIPS 180-4FIPS 180-4 (SHA-2)FIPS 180-4 (SHA-2)
Collision resistanceBroken: collisions found in seconds on a PCBroken: first collision published in 2017128-bit strength (NIST)256-bit strength (NIST)
StandingNot acceptable where collision resistance is requiredDeprecated by NIST; to be phased out by the end of 2030NIST-approvedNIST-approved
Reasonable use todayDetecting accidental corruption; matching an existing checksumMatching an existing checksumChecksums, signatures, HMACAs SHA-256, where a longer digest is specified
Hex lengths checked by hashing the string "abc" with Node.js crypto.

What does "broken" mean for MD5 and SHA-1?

A cryptographic hash is expected to resist three things: finding two inputs with the same digest (a collision), finding an input for a given digest (a preimage), and finding a second input that matches a given input's digest (a second preimage). MD5 and SHA-1 have failed the first.

For MD5, RFC 6151 records that the first collision pairs were published in 2004, that later attacks find a collision in about a minute on a notebook PC, with one paper claiming 10 seconds or less, and that the attacks were applied to X.509 certificates. It concludes that MD5 is no longer acceptable where collision resistance is required, such as digital signatures. Preimage resistance has held up better: the best attack the RFC cites still needs about 2^123.4 work.

For SHA-1, researchers at CWI Amsterdam and Google announced the first practical collision on 23 February 2017: two PDF files with different content and the same SHA-1 digest. They report it took 9,223,372,036,854,775,808 SHA-1 computations, which is 2^63, using 6,500 years of CPU time and 110 years of GPU time.

Is SHA-1 still allowed?

For new work, no. NIST deprecated SHA-1 in 2011 and disallowed it for digital signatures at the end of 2013. In December 2022 it announced that SHA-1 should be phased out everywhere by 31 December 2030 and recommended that anyone relying on it for security move to SHA-2 or SHA-3.

Existing identifiers and published checksums that use SHA-1 still work as identifiers. What is lost is the guarantee that nobody can construct two files with the same value.

Should I use SHA-256 or SHA-512?

Both belong to the SHA-2 family in FIPS 180-4, and NIST approves both. NIST rates a hash's collision resistance at half its output size and its preimage resistance at its full output size.

NIST security strengths of approved hash functions
AlgorithmDigestCollision resistancePreimage resistance
SHA-1160 bitsUnder 80 bits160 bits
SHA-256256 bits128 bits256 bits
SHA-384384 bits192 bits384 bits
SHA-512512 bits256 bits512 bits
SHA3-256256 bits128 bits256 bits
Read from the security-strength table on NIST's Hash Functions page. MD5 is not in the table because it is not a NIST-approved algorithm.

Pick the one your protocol, package manager or published checksum already uses. If nothing dictates it, SHA-256 gives the shorter digest: half as long to store and compare. SHA-3 is an approved alternative with a different internal design.

Why should none of them store passwords?

Because they are fast. The OWASP Password Storage Cheat Sheet says fast hashing algorithms such as SHA-256 are not suitable for password storage because they let an attacker make large numbers of guesses quickly. Password hashing needs a function that is slow on purpose, salted per password, and adjustable as hardware improves.

OWASP minimum settings for password hashing
AlgorithmMinimum configurationWhen OWASP says to use it
Argon2id19 MiB of memory, 2 iterations, parallelism 1First choice
scryptCost 2^17, block size 8, parallelism 1If Argon2id is not available
bcryptWork factor 10 or more; 72-byte password limitLegacy systems
PBKDF2-HMAC-SHA256600,000 iterationsIf FIPS-140 compliance is required
As stated in the OWASP Password Storage Cheat Sheet on 11 November 2026. OWASP revises these numbers, so check the sheet before copying them.

bcrypt is a password hashing function, not a checksum: its output is a 60-character string that contains the work factor and a random salt, so hashing the same password twice gives two different strings. OWASP now says bcrypt should only be used in legacy systems where Argon2 and scrypt are not available.

Is HMAC-MD5 broken too?

Not in the same way. HMAC combines the hash with a secret key, and RFC 6151 says the published attacks on HMAC-MD5 "do not seem to indicate a practical vulnerability when used as a message authentication code". Its guidance is that it is not urgent to remove HMAC-MD5 from existing protocols, but that new protocol designs should not use it. It names HMAC-SHA256 as an alternative.

Which should you use?

Use SHA-256 by default for file checksums, content addressing, signatures and HMAC. Use SHA-512 when a specification asks for it. Use MD5 or SHA-1 only to match a checksum that someone else already published in that format, and never where an attacker could choose the input.

For passwords, use Argon2id, or scrypt, bcrypt or PBKDF2 where your platform requires it, with the settings OWASP currently lists.

Tools for this

Sources

This page was written from the primary sources below, read on .

Published by Hyperdusk Ltd. Last updated . Figures in computed tables were produced by the method stated under each table.

All guides→