ToolPopToolPop
Back to BlogGuides

Hash Functions Explained: MD5, SHA-1, SHA-256 for Developers

Hash functions are fundamental to modern cryptography and software development. Learn how they work, their differences, and practical applications.

ToolPop TeamFebruary 20, 202515 min read

What Are Hash Functions?

A hash function is a mathematical algorithm that converts input data of any size into a fixed-size output, called a hash, digest, or checksum. Think of it as a digital fingerprint—unique (ideally) to the input data.

Key Properties of Cryptographic Hash Functions

1. Deterministic The same input always produces the same output.

2. Fixed Output Length Regardless of input size, output length is constant:

  • MD5: 128 bits (32 hex characters)
  • SHA-1: 160 bits (40 hex characters)
  • SHA-256: 256 bits (64 hex characters)
3. One-Way Function It's computationally infeasible to reverse the hash to find the input.

4. Avalanche Effect Small changes in input produce drastically different outputs. Changing "hello" to "Hello" produces completely different hashes.

5. Collision Resistance Finding two different inputs that produce the same hash should be computationally infeasible.

6. Pre-image Resistance Given a hash, finding any input that produces it should be computationally infeasible.

Hash Algorithms Deep Dive

MD5 (Message Digest Algorithm 5)

Developed by Ron Rivest in 1991, MD5 was widely used for decades.

Specifications:

  • Output: 128 bits (16 bytes)
  • Block size: 512 bits
  • Rounds: 64
  • Structure: Merkle-Damgard construction
Security Status: BROKEN
  • First collision found in 2004
  • Practical collision attacks demonstrated
  • Should NOT be used for security purposes
Acceptable Uses:
  • Non-security checksums
  • Cache keys
  • De-duplication (with verification)
  • Legacy system compatibility

SHA-1 (Secure Hash Algorithm 1)

Published by NSA in 1995, SHA-1 was the standard for many years.

Specifications:

  • Output: 160 bits (20 bytes)
  • Block size: 512 bits
  • Rounds: 80
  • Structure: Merkle-Damgard construction
Security Status: DEPRECATED
  • Theoretical weaknesses since 2005
  • First practical collision in 2017 (SHAttered attack)
  • Major browsers/CAs discontinued support
Should NOT be used for:
  • Digital signatures
  • Certificate validation
  • New security implementations

SHA-2 Family

Published by NSA in 2001, SHA-2 includes multiple variants.

SHA-256:

  • Output: 256 bits (32 bytes)
  • Block size: 512 bits
  • Rounds: 64
  • Most widely used variant
SHA-384:
  • Output: 384 bits (48 bytes)
  • Block size: 1024 bits
  • Truncated SHA-512
SHA-512:
  • Output: 512 bits (64 bytes)
  • Block size: 1024 bits
  • Rounds: 80
  • Better performance on 64-bit systems
Security Status: SECURE
  • No known practical attacks
  • Recommended for most security applications
  • Industry standard

SHA-3 (Keccak)

Selected through NIST competition in 2012, SHA-3 uses a different construction.

Key Differences from SHA-2:

  • Sponge construction (vs. Merkle-Damgard)
  • Different internal structure
  • Not derived from SHA-2
Security Status: SECURE
  • Alternative to SHA-2 (backup if SHA-2 broken)
  • Resistant to length extension attacks
  • Growing adoption

BLAKE2 and BLAKE3

Modern alternatives optimized for performance.

BLAKE2:

  • Faster than MD5 while being secure
  • BLAKE2b (64-bit optimized), BLAKE2s (32-bit optimized)
  • Used in Argon2 password hashing
BLAKE3:
  • Even faster with parallelization
  • Single algorithm (no variants)
  • Modern construction

Comparison Table

