Hashing is the backbone of modern digital security. It's used for everything from storing passwords and verifying file downloads to proving that a blockchain transaction is valid.
But with so many algorithms—MD5, SHA-1, SHA-256, SHA-512—which one should you use? This guide breaks down the strengths and weaknesses of each.
What is a Hash Function?#
A hash function takes an input of any size (a password, a file, a hard drive image) and produces a fixed-size string of characters, called a hash or digest.
Key Properties:
- Deterministic: The same input always produces the same hash.
- One-Way: You cannot "decrypt" a hash back to the original input.
- Avalanche Effect: Changing just 1 bit of input drastically changes the output.
- Collision Resistant: It should be impossible to find two inputs that produce the same hash.
The Algorithms: MD5 vs SHA#
1. MD5 (Message Digest 5) - The "Broken" One
MD5 is fast and produces a 128-bit hash. However, it is cryptographically broken. Researchers can generate collisions (two files with the same hash) in seconds.
Use for: Non-critical file integrity checks (checksums), caching keys.
Never use for: Passwords, digital signatures.
2. SHA-1 (Secure Hash Algorithm 1) - The "Retired" One
SHA-1 was the standard for SSL certificates for years until Google shattered it in 2017. Like MD5, it is no longer considered secure against well-funded attackers.
Use for: Legacy git repositories (Git still uses SHA-1 internally).
Never use for: New security systems.
3. SHA-256 (Secure Hash Algorithm 2) - The Standard
SHA-256 is the gold standard for security today. It powers Bitcoin, SSL certificates, and most secure apps. It produces a 256-bit hash that is computationally impossible to reverse or collide.
Use for: Everything requiring real security.
Output Examples#
See how the output length differs for the input "hello":
Input: "hello"
MD5 (32 chars):
5d41402abc4b2a76b9719d911017c592
SHA-1 (40 chars):
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
SHA-256 (64 chars):
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824A Note on Passwords#
Do not use simple hashes for passwords.
Even SHA-256 is too fast for password storage, making it vulnerable to brute-force attacks. For user passwords, always use slow algorithms specifically designed for the purpose, like bcrypt, Argon2, or PBKDF2.
Frequently Asked Questions
Can I decrypt an MD5 hash?▼
What is a "file checksum"?▼
Is SHA-256 encryption?▼
Generate SHA & MD5 Hashes
Generate secure hashes for passwords, check file integrity, or verify API signatures instantly in your browser.
Related Articles
Base64 Encoding Explained
Learn how Base64 encoding works, why we use it for images and email, and the difference between encoding and encryption.
UUID vs GUID
Confusion cleared: The definitive explanation of UUIDs vs GUIDs. Learn about v4 random generation, collision probabilities, and database performance.