Skip to the workspace
Pebellslearn by building
Hashes, Keys and Signatures  ›  Lesson

Hash Functions — Fingerprints for Data

Cryptography & Hashing 12 minA cryptographic hash function turns any input into a fixed-size fingerprint that is deterministic, changes completely with any edit, and cannot practically be reversed.

blockchain / Hash Functions — Fingerprints for Data

Explore each scene at your own pace.

01 · The rule

The rule

Hash Functions — Fingerprints for Data

In section 1, Ravi's edit to an old block was caught because the block's fingerprint changed. That fingerprint is a hash, and almost every part of a blockchain leans on it: block links, transaction IDs, mining and addresses. This lesson makes the idea precise.

The rule

Same input, same hash; change one bit, change everything; never run it backwards.

A cryptographic hash function takes input of any size and returns an output of fixed size. Bitcoin uses SHA-256, whose output is 256 bits, usually written as 64 hexadecimal characters. Ethereum uses a different function, Keccak-256, which is also 256 bits long.

SHA-256("Asha pays Ravi 5") = ef4f6f0fea431f4b4dd3b1e9f0c88c5dc028a807ede25da5ab3efb7e9e80245e
SHA-256("Asha pays Ravi 6") = 245847cc211a5555290467fb275551853ae46e26dd13b260c35c80acd5b899e6

One digit changed in the input, and the two outputs share no visible pattern. Five properties make hashes useful:

  1. Deterministic. The same input always gives the same hash, on any computer, at any time.
  2. Fixed size. A 16-character message and an 18,000-character file both produce 64 hex characters.
  3. Avalanche effect. A tiny change to the input scrambles the whole output.
  4. One-way. Given a hash, there is no practical way to find an input that produces it, other than guessing inputs one at a time.
  5. Collision resistant. Nobody can practically find two different inputs with the same hash.

Collisions must exist in principle, because there are endlessly many possible inputs and only 2²⁵⁶ possible outputs. But finding one for SHA-256 is far beyond any computer that exists.

A hash is not encryption. Encryption is built to be reversed by whoever holds the key. A hash has no key and is built never to be reversed.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.