A hash function turns any input, from one word to a whole block of transactions, into a short fixed-length output called a hash or digest. The same input always gives the same hash, but a tiny change gives a completely different one, and you can't work backward from the hash. Blockchains depend on this to link blocks, identify transactions, derive addresses and run proof-of-work mining.
What does a hash function actually do?
A hash function takes data of any size and produces an output of a fixed size. SHA-256, the function Bitcoin uses, always returns 256 bits, written as 64 hexadecimal characters. It does that whether you feed it the word "hello" or a 4-gigabyte file.
The output works like a fingerprint. It is far smaller than the data, yet it identifies that data. NIST's hash function standard describes their purpose as detecting whether a message has changed since its digest was made. If you know the hash of a file, you can hash your copy and compare. A match means the copy is the same.
Not every hash function is safe for this. The ones used in hash tables and checksums are built for speed. A cryptographic hash function is designed so that even a well-funded attacker can't find inputs that defeat it, and that is the kind blockchains use.
What makes a hash function secure?
A cryptographic hash function needs to be deterministic and fast to compute, and it must have three security properties. NIST's hash functions project page defines them this way:
| Property | What it means | What it protects in a blockchain |
|---|---|---|
| Preimage resistance | Given a hash, you can't find an input that produces it | You can't reverse an address or a commitment to learn what was hashed |
| Second preimage resistance | Given one input, you can't find a different input with the same hash | No one can swap in a different transaction that matches a recorded one |
| Collision resistance | You can't find any two different inputs with the same hash | No one can prepare two versions of a block or document that share an ID |
"Can't" here means computationally infeasible, not impossible. SHA-256 has only 2^256 possible outputs, so collisions must exist. The point is that nobody can find one. NIST rates SHA-256 at 128 bits of collision resistance and 256 bits of preimage resistance. That means a brute-force collision search would take around 2^128 attempts, far more than all the world's computers could manage.
Designers also aim for the avalanche effect: flipping a single bit of input should flip about half the output bits, with no visible pattern. That's what makes the output look random.
A worked example: the avalanche effect
These two messages differ by one character. In computer encoding, "0" and "1" differ by a single bit. We ran both through SHA-256:
"Pay Alice 10 BTC"
d6692c17dd8b0a548fff082417f1784f5c9918094912d484f4bc101584ce5561
"Pay Alice 11 BTC"
c6540c3293657f6f6079ed9240ccf29f155112942474ab1a869f9ba73a6d796e
One bit changed in the input, and 132 of the 256 output bits changed. That's about 52%, close to the 50% you'd expect from random output. Of the 64 hex characters, 59 differ.
Three lessons follow from this:
- Hashes don't leak similarity. Two nearly identical messages have unrelated hashes, so you can't learn anything about the input by studying the output.
- Tampering is obvious. Change one digit in a payment and its fingerprint changes beyond recognition.
- You can't steer the output. Since there's no pattern, the only way to get a hash with a particular feature is to keep trying inputs. Mining relies on exactly this.
SHA-256 and Keccak-256: the two hashes you'll meet most
Most of crypto runs on two hash functions, and they come from different families.
SHA-256 belongs to the SHA-2 family, specified in NIST's FIPS 180-4, last revised in August 2015. Bitcoin uses it everywhere, often twice in a row. Its developer reference shows that block header fields such as the previous block's hash and the Merkle root are SHA256(SHA256()) hashes.
Keccak-256 is what Ethereum uses. Keccak won NIST's competition for a new standard, and NIST published the result as SHA-3 in FIPS 202, also in August 2015. Ethereum had already adopted the competition version, and NIST's final standard changed the padding rule. So Ethereum's Keccak-256 and the official SHA3-256 give different answers for the same input. We checked with the empty input:
| Function | Hash of an empty input |
|---|---|
| SHA-256 | e3b0c442...7852b855 |
| Keccak-256 (Ethereum) | c5d24601...5d85a470 |
| SHA3-256 (NIST) | a7ffc6f8...80f8434a |
This trips up developers. A library function called "sha3" may compute either one, and choosing the wrong one produces wrong addresses and signatures. Solidity removed its old sha3 alias in version 0.5.0, and its keccak256 function names the algorithm plainly.
Ethereum uses Keccak-256 in places most users never see. An address is the last 20 bytes of the Keccak-256 hash of the public key. A contract function is identified by the first four bytes of the Keccak-256 hash of its signature, which is the "method ID" you see when you read a transaction on a block explorer.
How do hashes link blocks into a chain?
Each block stores the hash of the block before it, which is what makes a blockchain a chain. The Bitcoin whitepaper describes the idea as a timestamp server: "Each timestamp includes the previous timestamp in its hash, forming a chain, with each additional timestamp reinforcing the ones before it."
Here's how a change ripples through:
- The transaction IDs in a block are hashed in pairs, and the pairs are hashed again, until one hash remains. That's the Merkle root, and it sits in the block header. (A Merkle tree is a topic of its own.)
- The header, including the previous block's hash and the Merkle root, is hashed to give this block's hash.
- The next block stores that hash in its own header.
Edit one old transaction and its Merkle root changes. That changes the block's hash, which no longer matches what the next block recorded. That block's hash then changes too, and so on to the tip of the chain. Anyone running a node can spot the mismatch with a few hash calculations.
Hashes also act as names. Bitcoin's developer guide notes that a transaction is hashed to create its transaction identifier, or txid. Many address formats hash a public key too, which shortens it and keeps the key itself hidden until it's used.
How does proof of work use hashing?
Proof of work turns the avalanche effect into a lottery. The whitepaper puts it simply: miners scan for a value that, "when hashed, such as with SHA-256, the hash begins with a number of zero bits." Since outputs can't be predicted, the only method is trial and error, changing a number called the nonce each time.
We ran a small version of this puzzle. We hashed the text "block 1: Alice pays Bob 1 BTC | nonce " followed by 0, 1, 2 and so on, stopping at the first hash that began with a given number of zeros:
| Required leading hex zeros | Expected attempts on average | Nonce we found |
|---|---|---|
| 1 | 16 | 9 |
| 2 | 256 | 522 |
| 3 | 4,096 | 5,915 |
| 4 | 65,536 | 12,722 |
Each extra zero makes the puzzle 16 times harder on average, and luck can make any single search shorter or longer. The winning hash for four zeros was 0000efea...4c945602. Anyone can check it with one hash, while finding it took 12,723 tries.
That gap between finding and checking is why Bitcoin mining works. Real Bitcoin compares the header hash against a numeric target, and the network retunes the difficulty every 2,016 blocks to keep blocks about 10 minutes apart. To rewrite an old block, an attacker would have to redo its work and the work of every later block, then overtake the honest network. That's the security model behind proof of work, and why a 51% attack needs so much hardware.
Common misconceptions about hashing
"Hashing is a kind of encryption." It isn't. Encryption is meant to be reversed by someone holding the key. A hash has no key and no way back. That's why a hash can prove that data hasn't changed, but it can't keep data secret if the input is easy to guess. Anyone can hash "yes" and "no" and compare.
"A hash proves the data is true." A hash proves only that data matches a fingerprint. If someone hashes a false record, the hash faithfully fingerprints a false record. This is one reason proof of reserves has limits. More explainers like this are in our cryptography hub.
"Hash functions last forever." They don't. SHA-1 was once widely used. NIST deprecated it in 2011 and barred it from digital signatures after 2013. In February 2017, researchers from CWI Amsterdam and Google published SHAttered, the first real SHA-1 collision: two different PDF files with the same hash. It took about 6,500 CPU-years and 110 GPU-years of computation. No comparable attack on SHA-256 or Keccak-256 is publicly known, but this is why designers watch the research closely.
"Quantum computers will break hashing." The bigger quantum worry is signatures, not hashes. As we explain in could quantum computers break Bitcoin, the known quantum algorithm for search only speeds up brute-force guessing against a hash. It offers no shortcut like the one that threatens signatures.
Key takeaways
- A cryptographic hash function turns any data into a fixed-length fingerprint that is easy to compute and infeasible to reverse.
- Its security rests on preimage, second preimage and collision resistance, plus an avalanche effect that makes the output look random.
- Bitcoin uses SHA-256, often applied twice. Ethereum uses Keccak-256, which differs from the official SHA3-256 only in padding but gives different outputs.
- Each block stores the previous block's hash, so editing old data breaks every later link in a way any node can detect.
- Proof of work is a search for an input whose hash falls below a target, which is costly to find and cheap to check.
- Hashes prove that data hasn't changed. They don't encrypt it, and they don't prove it's true.
Sources
Get the weekly commit
New blockchain deep dives every week.

