What is a hash?
A hash is like a fingerprint for data. A hash function takes any input, like a sentence or a whole file, and turns it into a short scrambled code. Real blockchains use a hash function called SHA-256, which stands for Secure Hash Algorithm 256. Every hash it makes is 256 bits long.
Three rules make hashes so useful:
- Same input, same output. Hashing "hello" today, tomorrow, or on any computer always gives the exact same code.
- Tiny change, totally different output. Change one letter, even just "hello" to "Hello", and the whole hash changes beyond recognition.
- One-way only. You can turn data into a hash, but you cannot turn a hash back into the data. It is a fingerprint, not a container.
Why "fingerprint"? Your fingerprint identifies you, but nobody could rebuild you from just a fingerprint. A hash identifies data the same way: perfect for checking that data has not changed.
Hash playground
Type anything below and watch its hash appear instantly. Then change just one letter and compare the new hash with the previous one. Notice how the whole fingerprint changes, not just one part.
This uses a small teaching hash (8 hex characters) as a simplified stand-in for SHA-256, which is 64 hex characters long.
Try changing hello to Hello. One capital letter, and every part of the hash scrambles.
Test rule one: delete your text, then type the exact same thing again. You get the exact same hash back. Same input, same output, every time.
Inside a block
Now for the "block" part of blockchain. A block is one page of the record book. Each block stores three key things:
Data
The transaction being recorded, like "Maria pays Sam 5 coins", plus a timestamp of when it happened.
Previous hash
The fingerprint of the block that came before it. This is the "chain" that links every block to its neighbor.
Its own hash
A fingerprint computed from everything inside the block, including the previous hash and the data.
Here is the trick that makes blockchain tamper-proof. Each block's hash is computed from its data and the previous block's hash. So the blocks are chained together by their fingerprints:
- If you change the data in a block, that block's hash changes.
- The next block still stores the old hash as its "previous hash", so the link no longer matches.
- That mismatch breaks the chain, and every block after it fails verification.
Change one old record and the whole chain lights up with evidence. Do not just take our word for it. Try it yourself below.
Try to tamper with a chain
Here is a tiny blockchain with three transactions. Pretend you are Sam, and you want to cheat by editing Block 2 to say Maria paid you 50 coins instead of 5. Go ahead, edit the data and watch what happens to the chain.
Edit the data in any block. Hashes recompute live using the same teaching hash from the playground above.
Why cheaters lose: you just re-mined 3 blocks with one click. On a real network, your edited copy would disagree with thousands of other copies of the ledger, and the network sides with the majority. To actually cheat, you would have to re-mine the chain on most of those computers at the same time. That is practically impossible, and that is the whole point.
Build a tiny blockchain in code
Real blockchain code has the same three jobs you just saw: hash data, link blocks, and verify the chain. The original version of this tutorial builds it in Java with SHA-256. Here is a simplified Python version that uses our small teaching hash instead, so the fingerprints match the demos on this page. Press Run:
# A teaching hash: a simple stand-in for SHA-256 def tiny_hash(text): value = 2166136261 for ch in text: value = (value ^ ord(ch)) * 16777619 % 2**32 return format(value, "08x") class Block: def __init__(self, data, previous_hash): self.data = data self.previous_hash = previous_hash # The block's fingerprint covers the previous # hash AND the data, chaining the blocks together self.hash = tiny_hash(previous_hash + data) # Build the chain, block by block chain = [] chain.append(Block("Maria pays Sam 5 coins", "0")) chain.append(Block("Sam pays Ana 2 coins", chain[0].hash)) chain.append(Block("Ana pays Leo 1 coin", chain[1].hash)) def is_chain_valid(): # Every block must point at its neighbor's real hash for i in range(1, len(chain)): if chain[i].previous_hash != chain[i - 1].hash: return False return True for i, block in enumerate(chain): print("Block", i + 1, "hash:", block.hash) print("Is the chain valid?", is_chain_valid())
Block 1 hash: 5d980494 Block 2 hash: fb796088 Block 3 hash: b0b1fc0e Is the chain valid? True
Look familiar? Those are the exact hashes from the hero image and the tamper lab. Same input, same output. Real blockchain code also mixes a timestamp and a nonce (a "number used once") into each hash, but the chaining idea is exactly what you see here.
Thousands of copies, one truth
Chained hashes make tampering visible. Decentralization makes it useless. Because thousands of computers each hold a full copy of the blockchain, everyone can check everyone else's work:
- When a new block is added, computers on the network verify it and add it to their own copy.
- If one copy has been tampered with, its hashes will not match the others.
- The network trusts the version that the majority of computers agree on. This agreement is called consensus.
On networks like Bitcoin, adding a block takes real work. To mine a block, a computer must find a hash that meets a difficulty target, like starting with a certain number of zeros. The only way to find one is brute force: change the nonce, hash again, and repeat millions of times. Higher difficulty means many more tries.
How hard is it really? Bitcoin miners use extremely powerful computers, and it still takes the network about 20 minutes on average to mine a coin. The difficulty value they are working against is over 17 trillion. Rewriting old blocks on thousands of computers at once is simply not realistic.
Where blockchain is used
Cryptocurrency made blockchain famous, but the idea of a tamper-proof shared record book is useful anywhere people need to trust records without trusting a single record-keeper:
Cryptocurrency
Bitcoin, Dogecoin, and others use a blockchain as their entire ledger of who owns what.
NFTs
Non-fungible tokens use a blockchain to record who owns a unique digital item.
Supply chains
Companies track products from factory to store, with a digital trail nobody can quietly edit.
Records and contracts
Medical records, property deeds, and digital contracts can be verified without a middleman.
A tiny blockchain in Python
A blockchain links blocks together by storing a hash of the previous block. This Python program builds a three-block chain and verifies it.
Quick quiz
1. What happens to a hash if you change one letter of the input?
2. Why does editing the data in Block 2 break Block 3?
3. What makes a blockchain "decentralized"?
Keep exploring the chain
You now know the secret behind blockchain: hashes chained together, copied across thousands of computers. Next, see what people build on top of it, or dig deeper into the cryptography that keeps data safe.