In this lesson you will learn to:
- Describe what a hash function does.
- Name its three key properties.
- Explain why a hash works like a fingerprint.
A machine that makes fingerprints
A hash function takes any input — a word, a book, a video — and produces a short, fixed-length output called a hash or digest. A widely used hash function, SHA-256, always produces 256 bits, usually written as 64 hexadecimal characters, whether the input is one letter or an entire library.
Think of it as a fingerprint for data. The fingerprint is much smaller than the thing it identifies, but it identifies it very reliably.
Three properties that matter
- Deterministic. The same input always produces the same hash. Anyone can recompute it and check.
- Avalanche effect. Change a single character of the input and the hash changes completely and unpredictably. There is no "slightly different" hash.
- One-way and collision-resistant. Given a hash, it is practically impossible to work out the input, and practically impossible to find two different inputs with the same hash.
"Practically impossible" has a precise meaning here: with all the computers on Earth working for longer than the age of the universe, you would still not expect to succeed. Older hash functions such as MD5 and SHA-1 lost this property as researchers found ways to create collisions, which is why systems moved to stronger functions.
A small example
Hash the sentence "Open Learning Path" and you get one 64-character string. Hash "open Learning Path" — only the first letter changed — and you get a completely different one. Nothing in the second string hints that the inputs were almost identical.
How blockchains use hashes
- Linking blocks. Every block stores the hash of the previous block. Change anything in an old block and its hash changes, breaking the link. Lesson 3.1 shows this in detail.
- Summarising transactions. Thousands of transactions can be summarised by a single hash using a structure called a Merkle tree.
- Proof of work. Some blockchains require participants to find a hash that meets a target, which takes enormous numbers of attempts.
- Addresses. Addresses are often derived from public keys by hashing.
Beyond blockchains
You use hash functions every day without noticing. Websites store hashes of passwords instead of the passwords themselves. Software downloads publish hashes so you can check the file was not altered. Version-control systems used by programmers identify every change by its hash. Blockchains borrowed a mature, well-studied tool.
Key takeaways
- A hash function turns any input into a short, fixed-length fingerprint.
- The same input always gives the same hash; any change gives a completely different one.
- It is practically impossible to reverse a hash or find two inputs with the same hash.
- Blockchains use hashes to link blocks, summarise transactions and secure consensus.
Check yourself
Does a longer input produce a longer SHA-256 hash?
No. SHA-256 always produces 256 bits, whatever the size of the input.
What is the avalanche effect?
A tiny change in the input produces a completely different, unpredictable hash.
Why did systems move away from SHA-1?
Researchers found practical ways to create collisions, so it was no longer collision-resistant.
Sources
This lesson is for general education about how the technology works. It is not a recommendation to acquire, sell or hold any crypto-asset and is not financial advice.