SHA-1 vs SHA-256 vs SHA-512
SHA-1, SHA-256, and SHA-512 are all members of the Secure Hash Algorithm family, but they differ significantly in security, output size, and performance. Choosing the right one depends on your security requirements, performance constraints, and compatibility needs.
Quick Comparison
| Feature | SHA-1 | SHA-256 | SHA-512 |
|---|---|---|---|
| Output size | 160 bits (20 bytes) | 256 bits (32 bytes) | 512 bits (64 bytes) |
| Security level | 80 bits (broken) | 128 bits (secure) | 256 bits (secure) |
| Rounds | 80 | 64 | 80 |
| Word size | 32 bits | 32 bits | 64 bits |
| Block size | 512 bits | 512 bits | 1024 bits |
| Status | Deprecated | Recommended | Recommended |
Security Analysis
SHA-1 produces a 160-bit hash, giving it a collision resistance of 2^80 operations by the birthday paradox. In 2017, Google demonstrated the SHAttered attack, producing the first practical SHA-1 collision using approximately 2^63 operations. This proved that SHA-1 no longer provides adequate security for any purpose where collision resistance matters.
SHA-256 provides 128-bit collision resistance. As of 2026, no practical attack reduces SHA-256's security below its design strength. It is approved by NIST for use in US government applications and is the standard for SSL/TLS certificates, blockchain, and digital signatures.
SHA-512 provides 256-bit collision resistance. It is even stronger than SHA-256 but offers more security than most applications need. The extra strength comes with a performance cost on 32-bit systems, but on 64-bit systems SHA-512 can actually be faster than SHA-256.
When SHA-1 Is Still Found
Despite being deprecated, SHA-1 still appears in legacy systems:
- Git uses SHA-1 for commit hashes (though Git has added SHA-256 support)
- Old digital signatures signed with SHA-1 certificates
- Legacy file checksums distributed before the deprecation
- Some version control systems and backup tools
If you encounter SHA-1 in a new system, migrate to SHA-256 immediately.
Performance Considerations
On 32-bit processors, SHA-256 is faster than SHA-512 because SHA-512 operates on 64-bit words, requiring extra instructions. On 64-bit processors with hardware acceleration (SHA extensions), SHA-256 and SHA-512 both perform well, with SHA-256 typically being slightly faster.
For hashing large files, the difference is measurable but rarely significant for typical use. A file that takes 1 second to hash with SHA-256 might take 0.7 seconds with SHA-1 or 1.3 seconds with SHA-512. For most applications, the security benefits of SHA-256 far outweigh the minor performance difference.
Code Examples
// PHP
echo hash('sha1', 'hello'); // aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
echo hash('sha256', 'hello'); // 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
echo hash('sha512', 'hello'); // 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043
import hashlib
print(hashlib.sha1(b'hello').hexdigest())
print(hashlib.sha256(b'hello').hexdigest())
print(hashlib.sha512(b'hello').hexdigest())
// Node.js
const crypto = require('crypto');
console.log(crypto.createHash('sha1').update('hello').digest('hex'));
console.log(crypto.createHash('sha256').update('hello').digest('hex'));
console.log(crypto.createHash('sha512').update('hello').digest('hex'));
Recommendation
| Use Case | Recommendation |
|---|---|
| SSL/TLS certificates | SHA-256 |
| File integrity verification | SHA-256 or SHA-512 |
| Digital signatures | SHA-256 |
| Password hashing | bcrypt or argon2 (not SHA) |
| Blockchain / crypto | SHA-256 |
| Long-term archiving | SHA-512 |
| Legacy compatibility | Migrate to SHA-256 |
Online Tools
Use the SHA-1 Generator, SHA-256 Generator, and SHA-512 Generator tools to compute hashes instantly. The Multiple Hash Generator generates all hash types at once for comparison.
Conclusion
SHA-1 is broken and should not be used. SHA-256 is the recommended standard for most applications. SHA-512 provides extra security for high-risk environments. Default to SHA-256 unless you have a specific reason to choose otherwise.