Core answer: A hash function maps any input to a fixed-size fingerprint: MD5 → 128 bits (32 hex chars), SHA-1 → 160 bits (40 hex), SHA-256 → 256 bits (64 hex). Same input = same output always; change one bit and ~half the output bits flip (avalanche). MD5 and SHA-1 are BROKEN for security (collisions found) — fine for checksums, forbidden for passwords/signatures. Passwords need slow salted KDFs: bcrypt, scrypt, Argon2.

The algorithm lineup

AlgorithmOutputStatusUse for
MD5128 bitbroken (2004 collisions)file checksums only
SHA-1160 bitbroken (2017 SHAttered)legacy, git internals
SHA-256256 bitsecuresignatures, blockchain, checksums
SHA-512512 bitsecurehigh-margin apps
bcrypt/scrypt/Argon2slow+saltedpassword-gradepassword storage ONLY
CRC3232 bitnot cryptographicerror detection

Hash ≠ encryption ≠ encoding

  • Hash: one-way; you cannot "decrypt" a hash; verification = re-hash and compare.
  • Encryption: two-way with a key (AES).
  • Encoding: two-way without a key (Base64).

Calling base64 "encryption" or expecting to "decrypt MD5" are the two classic confusions.

Worked examples

Example 1 — File integrity. Download page shows SHA-256 abc123...; after download run sha256sum file.iso and compare — one flipped bit anywhere changes the whole hash. Mismatch = corrupted or tampered file.

Example 2 — Password storage done right. Never store SHA-256(password) — attackers brute-force billions/sec and rainbow-table common passwords. Store bcrypt(password, cost=12, random salt): ~250 ms per attempt, salts defeat precomputed tables.

Example 3 — Deduplication. A photo cloud hashes each upload; identical files hash identically → store one copy. Millions of users' identical memes = one object.

Example 4 — Cache busting. app.a3f9c2.js: content hash in the filename means immutable caching (1 year) with instant invalidation on change — the standard frontend deploy pattern.

Common mistakes and myths

  1. MD5 for security — collision attacks are practical (two different PDFs with the same MD5 since 2008); use SHA-256 for anything adversarial.
  2. Fast hash for passwords — SHA-256(password) falls to GPU brute force at billions/s; KDFs exist precisely to be slow and memory-hard.
  3. "Salted MD5 is fine now" — no; migrate legacy hashes on next login: verify old, rehash with Argon2/bcrypt, store new.
  4. Hash = signature — HMAC (keyed hash) proves authenticity; a plain hash proves only integrity against accidents, not attackers who can recompute it.
  5. Believing longer is always better — SHA-512 on 64-bit CPUs is often FASTER than SHA-256 and truncating it is standard (SHA-512/256); pick per platform.