โ† Back to Blog

MD5 vs SHA1 vs SHA256: Which to Use?

2026-04-06 ยท 5 min read

Quick Comparison of Three Algorithms

Algorithm  Output Bits  Hex Chars  Status
MD5        128          32         Broken (collision attacks practical)
SHA1       160          40         Broken (collision attacks demonstrated)
SHA256     256          64         Secure (no known practical attacks)

Performance (higher = faster):
MD5    โ‰ˆ 100%
SHA1   โ‰ˆ 80%
SHA256 โ‰ˆ 40%

SHA1 Security Status

SHA1's security status falls between MD5 and SHA256: more secure than MD5, but proven to no longer be secure. In 2017, Google and CWI Institute completed the first real SHA1 collision attack (the SHAttered project), generating two PDF files with different content but identical SHA1 values. This attack consumed approximately 6,500 CPU-years and 100 GPU-years of computation โ€” enormous cost, but proving SHA1 is no longer secure against well-resourced attackers.

Major browsers and Certificate Authorities stopped accepting SHA1-signed TLS certificates starting 2016โ€“2017. Git still uses SHA1 for object identification, but the practical collision threat in Git's use case is relatively manageable, and Git is already transitioning to SHA256.

Algorithm Recommendations by Scenario

SHA1's Historical Significance

SHA1 was designed by NSA and published in 1995, long serving as the foundation of internet security infrastructure โ€” TLS certificates, SSH keys, PGP/GPG signatures, Git version control, and more all used SHA1. With 32 more bits than MD5 (160 vs 128), it provided a stronger security margin, but was eventually broken as computing power increased. SHA1's retirement is a normal part of cryptographic evolution, reminding us that security standards must be updated over time.

Length Extension Attack: A Shared Weakness

MD5, SHA1, and SHA256 are all based on Merkle-Damgรฅrd construction, making all three vulnerable to Length Extension Attacks. This attack allows an attacker to compute the hash of hash(secret + message + attacker_controlled) without knowing the original message content. The fix is to use HMAC (wrapping the message with a key), or to use SHA-3 which is not affected by this attack.

Simple Decision Tree

Is this security-sensitive?
โ”œโ”€ YES โ†’ Use SHA256 (or SHA-3/SHA-512)
โ”‚        Never use MD5 or SHA1
โ””โ”€ NO (e.g., deduplication, caching)
   โ”œโ”€ Speed critical? โ†’ MD5 (simple, fast)
   โ””โ”€ Otherwise โ†’ SHA256 (future-proof)

Try the free tool now

Use Free Tool โ†’