AlgorithmOutput SizeSpeedSecurityUse Case
MD5128 bitsVery FastBrokenLegacy, non-security
SHA-1160 bitsFastDeprecatedLegacy systems
SHA-256256 bitsModerateSecureGeneral security
SHA-384384 bitsModerateSecureHigher security
SHA-512512 bitsFast (64-bit)SecureHighest security
SHA3-256256 bitsModerateSecureSHA-2 alternative
BLAKE2bVariableVery FastSecurePerformance-critical
BLAKE3VariableFastestSecureModern applications

Practical Applications

File Integrity Verification

Verify files haven't been tampered with by comparing checksums before and after transfer.

Password Hashing

Never use raw hash functions for passwords!

Raw hashes are too fast (billions per second) and vulnerable to rainbow tables. Use specialized password hashing algorithms like Argon2, bcrypt, or scrypt instead.

Digital Signatures

Hash functions enable efficient digital signatures by hashing the document before signing with a private key.

Content Addressing

Use hashes as content identifiers (CIDs) for Git-style content addressing, IPFS, Docker image layers, and blockchain.

HMAC (Hash-based Message Authentication Code)

Combine hash functions with keys for message authentication in API authentication, session tokens, webhook verification, and JWT signatures.

Security Considerations

Collision Attacks

When two different inputs produce the same hash. Impact includes digital signature forgery, certificate substitution, and data integrity bypass.

Protection: Use collision-resistant algorithms (SHA-256+). Avoid MD5 and SHA-1 for security.

Length Extension Attacks

Merkle-Damgard hashes (MD5, SHA-1, SHA-256) are vulnerable. Given H(secret || message) and length of secret, an attacker can calculate H(secret || message || padding || extension) without knowing the secret.

Protection: Use HMAC instead of H(key || message), use SHA-3, or use BLAKE2/BLAKE3.

Rainbow Table Attacks

Pre-computed tables of hash to input mappings.

Protection: Add salt to inputs, use key derivation functions, don't hash passwords directly.

Side-Channel Attacks

Timing attacks can reveal information through comparison timing. Always use constant-time comparison functions like crypto.timingSafeEqual().

Choosing the Right Hash Function

Decision Guide

For file integrity: SHA-256 (standard) or BLAKE3 (performance)

For digital signatures: SHA-256 or SHA-384, SHA3-256 (alternative)

For content addressing: SHA-256 (compatibility) or BLAKE3 (modern systems)

For password hashing: Argon2id (preferred), bcrypt (widely supported), NEVER raw hash functions

For API authentication (HMAC): HMAC-SHA256 or HMAC-SHA384

For checksums (non-security): CRC32 (fastest), xxHash (fast, good distribution), MD5 (legacy compatibility)

Using ToolPop's Hash Generator

ToolPop provides instant hash generation for all major algorithms:

Features

  • Multiple algorithms: MD5, SHA-1, SHA-256, SHA-384, SHA-512, SHA3-256
  • Text and file hashing
  • Side-by-side comparison
  • Copy to clipboard
  • Bulk hashing

Use Cases

  • Verify downloads: Compare file hash against published checksums
  • Generate checksums: Create hashes for files you distribute
  • Compare hashes: Check if files are identical
  • Learning: Understand hash properties and differences

Conclusion

Hash functions are foundational cryptographic primitives with diverse applications. Understanding their properties, strengths, and weaknesses is essential for building secure systems.

Key takeaways:

  • MD5 and SHA-1 are broken for security—use SHA-256 or better
  • Never use raw hashes for passwords—use Argon2, bcrypt, or scrypt
  • Use HMAC for keyed authentication, not H(key || message)
  • Consider BLAKE2/BLAKE3 for performance-critical applications
  • Always use constant-time comparison for hash verification
Generate hashes instantly with ToolPop's Hash Generator—supporting all major algorithms with file upload and text input.

Tags
hash functionsMD5SHA-1SHA-256cryptographyhash generatordata integrity
Share this article

Try Our Free Tools

Put these tips into practice with our free online tools. No signup required.

Explore Tools