Skip to content
CryptoAcademy logo CryptoAcademy
Menu
Lesson Beginner · 10 min

The avalanche effect

Flip a single bit of the input and roughly half of the output bits change. No correlation, no leftovers — the avalanche effect.

In this lesson

  • Explain the avalanche effect in your own words
  • Predict that similar inputs give completely unrelated hashes
  • Measure bit differences with a short script

Prerequisites

Similar inputs, unrelated digests

A secure hash must diffuse: every input bit should influence every output bit. In SHA-256, flipping one input bit changes on average 128 of the 256 output bits — the avalanche effect.

This is why password1 and password2 hash to strings that share no visible similarity, and why an attacker cannot work backwards from "close enough".

One bit in, half the digest out
The avalanche effect: flipping one input bit changes about half of the output bits INPUT BITS OUTPUT BITS (256) "cat" "cbs" 1 bit flipped Avalanche effect Flip one input bit → on average half of the 256 output bits change. No pattern, no similarity. That is why "cat" and "cbs" hashes look nothing alike — and why hashes never leak structure. original bit different output bit flipped input bit unchanged / zero
The flipped input bit (red) changes about half of the output bits — there is no pattern to exploit.

Example · Two nearly identical passwords

Hash correcthorsebatterystaple and correcthorsebatterystapl3. The digests differ in ~128 bits on average. If hashes leaked structure, attackers could narrow the search space; the avalanche effect removes that shortcut.

avalanche.py python
import hashlib\n\ndef bits(a: str, b: str) -> int:\n    x = int(hashlib.sha256(a.encode()).hexdigest(), 16)\n    y = int(hashlib.sha256(b.encode()).hexdigest(), 16)\n    return bin(x ^ y).count("1")\n\nprint(bits("cat", "cbs"))   # typically 120-135 out of 256

Never judge a hash by eye

"These hashes look similar, so the files must be similar" is wrong. Similarity in the input tells you nothing about similarity in the digest — and vice versa.

Watch it avalanche

Hash two inputs that differ by one character and count how many hex digits change.

Try it yourself
Why does a good hash need this?

Diffusion removes partial information. Without it, an attacker could tweak the input slightly and predict part of the output, which breaks collision resistance.

Is ~50% exact?

It is an average over many inputs. Any single pair might be a bit above or below half.

Name the effect

Practice · server-graded
  • Changing one character in the input changes roughly half of the output bits. This is called the ______ effect.

    1 pt

True or false

Practice · server-graded
  • Similar inputs produce similar hashes.

    1 pt

Share this page

Send this link to a friend, or scan the QR code to open it on your phone.