What is a hash function?

A hash function turns any input into a short fingerprint of fixed size. The same input always gives the same fingerprint, and nobody can work back from it or find two inputs that share one.

Also called cryptographic hash, SHA-256 or BLAKE2.

Explain it like I’m five

A magic fingerprint machine takes anything you feed it, a word, a photo or a whole library, and prints a card with exactly 64 characters. Feed it the same thing again and the same card comes out. Change one comma in the library and the new card looks nothing like the old one. Nobody can look at a card and say what was fed in, and finding two different things that print the same card is out of reach.

What problem it solves

Storing, sending and comparing big data is expensive, and trusting a copy of it is risky. A hash replaces the data with a fixed-size fingerprint that is cheap to store, send and compare. If the fingerprints match, the data is the same. That one idea lets people detect a changed file, link blocks into a chain, sign a short digest instead of a long message and commit to a secret without showing it.

How it works, step by step

  • SHA-256 pads the message and cuts it into blocks of 512 bits.
  • It starts from a fixed internal state of eight 32-bit words, taken from the square roots of the first eight prime numbers, which anyone can recompute.
  • Each block is stretched into 64 words and mixed into the state over 64 rounds of rotations, shifts, bitwise choices and additions, using 64 constants taken from the cube roots of the first 64 primes.
  • The result of each block is added to the state, and the state after the last block is the 256-bit digest.
  • The design aims to make three things infeasible: finding an input for a given digest (one-way), finding a second input with the same digest as a given one (second-preimage resistance), and finding any two inputs with the same digest (collision resistance).
  • Any change to the input flips about half of the output bits, so similar inputs give unrelated digests (the avalanche effect).

A worked example

SHA-256 of the three letters abc is ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad. Changing the last letter to d gives a52d159f 262b2c6d db724a61 840befc3 6eb30c88 877a4030 b65cbe86 298449c9, which differs from the first in 122 of the 256 bits, about half. There are 2 to the power of 256 possible digests, a number with 78 digits, and finding a collision by chance takes about 2 to the power of 128 tries, a number with 39 digits.

A short secret gives a hash nothing to hide behind. A four-digit PIN has only 10,000 possibilities, so anyone can hash all of them and see which one matches.

What it guarantees

  • FIPS 180-4, the standard that defines SHA-256, says that it is computationally infeasible to find a message for a given digest or two different messages with the same digest, and that any change to a message changes the digest with very high probability.
  • SHA-256 gives about 256 bits of strength against finding an input for a digest and about 128 bits against finding a collision, because of the birthday effect.
  • The same input always gives the same digest, and the digest has a fixed size whatever the size of the input.
  • A hash has no key, so anyone can compute it, and a hash alone proves nothing about who made the data.

Common misunderstandings

  • A hash is no kind of encryption. It has no key and no way back, yet a guessable input can still be found by trying every candidate.
  • Two inputs can share a digest, since there are more possible inputs than digests. The claim is that finding such a pair is out of reach. SHA-1 shows the claim can fail: researchers announced a first collision in 2017, and NIST says SHA-1 should be phased out by the end of 2030.
  • Quantum computers threaten systems built on factoring and discrete logarithms, such as RSA and elliptic-curve signatures, as NIST’s FIPS 205 notes. Against a hash, the best generic quantum attack, Grover’s algorithm, needs only quadratically fewer guesses, which a 256-bit output absorbs.

Where it is used

Bitcoin uses SHA-256 for its proof-of-work and hashes each block’s transactions into a Merkle tree. The ethereum.org documentation shows Ethereum addressing its data with keccak256 and building its state root from it. NIST’s FIPS 205 builds digital signatures from hash functions alone.

History

NIST published SHA-1 in 1995, and FIPS 180-4 specifies it together with the SHA-2 family that includes SHA-256. A first SHA-1 collision was announced in February 2017, and in December 2022 NIST announced that SHA-1 should give way to SHA-2 and SHA-3 by 31 December 2030.

In Redacted

In Redacted, notes, nullifiers, the note tree and every proof transcript use SHA-256, and the formats keep room for a second hash such as BLAKE2s. The proofs and the signatures are built from hashes too.

Bunker mode →

Related terms

Sources: FIPS 180-4, Secure Hash Standard (SHS), NIST · FIPS 205, Stateless Hash-Based Digital Signature Standard, NIST · NIST Retires SHA-1 Cryptographic Algorithm, NIST, 2022 · Announcing the first SHA1 collision, Google Online Security Blog, 2017 · Bitcoin: A Peer-to-Peer Electronic Cash System, Satoshi Nakamoto, 2008

Updated November 1, 2026. All terms