What Is SHA? Cryptographic Hash Functions Explained

SHA-256, MD5, SHA-3 — hash functions are everywhere in security. Learn how they work, why MD5 is broken, and where hashing is used in the real world.

What Is a Hash Function?

A cryptographic hash function takes any input — a password, a file, a message — and produces a fixed-length string of characters called a hash, digest, or fingerprint. No matter how large the input, the output is always the same size.

Input:  "hello"
SHA-256: 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Input:  "hello!" (one extra character)
SHA-256: ce06092fb948d9af0d2a3c96f61d2b77b0a3d5429a698f5a24c40b33f427d02b

That tiny change produces a completely different output — this is called the avalanche effect, and it is central to why hash functions are useful in security.

Core Properties of Cryptographic Hash Functions

A secure hash function must satisfy four properties:

| Property | What it means | |---|---| | Deterministic | Same input always produces the same output | | Pre-image resistance | You cannot reverse the hash to find the original input | | Collision resistance | It is computationally infeasible to find two different inputs that produce the same hash | | Avalanche effect | A tiny change in input produces a completely different hash |

The SHA Family

SHA stands for Secure Hash Algorithm. The family was developed by NIST (National Institute of Standards and Technology) and NSA.

SHA-1 (Deprecated)

  • Output: 160 bits (40 hex characters)
  • Status: Broken — collision attacks demonstrated in 2017 (Google's SHAttered attack)
  • Do not use for new systems

SHA-256

  • Output: 256 bits (64 hex characters)
  • Part of the SHA-2 family alongside SHA-224, SHA-384, SHA-512
  • Widely used in TLS certificates-tls-how-HTTPS-keeps-your-data-safe), Bitcoin mining, file integrity checks, digital signatures-symmetric-vs-asymmetric)
  • Still considered secure as of 2026

SHA-3

  • Output: Variable (224 / 256 / 384 / 512 bits)
  • Uses a completely different internal structure (Keccak sponge construction)
  • Standardised in 2015 as a backup if SHA-2 were broken
  • Provides diversity — SHA-3 and SHA-2 have different vulnerabilities

BLAKE2 / BLAKE3

  • Faster than SHA-256, still cryptographically secure
  • Used in password managers, file storage systems, and modern protocols
  • BLAKE3 is one of the fastest secure hash functions available today

What About MD5?

MD5 (Message Digest 5) was once ubiquitous but is now considered cryptographically broken:

  • Collisions can be generated in seconds on modern hardware
  • Two different files can be crafted to have the same MD5 hash
  • MD5 should never be used for security-sensitive purposes

MD5 is still occasionally used for non-security checksums (e.g., verifying a downloaded file was not corrupted in transit) but even for that, SHA-256 is preferred.

Real-World Uses of Hashing

1. Password Storage

Websites should never store passwords in plaintext. Instead, they store a hash of the password. When you log in, the entered password is hashed and compared to the stored hash. Modern password hashing uses bcrypt-explained)), Argon2, or PBKDF2 — these are deliberately slow algorithms with a salt added to prevent rainbow table attacks.

> SHA-256 alone is NOT safe for password storage — it is too fast, allowing billions of guesses per second on a GPU. Use bcrypt-explained)) or Argon2 instead.

2. File Integrity Verification

Software publishers publish SHA-256 hashes of their installers. After downloading, you compute the hash of the file and compare it to the published value. A mismatch means the file was corrupted or tampered with.

3. Digital Signatures

A digital signature does not sign the entire document — it signs the hash of the document. This is efficient and equally secure. Any change to the document changes the hash, invalidating the signature.

4. TLS/HTTPS

During the [TLS handshake](/learning-center/what-is-SSL-tls-how-HTTPS-keeps-your-data-safe), hash functions verify the integrity of messages exchanged between client and server. certificate-explained) chains also use SHA-256 to bind public keys to identities.

5. Blockchain and Bitcoin

Bitcoin uses double SHA-256 (SHA-256 applied twice) in the proof-of-work mining algorithm and to generate wallet addresses from public keys.

6. File Integrity Monitoring

Security tools hash known-good system files. Comparing live hashes against these baselines detects file tampering — this is the principle behind file integrity monitoring (FIM) tools like Tripwire.

Hash Functions vs Encryption

A common misconception: hashing is not encryption.

| | Hashing | encryption | |---|---|---| | Reversible? | No | Yes (with the key) | | Key required? | No | Yes | | Use case | Integrity verification | Confidentiality | | Examples | SHA-256, MD5 | AES, RSA |

Keyed Hashing: HMAC

An HMAC (Hash-based Message Authentication Code) combines a secret key with a hash function to produce a code that verifies both the integrity and authenticity of a message. HMACs are used in API authentication (e.g., AWS Signature Version 4), JWT tokens, and cookie-how-the-world-wide-web-works) validation.

Summary

  • A hash function turns any input into a fixed-size fingerprint
  • SHA-256 is the current workhorse of security — used in TLS, digital signatures-symmetric-vs-asymmetric), and more
  • SHA-3 provides a structurally different alternative for defence in depth
  • MD5 and SHA-1 are broken — do not use for security
  • For passwords, use bcrypt-explained)) or Argon2, not raw SHA-256
  • Hashing provides integrity, not confidentiality — it is not encryption