What is a hash in blockchain?
A hash is a fixed-length digital fingerprint of a piece of data. Blockchains use hashes to link blocks together and to make tampering obvious.
A hash is a short, fixed-length string of letters and numbers produced by running data through a mathematical formula called a hash function. It works as a digital fingerprint. The same data always gives the same hash, and any change to the data gives a different one.
How does a hash function work?
A hash function accepts any input, whether a single word, a photo or a block of thousands of transactions, and returns an output of a set size. Bitcoin uses a function called SHA-256, published by the US government in 2001. Its output is always 256 bits long, usually written as 64 characters.
Four properties make it useful:
- Consistent. The same input always produces the same hash.
- One-way. There is no formula for working backward from a hash to the input. The only method is to guess inputs until one matches.
- Sensitive. Changing one character of the input produces a completely different hash, with no visible relation to the old one.
- Unique in practice. Finding two different inputs with the same hash is so unlikely that it is treated as impossible.
How do hashes link blocks together?
The header of each block contains the hash of the block before it. If someone edited an old transaction, that block's hash would change and would no longer match the value stored in the next block. The forger would have to recalculate every later block as well, and the nodes holding honest copies would reject the result.
Hashes also organize the transactions inside a block. They are hashed in pairs, and the results hashed again, until a single hash stands for all of them.
How are hashes used in mining?
In proof-of-work mining, a new block is valid only if its hash falls below a target number, which in practice means it starts with a long run of zeros. No shortcut exists. Miners change a small number in the block, hash it, and repeat, making enormous numbers of attempts every second.
Finding a winning hash is hard, but checking one takes a single calculation. That imbalance is what makes the work a proof. The combined guessing speed of all miners is called the hash rate.
Where else do hashes appear?
They are everywhere in crypto. A wallet address is derived by hashing a public key. A transaction ID is a hash of the transaction. Digital signatures, covered in the guide to how cryptography secures crypto, sign the hash of a message.
Hashing is not encryption. Encrypted data can be decoded with the right key. A hash cannot be decoded at all.
Hash functions can also age. An older standard, SHA-1, was retired from secure use after researchers produced two different files with the same hash in 2017. No practical attack of that kind on SHA-256 has been made public.
This guide explains how things work. It is not financial, legal or tax advice. Last updated .