What is blockchain, and how does it ensure immutability?
What is blockchain?
A blockchain is a way of keeping a list of records that many people can share and check, without trusting one person or company to keep it. Records, such as payments, are grouped into blocks. Each new block is added to the end of the chain, and once it is in, it is designed never to change. That is what immutability means: the history can be added to, but not edited.
The idea became famous with Bitcoin, described in a 2008 paper by the pseudonymous Satoshi Nakamoto. Bitcoin's blockchain is a public ledger of every Bitcoin payment ever made, copied on thousands of computers, called nodes, around the world.
What is in a block?
- The data: for a cryptocurrency, a list of transactions.
- The previous block's hash: the link that chains the blocks together.
- A timestamp and other housekeeping details.
- A nonce: a number miners change to find a valid hash (see proof of work below).
Hashing all of these together gives the block's own hash, which then goes into the next block. The very first block, the genesis block, has no block before it.
How does blockchain ensure immutability?
Three layers of protection work together. The first works on any blockchain; the other two make public blockchains so hard to rewrite.
1. Hashes chain the blocks together
A hash function turns any input into a fixed length fingerprint. Bitcoin uses SHA-256, defined by the US standards body NIST in FIPS 180-4, which always outputs 256 bits, written as 64 hexadecimal digits. Three properties matter:
- The same input always gives the same hash, so anyone can check it.
- A tiny change gives a completely different hash (the avalanche effect).
- It only works one way: you can't work backwards from a hash to the data, or find different data with the same hash in any practical time.
Here are the real SHA-256 hashes of two messages that differ by one character:
"Alice pays Bob 5" -> 66ed59ebf7d156f0f5fca203039b6263ebbc7da0f2479caaa04544864d7b1719
"Alice pays Bob 6" -> 081557435b69a7539ffd0aa6c411e56edf5fccf3cfb8193618623f4da59597a0Now suppose someone edits a payment in block 100. Block 100's hash changes. But block 101 stored the old hash of block 100, so the link no longer matches, and anyone checking the chain sees the break at once. To hide the edit, the attacker would have to recalculate block 101's hash, which breaks block 102, and so on to the end of the chain.
Try it: this question shows a short chain with one block edited and asks you to find it from the hashes.
Four blocks, one of them edited: find it from a hash that lost its zeros or a previous hash that no longer matches.
Press Mark to have your answer marked in the Cryptocurrencies course.
2. Proof of work makes each block expensive
If recalculating hashes were easy, an attacker could just redo them all. So Bitcoin makes every block costly to create. A block only counts if its hash is below a target, which in practice means it starts with a long run of zeros. Nobody can predict which nonce gives such a hash, so miners try nonce after nonce, hashing each time, until one works. This is proof of work.
Each hex digit is 0 with a chance of 1 in 16, so needing 4 leading zeros takes 164 = 65,536 tries on average, and 5 zeros takes 165 = 1,048,576. Bitcoin adjusts the target so that the whole network finds a block about every 10 minutes on average, according to the Bitcoin developer guide. Try one: this question asks how many tries a given difficulty takes.
Type the average number of tries for a number of leading zeros, or how many times harder one target is than another.
Press Mark to have your answer marked in the Cryptocurrencies course.
As the Bitcoin paper puts it, to modify a past block an attacker would have to redo the proof of work of that block and every block after it, and then catch up with and overtake the work of the honest nodes, who keep adding new blocks all the time.
3. Thousands of copies and the most work chain rule
There is no single master copy to hack. Every full node keeps its own copy and checks every new block itself: are the hashes right, is the proof of work valid, are the payments allowed? Invalid blocks are simply rejected. When two versions of the chain compete, nodes follow the one with the most proof of work behind it (often called the longest chain). So a rewritten history is only accepted if it has more work than the honest chain.
Why older blocks are safer
Every block added on top of yours is another block an attacker must redo. The Bitcoin paper works out the chance that an attacker with 10% of the network's computing power ever catches up from z blocks behind. We recalculated these from the paper's own formula:
| Blocks on top (z) | Chance a 10% attacker ever catches up |
|---|---|
| 0 | 1 (certain) |
| 1 | 0.2045873 |
| 2 | 0.0509779 |
| 3 | 0.0131722 |
| 4 | 0.0034552 |
| 5 | 0.0009137 |
| 6 | 0.0002428 |
The chance falls by roughly 4 times with each extra block. After 5 blocks it is under 1 in 1,000. That is why people wait for several confirmations before treating a large payment as final.
Is a blockchain truly immutable?
Not absolutely. Immutability is a matter of cost and odds, not a law of nature:
- A 51% attack. Someone controlling more than half of the computing power could, in principle, out-mine everyone else and rewrite recent blocks. On a large network this would be extremely expensive; small blockchains with few miners are far more at risk.
- Rules can change by agreement. If most users agree to run different software, the chain can split (a fork).
- Bad data stays bad. A blockchain stops records being changed, not wrong records being added. A mistaken or fraudulent payment is just as permanent as a real one.
- Private blockchains run by one company or a small group rely mainly on the hash links and on trusting the members, so they are only as tamper proof as those members.
Proof of stake
Proof of work uses a lot of electricity. Many blockchains now use proof of stake instead: validators lock up coins as a deposit and are picked to add blocks, and they lose some of the deposit if they cheat. Ethereum switched from proof of work to proof of stake on 15 September 2022, in an upgrade called The Merge, which ethereum.org says cut its energy use by about 99.95%. Here rewriting history is made costly by putting money at risk instead of computing work.
Common misconceptions
- "Blockchain is encryption." Public blockchain data is usually readable by anyone. It is protected from changes by hashing, not hidden by encryption.
- "Blockchain and Bitcoin are the same." Bitcoin is one use of a blockchain.
- "Nothing can ever be changed." Changing it is designed to be impractically expensive, not impossible.
- "A hash can be reversed to get the data." Hash functions only work one way.
- "Miners solve hard maths problems." They guess and check, very fast. The difficulty comes from how many guesses it takes.
To see all of this working with real SHA-256 hashes, including editing a block and watching the chain break, try the Cryptocurrencies course. Hashes are written in hexadecimal; our Number Base Converter shows how each hex digit maps to 4 bits.
Common questions
How does blockchain ensure immutability?
What is a hash in blockchain?
Can a blockchain be hacked?
What is the difference between proof of work and proof of stake?
Is blockchain data private?
What is a blockchain used for besides cryptocurrency?
Revision cards
Read the front, say your answer, then flip to check.
Where to go next
- Solve it
Number Base Converter
Convert between binary, hex and decimal and add in binary
Open the tool - Learn it
Cryptocurrencies
Blockchain, Bitcoin and the tech reshaping money, from hashing to smart contracts
Start the course