Lesson 2 of 24 in Understanding Blockchain & Crypto · 12m
Hashing: digital fingerprints
If you take one technical idea away from this course, make it this one. Hash functions are the glue of every blockchain. They link blocks together, summarise thousands of transactions in a few dozen characters, help produce addresses, and are at the heart of proof of work. The good news is that you do not need any maths to understand what they do.
What a hash function does
A hash function takes any input (a word, a contract, a whole film) and produces a short, fixed-length output called a hash or digest. Think of it as a fingerprint for data. Bitcoin and many other systems use SHA-256, a function standardised by the US National Institute of Standards and Technology (NIST). Its output is always 256 bits, usually written as 64 hexadecimal characters.
For example, the SHA-256 hash of the word hello (all lowercase, nothing else) is:
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Change just the first letter to a capital, Hello, and you get:
185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969
There is no visible relationship between the two, even though the inputs differ by a single character. That is exactly what we want.
The five properties that matter
A cryptographic hash function is an ordinary hash function with extra security guarantees. These are the properties that make it useful for blockchains:
-
Deterministic. The same input always produces the same output, on any computer, forever. That is what lets thousands of strangers check the same data and agree.
-
Fixed size. Whether you hash one letter or a gigabyte, the output has the same length. A short fingerprint can stand in for a large amount of data.
-
One-way (preimage resistant). Given a hash, there is no practical way to work out the input, except by guessing inputs and hashing each one. For a well-designed function, guessing is hopeless for any input with real randomness in it.
-
Avalanche effect. A tiny change in the input changes the output completely and unpredictably. You cannot "nudge" an input to get a hash that is close to a target.
-
Collision resistant. It is practically impossible to find two different inputs with the same hash. Collisions must exist in theory (there are infinitely many inputs and only so many outputs) but nobody can find one for SHA-256 with any known method.
Try it: a toy hash function
The playground below uses a deliberately simple toy hash function. It is not secure (its output is only 32 bits, so collisions are easy to find with a computer), but it behaves enough like a real one to show determinism, fixed size and the avalanche effect. Run it, then change the inputs and run it again.
Where blockchains use hashes
Once you know what to look for, hashes are everywhere:
-
Fingerprinting data. A transaction is identified by the hash of its contents (its transaction ID). If anyone changes even one digit of the amount, the ID changes too.
-
Linking blocks. Each block stores the hash of the previous block. Change an old block and its hash changes, which breaks the link from the next block. Lesson 3 builds this.
-
Summarising many transactions. A Merkle tree hashes transactions in pairs, then hashes those results in pairs, until one hash (the Merkle root) represents the whole set.
-
Proof of work. Miners repeatedly hash a block header with different values until the result is below a target. Because hashes are unpredictable, the only way to succeed is lots of attempts (section 2).
-
Addresses. Many blockchains derive an address by hashing a public key, giving a shorter identifier to send funds to (section 3).
A useful everyday comparison: when you download software, some sites publish a SHA-256 checksum. If the file you downloaded has the same hash, you can be confident it was not corrupted or swapped along the way. Blockchains apply the same idea to an entire history of transactions.
Key takeaways
- A hash function turns any input into a short, fixed-length fingerprint.
- Cryptographic hashes are deterministic, fixed size, one-way, show the avalanche effect and resist collisions.
- SHA-256 is a widely used standard hash; Bitcoin relies on it.
- Blockchains use hashes to identify transactions, link blocks, summarise transactions (Merkle roots), run proof of work and derive addresses.
- Hashing is one-way and is not the same as encryption.
Sources
- NIST FIPS 180-4, Secure Hash Standard (SHS)
- NIST IR 8202, Blockchain Technology Overview
This lesson also has interactive exercises. Open the course to try them and track your progress.