HomeArticlesCryptography

Cryptographic Hash Functions: Avalanche Effect, Collisions and the Birthday Bound

Why one flipped input bit changes half the output, why collisions are found in 2^(n/2) tries rather than 2^n, and why MD5 and SHA-1 broke while SHA-256 hasn't.

mysimulator teamUpdated June 2026≈ 7 min read▶ Open the simulation

What a cryptographic hash promises

A cryptographic hash function takes an input of any length and produces a fixed-size digest — 256 bits for SHA-256 — and it must satisfy three properties to be considered secure: preimage resistance (given a hash, you can't find any input that produces it), second-preimage resistance (given one input, you can't find a different input with the same hash), and collision resistance (you can't find any two inputs with the same hash, which by the birthday bound is strictly harder than second-preimage resistance). None of these are proven mathematically impossible to break — they're empirical claims that survive as long as nobody publishes an attack faster than brute force.

live demo · one flipped input bit rippling through the output● LIVE

The avalanche effect

A good hash function exhibits the avalanche effect: flipping a single input bit should change roughly half of the output bits, in a way that looks statistically indistinguishable from flipping a fresh coin for each output bit. This is what SHA-256's internal design — 64 rounds of bitwise rotations, XORs, modular additions and nonlinear choice/majority functions on a 256-bit state — is built to guarantee. There is no visible relationship between the input and output at all; a hash of "hello" and a hash of "Hello" share no meaningful structure despite differing by one bit in the input.

SHA-256("hello") = 2cf24dba5fb0a30e26e83b2ac5b9e29e...
SHA-256("Hello") = 185f8db32271fe25f561a6fc938b2e26...
// one bit flipped in the input -> ~50% of output bits differ,
// with no discernible pattern connecting the two digests

This is why hashes are used for integrity checking and why they make terrible locality-preserving structures — you can't use a hash to find "similar" inputs the way you could with, say, a perceptual image hash, because avalanche behaviour deliberately destroys any correlation between input similarity and output similarity.

The birthday bound: collisions are closer than intuition says

For a hash with n-bit output, brute-forcing a specific preimage takes about 2ⁿ tries on average. But finding any collision between two unspecified inputs is far cheaper, thanks to the birthday paradox: among a room of just 23 people, there's already better than 50% odds two share a birthday, because you're comparing every pair, not searching for one specific date. The same math means a collision in an n-bit hash is expected after roughly 2ⁿ/² random tries, not 2ⁿ. For a 256-bit hash that's still an astronomical 2¹²⁸ operations — safe by any practical measure — but for a 128-bit hash it's only 2⁶⁴, within reach of dedicated hardware, which is one reason 128-bit digests are considered too short for new cryptographic uses.

expected tries for a collision  ≈ sqrt(2^n) = 2^(n/2)
n = 256 (SHA-256)  -> ~2^128 tries  (infeasible)
n = 128 (MD5-ish)  -> ~2^64  tries  (feasible with enough hardware)
n =  64             -> ~2^32  tries  (feasible on a laptop in hours)

When hash functions actually break

MD5 (128-bit) has had practical collisions since 2004 and is now considered cryptographically broken — collision attacks run in seconds on ordinary hardware. SHA-1 (160-bit) fell in 2017 when Google and CWI Amsterdam published the SHAttered attack, producing two distinct PDF files with identical SHA-1 hashes after roughly 2⁶³ computations — dramatically less than the 2⁸⁰ brute-force birthday bound would suggest, because the attack exploited structural weaknesses in SHA-1's compression function rather than relying on pure brute force. SHA-2 (SHA-256/SHA-512) and SHA-3 (a structurally different sponge-based design, standardised in 2015 specifically to hedge against any future structural weakness discovered in the SHA-2 family) remain unbroken as of today.

Hashing passwords is a different problem

SHA-256 is deliberately fast — that's exactly wrong for password storage, because fast hashing is what makes brute-force and rainfall-table attacks against stolen password databases cheap. Password hashing uses purpose-built slow functions instead — bcrypt, scrypt, and Argon2 (the current recommended default) — which add a tunable work factor and, for scrypt and Argon2, deliberately large memory requirements to resist GPU and ASIC parallelism, so that checking one password takes milliseconds for a legitimate login but checking a billion candidate passwords takes correspondingly longer for an attacker.

Frequently asked questions

What is the avalanche effect in a hash function?

It's the property that flipping just one bit of the input changes roughly half of the output bits, in a way indistinguishable from random. It's what makes hash outputs look completely unrelated to similar inputs, which is exactly what you want for integrity checking — but it also means hashes can't be used to find 'similar' inputs the way other fingerprinting techniques can.

Why are hash collisions easier to find than preimages?

Finding a specific preimage requires roughly 2^n tries for an n-bit hash, but finding any two colliding inputs only requires about 2^(n/2) tries — the same birthday-paradox math that makes two people in a room of 23 likely to share a birthday. That's why 128-bit hashes are considered too short for collision resistance today even though 2^128 preimage attempts would still be infeasible.

Is SHA-256 still safe to use?

Yes — SHA-256 and the rest of the SHA-2 family have no known practical collision or preimage attacks and remain the standard choice for integrity checking, digital signatures and blockchain applications. MD5 and SHA-1, by contrast, both have practical collision attacks and should not be used for anything security-critical.

Try it live

Everything above runs in your browser — open Hash Functions and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open Hash Functions simulation

What did you find?

Add reproduction steps (optional)