Hashing Algorithms Compared: MD5, SHA-1, SHA-256, SHA-512, BLAKE2
You need to verify file integrity, generate checksums, or create unique identifiers. But which hashing algorithm should you use? MD5 is fast but broken. SHA-1 is deprecated. SHA-256 is the standard but slower. BLAKE2 claims to be faster than MD5 while being secure. This guide compares major hashing algorithms so you can choose the right one for your use case.
Quick Comparison Table
| Algorithm | Output Size | Security Status | Speed | Use Case |
|---|---|---|---|---|
| MD5 | 128 bits | Broken | Very fast | Non-security checksums only |
| SHA-1 | 160 bits | Deprecated | Fast | Legacy systems (avoid new use) |
| SHA-256 | 256 bits | Secure | Moderate | General purpose, security-critical |
| SHA-512 | 512 bits | Secure | Moderate | Extra security margin, 64-bit systems |
| BLAKE2b | Up to 512 bits | Secure | Very fast | Performance-critical applications |
| BLAKE2s | Up to 256 bits | Secure | Very fast | 32-bit systems, embedded |
Algorithm Deep Dive
MD5 (Message-Digest Algorithm 5)
MD5 produces a 128-bit (16-byte) hash value, typically represented as a 32-character hexadecimal string. Released in 1991, it was the standard for years.
# MD5 hash example
echo -n "Hello World" | md5sum
# b10a8db164e0754105b7a99be72e3fe5
# File checksum
md5sum large-file.zip
# a3b5c7d9e1f2... large-file.zipWhy it's broken: In 2004, researchers demonstrated collision attacks—finding two different inputs that produce the same MD5 hash. By 2012, the Flame malware exploited MD5 collisions to forge Windows Update certificates.
# Collision example (conceptual)
# Different files can produce same MD5 hash
md5(file_A) = "d41d8cd98f00b204e9800998ecf8427e"
md5(file_B) = "d41d8cd98f00b204e9800998ecf8427e"
# file_A != file_B (collision!)When to use MD5:
- Non-security checksums (file transfer verification where malicious tampering is not a concern)
- Deduplication and caching (when collision resistance isn't critical)
- Legacy system compatibility
When NOT to use MD5:
- Digital signatures
- Certificate validation
- Any security-critical application
- Password hashing (use bcrypt/Argon2 instead)
SHA-1 (Secure Hash Algorithm 1)
SHA-1 produces a 160-bit (20-byte) hash. It was the successor to MD5 and used extensively in SSL certificates, Git commits, and digital signatures.
# SHA-1 hash example
echo -n "Hello World" | sha1sum
# 0a4d55a8d778e5022fab701977c5d840bbc486d0
# Git uses SHA-1 for commit IDs
git log --oneline
# a3b5c7d Fix authentication bugWhy it's deprecated: In 2017, Google and CWI Amsterdam demonstrated the first practical SHA-1 collision attack (SHAttered). They created two different PDF files with identical SHA-1 hashes.
# The SHAttered attack
sha1(pdf_good.pdf) = "38762cf7f55934b34d179ae6a4c80cadccbb7f0a"
sha1(pdf_evil.pdf) = "38762cf7f55934b34d179ae6a4c80cadccbb7f0a"
# Different content, same hash!Current status:
- Major browsers stopped accepting SHA-1 certificates in 2017
- Git is transitioning to SHA-256 (git config --global init.objectFormat sha256)
- Still used in legacy systems but should be migrated
SHA-256 (SHA-2 Family)
SHA-256 is part of the SHA-2 family, producing a 256-bit (32-byte) hash. It's currently the industry standard for security-critical applications.
# SHA-256 hash example
echo -n "Hello World" | sha256sum
# a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e
# Verify downloaded file
curl -O https://example.com/software.tar.gz
curl -O https://example.com/software.tar.gz.sha256
sha256sum -c software.tar.gz.sha256
# software.tar.gz: OKWhy SHA-256 is the standard:
- No known practical attacks (as of 2026)
- 256-bit output provides 128-bit collision resistance
- Widely implemented in all major languages and systems
- Used in TLS certificates, Bitcoin, digital signatures
# Python SHA-256 example
import hashlib
def hash_file(filepath):
sha256 = hashlib.sha256()
with open(filepath, 'rb') as f:
for chunk in iter(lambda: f.read(8192), b''):
sha256.update(chunk)
return sha256.hexdigest()
# Hash a file
file_hash = hash_file('document.pdf')
print(f"SHA-256: {file_hash}")Use the Hash/Checksum Generator to compute SHA-256 hashes for text input, or the Server-side Hash Calculator for large files.
SHA-512 (SHA-2 Family)
SHA-512 produces a 512-bit (64-byte) hash. It offers a larger security margin and is actually faster than SHA-256 on 64-bit processors.
# SHA-512 hash example
echo -n "Hello World" | sha512sum
# 2c74fd17edafd80e8447b0d46741ee243b7eb74dd2149a0ab1b9246fb30382f27e853d8585719e0e6...
# Compare output lengths
SHA-256: 64 hex characters (256 bits)
SHA-512: 128 hex characters (512 bits)SHA-256 vs SHA-512 performance:
# On 64-bit systems (counter-intuitive results)
# SHA-512 uses 64-bit operations, which are native on 64-bit CPUs
# SHA-256 uses 32-bit operations
# Typical benchmarks on modern 64-bit CPU:
SHA-256: ~500 MB/s
SHA-512: ~700 MB/s # Faster despite larger output!
# On 32-bit systems, SHA-256 is fasterWhen to use SHA-512:
- 64-bit server environments where performance matters
- When you need extra security margin for long-term storage
- Applications already using 512-bit hashes (HMAC-SHA-512, etc.)
BLAKE2 (BLAKE2b and BLAKE2s)
BLAKE2 is a cryptographic hash function designed to be faster than MD5 while being as secure as SHA-3. It comes in two variants: BLAKE2b (optimized for 64-bit) and BLAKE2s (optimized for 32-bit).
# BLAKE2b example (Python)
import hashlib
# 256-bit BLAKE2b hash
h = hashlib.blake2b(b"Hello World", digest_size=32)
print(h.hexdigest())
# 256-bit output
# 512-bit BLAKE2b hash (default)
h = hashlib.blake2b(b"Hello World")
print(h.hexdigest())
# 512-bit outputBLAKE2 performance advantages:
# Typical benchmarks on modern CPU:
MD5: ~1000 MB/s
SHA-256: ~500 MB/s
SHA-512: ~700 MB/s
BLAKE2b: ~1000 MB/s # As fast as MD5, but secure!
BLAKE2s: ~800 MB/s # For 32-bit systemsWhy BLAKE2 is fast:
- Designed for modern CPU architectures
- Fewer rounds than SHA-256 (12 vs 64) with equivalent security
- Optimized for parallel execution
- Built-in keyed hashing (MAC) without HMAC overhead
# BLAKE2 keyed hashing (built-in MAC)
import hashlib
key = b"my-secret-key"
h = hashlib.blake2b(b"Message to authenticate", key=key)
print(h.hexdigest())
# Equivalent to HMAC-SHA-512 but faster
# No need for outer/inner key padding like HMACWhen to use BLAKE2:
- Performance-critical applications (file hashing, content addressing)
- New projects without SHA-256 compatibility requirements
- When you need both hashing and MAC functionality
- Embedded systems (BLAKE2s for 32-bit)
Performance Benchmarks
Real-world performance varies by implementation, hardware, and data size. Here are typical benchmarks on modern hardware:
# Benchmark: Hashing 1 GB file on AMD Ryzen 9 5900X
Algorithm | Time | Throughput
------------|-----------|------------
MD5 | 0.98s | 1020 MB/s
SHA-1 | 1.52s | 658 MB/s
SHA-256 | 1.95s | 513 MB/s
SHA-512 | 1.41s | 709 MB/s
BLAKE2b | 0.96s | 1041 MB/s
BLAKE2s | 1.24s | 806 MB/s
# With hardware acceleration (SHA-NI instructions):
SHA-256 | 0.31s | 3226 MB/s # 6x faster!
# Modern CPUs with SHA-NI make SHA-256 very competitiveHardware acceleration note: Intel and AMD CPUs with SHA-NI extensions can accelerate SHA-256 significantly. Check with:
# Linux: Check for SHA-NI support
grep -o 'sha_ni' /proc/cpuinfo | head -1
# Output: sha_ni (if supported)
# macOS (Apple Silicon has hardware SHA)
sysctl hw.optional.armv8_sha256
# hw.optional.armv8_sha256: 1Security Comparison
Collision Resistance
Collision resistance measures how hard it is to find two different inputs with the same hash. For an n-bit hash, ideal collision resistance is 2^(n/2) operations (birthday attack).
# Collision resistance (operations to find collision)
Algorithm | Output Bits | Ideal | Actual (2026)
------------|-------------|----------------|---------------
MD5 | 128 | 2^64 | 2^18 (BROKEN)
SHA-1 | 160 | 2^80 | 2^63 (BROKEN)
SHA-256 | 256 | 2^128 | 2^128 (SECURE)
SHA-512 | 512 | 2^256 | 2^256 (SECURE)
BLAKE2b | 512 | 2^256 | 2^256 (SECURE)Pre-image Resistance
Pre-image resistance measures how hard it is to find an input that produces a given hash output. All listed algorithms (including MD5) still have acceptable pre-image resistance.
# Pre-image resistance (operations to reverse hash)
Algorithm | Ideal | Practical Status
------------|----------------|------------------
MD5 | 2^128 | Weakened but not broken
SHA-1 | 2^160 | Weakened but not broken
SHA-256 | 2^256 | Secure
SHA-512 | 2^512 | Secure
BLAKE2b | 2^512 | Secure
# Note: MD5/SHA-1 collision attacks don't help reverse hashes
# But their weakened state makes them unsuitable for securityPractical Decision Guide
Use MD5 When:
- Non-security checksums: Verifying file transfer completed correctly (no malicious tampering concern)
- Deduplication: Finding duplicate files in your own storage
- Cache keys: Generating cache identifiers for content
- Legacy compatibility: Interacting with systems that require MD5
Avoid SHA-1, Migrate to SHA-256
- SHA-1 should not be used for new projects
- Plan migration for existing SHA-1 usage
- Git is transitioning:
git config --global init.objectFormat sha256
Use SHA-256 When:
- Security-critical verification: Downloading software, verifying packages
- Digital signatures: Signing documents, code, certificates
- Blockchain/cryptocurrency: Bitcoin uses SHA-256 extensively
- API authentication: HMAC-SHA-256 for request signing
- Compliance requirements: Many standards mandate SHA-256
Use SHA-512 When:
- 64-bit server environments: May be faster than SHA-256
- Long-term archival: Extra security margin for decades
- Key derivation: PBKDF2-HMAC-SHA-512 for passwords
Use BLAKE2 When:
- Performance is critical: High-throughput file processing
- New projects without compatibility constraints: Modern applications
- Need keyed hashing: Built-in MAC without HMAC overhead
- Embedded/IoT: BLAKE2s for 32-bit systems
Implementation Examples
Python: All Algorithms
import hashlib
data = b"Hello World"
# MD5 (non-security use only)
md5_hash = hashlib.md5(data).hexdigest()
# SHA-1 (deprecated, avoid)
sha1_hash = hashlib.sha1(data).hexdigest()
# SHA-256 (recommended)
sha256_hash = hashlib.sha256(data).hexdigest()
# SHA-512
sha512_hash = hashlib.sha512(data).hexdigest()
# BLAKE2b (fast and secure)
blake2b_hash = hashlib.blake2b(data).hexdigest()
# BLAKE2s (for 32-bit systems)
blake2s_hash = hashlib.blake2s(data).hexdigest()
print(f"MD5: {md5_hash}")
print(f"SHA-1: {sha1_hash}")
print(f"SHA-256: {sha256_hash}")
print(f"SHA-512: {sha512_hash}")
print(f"BLAKE2b: {blake2b_hash}")
print(f"BLAKE2s: {blake2s_hash}")Node.js: File Hashing
const crypto = require('crypto');
const fs = require('fs');
function hashFile(filepath, algorithm = 'sha256') {
return new Promise((resolve, reject) => {
const hash = crypto.createHash(algorithm);
const stream = fs.createReadStream(filepath);
stream.on('data', data => hash.update(data));
stream.on('end', () => resolve(hash.digest('hex')));
stream.on('error', reject);
});
}
// Usage
async function main() {
const sha256 = await hashFile('document.pdf', 'sha256');
const sha512 = await hashFile('document.pdf', 'sha512');
const blake2b = await hashFile('document.pdf', 'blake2b512');
console.log('SHA-256:', sha256);
console.log('SHA-512:', sha512);
console.log('BLAKE2b:', blake2b);
}
main();Command Line: Compare Hashes
# Generate all hashes for a file
file="important-document.pdf"
echo "MD5: $(md5sum "$file" | cut -d' ' -f1)"
echo "SHA-1: $(sha1sum "$file" | cut -d' ' -f1)"
echo "SHA-256: $(sha256sum "$file" | cut -d' ' -f1)"
echo "SHA-512: $(sha512sum "$file" | cut -d' ' -f1)"
# BLAKE2b (if b2sum is installed)
echo "BLAKE2b: $(b2sum "$file" | cut -d' ' -f1)"Practical Tools
For quick hash generation without writing code:
- Hash/Checksum Generator - Compute MD5, SHA-1, SHA-256, SHA-512 hashes for text input directly in your browser
- Server-side Hash Calculator - Enterprise-grade hash generation for large files with high-performance server-side processing
Summary
- MD5: Fast but cryptographically broken. Use only for non-security checksums and legacy compatibility.
- SHA-1: Deprecated with practical collision attacks. Migrate to SHA-256.
- SHA-256: The current standard. Secure, widely supported, and fast with hardware acceleration.
- SHA-512: Extra security margin, faster than SHA-256 on 64-bit systems.
- BLAKE2: As fast as MD5, as secure as SHA-256. Excellent for new projects without compatibility constraints.
For most developers, SHA-256 is the right choice. It's secure, universally supported, and increasingly fast with hardware acceleration. Use the Hash/Checksum Generator for quick text hashing or the Server-side Hash Calculator for large file verification.