MD5 vs SHA-1 vs SHA-256: Which Hash Should You Use?
Not sure which hash algorithm to pick? This breaks down MD5, SHA-1, and SHA-256 — what they're for and when to use each.
# MD5 vs SHA-1 vs SHA-256: Which Hash Should You Use?
Cryptographic hashing turns any input into a fixed-size string. Same input always gives same output. Different inputs give different outputs (ideally). You can't reverse a hash back to the original input.
The Three You'll See
| Algorithm | Output Length | Status | Use Case |
|---|---|---|---|
| MD5 | 32 hex chars | Broken | Checksums, file integrity |
| SHA-1 | 40 hex chars | Broken | Legacy systems, git |
| SHA-256 | 64 hex chars | Secure | Passwords, signatures, blockchain |
What "Broken" Means
MD5 and SHA-1 have collision vulnerabilities — researchers found ways to create two different inputs that produce the same hash. This doesn't mean MD5 is useless, but it means you shouldn't use it for anything security-critical.
Safe uses of MD5: - File checksums (detecting accidental corruption) - Cache keys - Deduplication where intentional collisions aren't a concern
Unsafe uses of MD5: - Password storage (use bcrypt or argon2 instead) - Digital signatures - Certificate generation
When I Use Each
- MD5 — Quick file integrity checks, cache keys, ETag generation
- SHA-1 — Git uses it internally. I don't choose it for new projects.
- SHA-256 — Anything security-related: API signatures, content addressing, certificate fingerprints
Password Hashing Is Different
Don't use any of these for password storage. Passwords need slow hash functions with salt:
- bcrypt — Designed for passwords, has a work factor parameter
- argon2 — Modern password hash, won the Password Hashing Competition
- scrypt — Memory-hard, resistant to GPU attacks
MD5/SHA-1/SHA-256 are fast — that's the opposite of what you want for passwords. Fast hashes let attackers try billions of guesses per second.
Generating Hashes
Our Hash Generator computes MD5, SHA-1, and SHA-256 from any text. Free, runs in your browser, no signup.
## Hash Functions Explained
A hash function takes input of any size and produces a fixed-size output (the "hash" or "digest"). Key properties:
- Deterministic: The same input always produces the same hash.
- Fixed size: Regardless of input size, the output is always the same length (e.g., 256 bits for SHA-256).
- One-way: You cannot reverse a hash to get the original input.
- Avalanche effect: Changing one bit of input changes roughly half the output bits.
- Collision resistant: It is computationally infeasible to find two different inputs that produce the same hash.
Cryptographic vs Non-Cryptographic Hashes
- Cryptographic hashes (SHA-256, SHA-3, BLAKE3): Designed to be impossible to reverse. Used for passwords, digital signatures, and integrity verification. Slower by design.
- Non-cryptographic hashes (xxHash, FNV, MurmurHash): Faster but not secure. Used for hash tables, checksums, and bloom filters. Do not use for security purposes.
- Broken cryptographic hashes (MD5, SHA-1): Have known collision vulnerabilities. MD5 collisions can be found in seconds. Do not use for security. Still acceptable for non-security checksums.
Common Uses of Hash Functions
- Password storage: Hash the password with a salt and store the hash. When the user logs in, hash the entered password and compare.
- File integrity: Hash a file before and after transfer. If the hashes match, the file was not corrupted.
- Digital signatures: Hash the document, then encrypt the hash with a private key.
- Blockchain: Each block contains the hash of the previous block, creating a tamper-evident chain.
- Content addressing: IPFS and Git use hashes as identifiers. The hash of content becomes its address.
- Bloom filters: Probabilistic data structure that uses multiple hashes to test set membership.