What a cryptographic hash guarantees
A hash function maps any input to a fixed-length output. Good ones are deterministic (same input, same output), fast to compute, one-way (you cannot recover the input), and collision resistant (finding two different inputs with the same output is impractical). The output length is fixed by the algorithm: 128 bits for MD5, 160 for SHA-1, 256 for SHA-256, 512 for SHA-512.
MD5 and SHA-1 are broken
MD5 collisions were demonstrated in 2004 and can now be produced in seconds. SHA-1 collisions were demonstrated in 2017 with the SHAttered attack, and chosen-prefix collisions followed. Neither should be used where an attacker benefits from creating two inputs with the same digest — code signing, certificates, tamper-evident logs, or integrity checks over untrusted data.
They remain acceptable for non-adversarial purposes: a quick checksum to see whether a download changed, or a cache key computed from your own content. Even then, prefer a modern hash unless a legacy system forces your hand.
SHA-256 and SHA-512
Both belong to the SHA-2 family and have no known practical collisions. SHA-256 is the default choice: it is what most protocols, package managers and certificate authorities use. SHA-512 produces a longer digest and is faster on 64-bit hardware, which matters for very high-throughput hashing but not for a one-off checksum.
Do not hash passwords with these
SHA-256 is deliberately fast, which is exactly what you do not want for passwords: an attacker with a GPU can try billions of candidates per second. Password storage needs a slow, memory-hard key derivation function such as Argon2id, scrypt or bcrypt, with a per-user salt. A salt does not slow down a single guess, but it prevents precomputed tables and stops two identical passwords from producing the same stored value.
Hashes versus encryption
A hash cannot be reversed, so it is not a way to hide data you need to read later. Encryption is reversible with a key; hashing is one-way by design. Integrity checks use hashes, confidentiality uses encryption, and authenticated encryption (AES-GCM, ChaCha20-Poly1305) provides both.
Choosing quickly
- File integrity, signatures, general purpose: SHA-256
- Legacy compatibility only: MD5 or SHA-1, with a comment explaining why
- Passwords: Argon2id, scrypt or bcrypt — never a plain fast hash
- Comparing secrets: a constant-time comparison, not a string equality check
Compute SHA-1, SHA-256, SHA-384 and SHA-512 side by side with our hash generator. It runs on the raw UTF-8 bytes of your input and never sends the text anywhere.