DevKits
Concept

How SHA-256 Works — The Cryptographic Hash That Secures the Web

SHA-256 produces a fixed 256-bit fingerprint for any input, from a single word to a 10 GB file. It's the hash behind TLS certificates, Bitcoin mining, and Git object-IDs. Learn how it works at a conceptual level and why collision resistance matters.

Last updated:

Core Concepts

What a cryptographic hash function does
A hash function takes an arbitrary-length input and produces a fixed-size output (digest). SHA-256 always produces 256 bits — 64 hex characters. Three key properties: 1) preimage resistance (you can't reverse the hash to find the original input), 2) collision resistance (you can't find two different inputs that hash to the same value), 3) avalanche effect (changing one bit in the input changes ~50% of the output bits).
Where SHA-256 is used every day
TLS/HTTPS certificate chains use SHA-256 to verify that a certificate wasn't tampered with. Bitcoin's proof-of-work mines for an input whose SHA-256 output starts with a specific number of zero bits. Git uses SHA-256 (opt-in mode) instead of SHA-1 for content-addressed object-IDs. Password storage systems use SHA-256 as part of PBKDF2 (key derivation), though bcrypt/Argon2 are better for passwords specifically.
SHA-1 vs SHA-256 vs SHA-512
SHA-1 (160 bits) is broken for collision resistance — the SHAttered attack demonstrated a practical collision in 2017. SHA-256 (256 bits) has no known collision attacks in over 20 years of cryptanalysis. SHA-512 (512 bits) is faster on 64-bit CPUs but unnecessary for most applications — 256 bits already exceeds the practical threat model (2^128 operations for a birthday bound collision is infeasible for any known hardware). Use SHA-256 for all new systems unless a specific standard requires SHA-512.
Hash is NOT encryption
Hashing is one-way — you cannot decrypt a hash. This is the second most common confusion after 'encoding = encryption.' If you need to recover the original data later, use encryption (AES-GCM), not hashing. Hashing is for integrity verification and fingerprinting.

Frequently Asked Questions

Can two different files have the same SHA-256 hash?

Theoretically yes (pigeonhole principle: there are infinite possible inputs but 'only' 2^256 possible SHA-256 outputs). Practically: no. The probability is astronomically small — 2^256 is roughly the number of atoms in the observable universe. No collision has ever been found for SHA-256 in the 25 years since its publication.

Is SHA-256 the same as SHA-2?

SHA-256 is part of the SHA-2 family, which includes SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256. They all use the same cryptographic construction (Merkle-Damgård) but differ in output size and internal state size. SHA-256 is the most widely deployed member.

Try these related tools