Free preview8 min read

What a Hash Function Does

A hash function takes any input (a word, a file, a whole block of transactions) and produces a short output of fixed length, called a hash or digest. SHA-256, which Bitcoin uses, always produces 256 bits, usually written as 64 hexadecimal characters, whether the input is one letter or a feature film.

The properties that matter

  • Deterministic: the same input always gives the same hash, on any computer.
  • Quick to compute: hashing a large file takes a fraction of a second.
  • One-way: from a hash alone there is no practical way to find an input that produces it, other than guessing.
  • Avalanche effect: change one character of the input and about half of the output bits change, so similar inputs give unrelated hashes.

A further property, collision resistance, means nobody can find two different inputs with the same hash. Collisions must exist, because there are more possible inputs than outputs, but for a well-designed function finding one would take more computing power than exists.

Where you meet hashes in crypto

  • Each block records the hash of the block before it, which makes old history tamper-evident.
  • A Merkle tree hashes every transaction in a block down to a single root hash, so a transaction can be proven to be in a block without downloading the whole block.
  • Proof of Work miners search for a block hash below a target number, which can only be done by trying input after input.
  • An Ethereum address is cut from the Keccak-256 hash of a public key.

Where hashing stops protecting you

A hash proves that data has not changed since it was hashed. It says nothing about whether the data was right in the first place. And one-way only holds when the input is hard to guess. Hash a four-digit PIN and anyone can reverse it by hashing all 10,000 possible PINs and comparing. Passwords, and seed phrases people make up themselves, fail for the same reason: the protection comes from the number of possible inputs, not from the hash.

A hash is a seal on a document, not a verdict on what the document says.
What a Hash Function Does · Crypto Academy