What Is a Hash? MD5, SHA-1, SHA-256 Explained for Developers
What Is a Hash Function?
A cryptographic hash function takes any input (a file, a string of text, an entire database) and produces a fixed-length output called a hash, digest, or checksum. The key properties that make hash functions useful are:
- Deterministic — The same input always produces the same hash output.
- Fixed output length — Regardless of input size (1 byte or 1 terabyte), the output is always the same length. SHA-256 always produces a 64-character hex string.
- Avalanche effect — A tiny change in input produces a completely different hash. "Hello" and "hello" (different capitalization) produce entirely different SHA-256 hashes.
- One-way — Given a hash, it is computationally infeasible to reconstruct the original input. This is the crucial property for security applications.
- Collision resistant — It should be extremely difficult to find two different inputs that produce the same hash output.
MD5: Fast, But Broken for Security
MD5 (Message Digest 5, designed by Ron Rivest in 1991) produces a 128-bit (32-character hex) hash. For decades it was ubiquitous in web development for password hashing, file integrity verification, and digital signatures.
MD5 is now cryptographically broken and should never be used for any security purpose. Researchers demonstrated practical MD5 collision attacks in 2004, and today generating MD5 collisions takes milliseconds on consumer hardware. Security researchers have demonstrated creating two different files with identical MD5 hashes — completely undermining its integrity verification value.
MD5 remains acceptable for non-security uses: verifying file integrity over trusted channels (e.g., checking a downloaded file wasn't corrupted in transit, not checking it wasn't tampered with), or as a simple non-secure identifier.
SHA-1: Deprecated, Not Yet Dead
SHA-1 (Secure Hash Algorithm 1, 1993) produces a 160-bit (40-character hex) hash. It was the dominant algorithm in SSL certificates, Git commits, and code signing for nearly two decades.
SHA-1 was theoretically compromised in 2005, and in 2017, Google's research team published the first practical SHA-1 collision attack (SHAttered) — creating two different PDF files with identical SHA-1 hashes. All major browsers and certificate authorities deprecated SHA-1 in 2017.
SHA-1 is still used in older Git repositories (all commits are identified by SHA-1 hashes) and some legacy systems. Git is transitioning to SHA-256, and you should not use SHA-1 for any new security-sensitive application.
SHA-256: The Current Standard
SHA-256 (part of the SHA-2 family, designed by the NSA and published by NIST in 2001) produces a 256-bit (64-character hex) hash. It is the current industry standard for cryptographic hash applications.
SHA-256 is used in:
- TLS/SSL certificates (HTTPS)
- Bitcoin and cryptocurrency (every transaction and block)
- Digital code signing
- JWT token signing (HS256)
- File integrity verification
- Password hashing (as part of bcrypt or PBKDF2 constructions)
- Software package distribution (download checksums)
For new development, SHA-256 is the minimum acceptable choice for any security-related hashing. SHA-384 and SHA-512 provide larger output and marginally more security headroom for extremely sensitive applications.
SHA-3: The Backup Champion
SHA-3 (Keccak, 2015) was developed as a backup to the SHA-2 family — not because SHA-2 is broken, but to ensure algorithmic diversity if a weakness in SHA-2's design were discovered. SHA-3 uses a fundamentally different internal structure (sponge construction vs SHA-2's Merkle-Damgård), meaning a cryptanalytic attack that breaks SHA-2 would not automatically break SHA-3.
Hash Algorithms Comparison
| Algorithm | Output Length | Status | Use Today? |
|---|---|---|---|
| MD5 | 128 bits (32 hex) | Broken | ❌ Not for security |
| SHA-1 | 160 bits (40 hex) | Deprecated | ❌ Not for security |
| SHA-256 | 256 bits (64 hex) | Secure | ✅ Recommended |
| SHA-384 | 384 bits (96 hex) | Secure | ✅ For high-security |
| SHA-512 | 512 bits (128 hex) | Secure | ✅ For high-security |
| SHA-3-256 | 256 bits (64 hex) | Secure | ✅ Alternative to SHA-256 |
| bcrypt | 60 chars | Secure | ✅ Password hashing only |
| Argon2id | Variable | Secure | ✅ Best for passwords |
Critical Warning: Never Use General Hash Functions for Passwords
This is the most important point in this entire article. General-purpose hash functions (SHA-256, SHA-512, even bcrypt alone) are not appropriate for password storage without additional measures. Passwords should be hashed with bcrypt, scrypt, or Argon2id — algorithms specifically designed to be intentionally slow and memory-intensive to defeat GPU-based brute-force attacks.
A SHA-256 hash of a common password can be cracked in milliseconds by a GPU. An Argon2id hash of the same password takes hundreds of milliseconds to compute — making cracking 10,000× harder.
Generate Hashes for Free
You can generate MD5, SHA-1, SHA-256, and SHA-512 hashes for any text or file with Flixfer's free Hash Generator. Verify downloaded file integrity with Flixfer's File Checksum Generator. Both tools run entirely in your browser — your data is never transmitted.