Learning LibraryBlockchain & DeFi LibraryTeens

What is a blockchain? A tamper-evident chain of data

Strip away the hype and a blockchain is a simple idea: a list of data blocks, each fingerprinted and linked to the last, copied across many computers so no one can secretly rewrite history.

The big idea

A blockchain is a chain of hash-linked blocks, shared across a network, that is tamper-evident because any change breaks the links.

See it in code

1The basics

A block is just a record: some data, a link to the block before it (prev), and its own fingerprint. Here's a single block as a dictionary, with its hash computed from prev plus data:

python
import hashlib

def sha(text):
    return hashlib.sha256(text.encode()).hexdigest()[:10]

block = {"data": "Alice pays Bob", "prev": "genesis"}
block["hash"] = sha(block["prev"] + block["data"])

print("Block:", block["data"])
print("Hash:", block["hash"])
Run it — one block with its own computed fingerprint:
Block: Alice pays Bob
Hash: 755a4b0a38

The block carries its own fingerprint, 755a4b0a38. Because that hash is built from the block's contents, re-computing it is how anyone checks the block hasn't been touched.

2A step further

So verify one block: recompute its hash from the stored data and prev, then compare against the hash it's carrying. If they match, no one has edited it:

python
import hashlib

def sha(text):
    return hashlib.sha256(text.encode()).hexdigest()[:10]

block = {"data": "Alice pays Bob", "prev": "genesis"}
block["hash"] = sha(block["prev"] + block["data"])

# recompute from the stored fields - does it still match?
check = sha(block["prev"] + block["data"])
print("Stored hash:", block["hash"])
print("Recomputed: ", check)
print("Untampered?", block["hash"] == check)
Run it — the recomputed hash matches, so the block is intact:
Stored hash: 755a4b0a38
Recomputed:  755a4b0a38
Untampered? True

The stored and recomputed hashes match, so Untampered? is True. That's one block verified — a whole chain just repeats this check and also links each block to the one before.

3In our world

Now link two blocks. Each stores the hash of the block before it, so block 2's prev should equal block 1's real hash — and checking that equality is how the network confirms the chain is intact:

python
import hashlib

def sha(text):
    return hashlib.sha256(text.encode()).hexdigest()[:10]

b1 = {"data": "Alice pays Bob", "prev": "genesis"}
b1["hash"] = sha(b1["prev"] + b1["data"])

b2 = {"data": "Bob pays Carol", "prev": b1["hash"]}
b2["hash"] = sha(b2["prev"] + b2["data"])

print("Block 2 points back to:", b2["prev"])
print("Block 1's real hash is:", b1["hash"])
print("Chain valid?", b2["prev"] == b1["hash"])
Run it — block 2's link matches block 1's hash, so the chain is valid:
Block 2 points back to: 755a4b0a38
Block 1's real hash is: 755a4b0a38
Chain valid? True

Because the links match, the chain checks out. Now imagine tampering with block 1's data: its hash would change, block 2's stored prev would no longer match, and Chain valid? would flip to False. Copy this chain across thousands of computers, and rewriting it everywhere at once becomes practically impossible.

The same idea, everywhere

The idea — a shared, append-only, tamper-evident record — solves a trust problem far beyond cryptocurrency: supply-chain tracking, certificate registries, voting research, any ledger many parties must agree on without a single boss. Blockchain is one answer to 'how do strangers share a record they can all trust?'

Try it yourself

Add a third block linked to block 2, then change block 1's data and re-run the checks — watch validity break down the chain. Then store the blocks in a list and loop a full verify() over all of them.

The common mistake

Thinking a blockchain makes data true. It only makes data tamper-evident and ordered — it guarantees the record wasn't changed after the fact, not that what was written was honest. Garbage written into a block is still garbage; the chain just proves no one edited it later.

What it unlocks

The big picture rests on hashing, blocks and chains, and agreement via proof of work.