The one-line mental model
A blockchain is a replicated ledger in which every new page is sealed with a fingerprint of the page before it, so rewriting one entry means rewriting every page that follows and persuading the entire network to accept your version.
Prerequisites
- !A rough idea of what a hash function is (SHA-256 at a high level)
- !The difference between a central database and a peer-to-peer network
What You'll Learn
- 1Describe the exact fields stored in a block header and why previousHash links pages together
- 2Simulate proof of work and predict how the difficulty adjustment keeps block times stable
- 3Explain why reorganizing history gets exponentially harder with each confirmation
- 4Compare public, private, and consortium networks on the axes that actually matter
Replication alone does not give you a ledger
A conventional database trusts one machine. Every write is authorized by the operator, and if the operator is compromised, the entire history can be rewritten silently. Mirroring that database across a hundred read replicas does not fix the problem, because a replica can only copy what the primary tells it â it cannot tell a forged history apart from a genuine one.
A blockchain changes the trust model by assuming the opposite: no machine is trusted, every machine keeps a full copy, and correctness is enforced by math rather than by permission. Each node independently re-verifies every block against a fixed rule set: the block must hash below the target, its transactions must be valid, its timestamp must be sane, and its previousHash must match the tip the node already accepted. A block that violates any rule is rejected locally, no matter how many peers advertise it.
The result is a ledger where validity is a property any observer can check, rather than a claim the operator must be believed on.
What a block actually stores
A block is not a mystical object. It is a small record with a header that gets hashed and a body of transactions. Stripped to the essentials, a header holds four things: the block height, the timestamp, the digest of the previous block, and a nonce that miners vary during proof of work. The body is a flat list of transactions plus a root that commits to all of them at once.
{
"index": 418331,
"timestamp": 1705123456,
"previousHash": "00000000000000000002f2a4b1a06d0d0c1a8e9f4b3d2c7a6e5f4d3c2b1a0987",
"merkleRoot": "7d4a1c9f0e2b8a3d5c6f7e8d9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b",
"nonce": 372018495,
"difficulty": 343749953,
"transactions": [
{ "from": "0xA1", "to": "0xB2", "value": 0.42, "fee": 0.00021 },
{ "from": "0xC3", "to": "0xD4", "value": 1.05, "fee": 0.00019 }
]
}
Two fields deserve special attention. previousHash is what makes the structure a chain rather than a pile, and merkleRoot compresses thousands of transactions into a single 32-byte value so that any light client can prove one transaction belonged to the block without downloading the rest.
Hash links make tampering expensive
Because the header hash covers previousHash, altering even one byte of an old block produces a brand-new hash, which no longer matches the value stored in the following block. The tamperer must therefore also regenerate block two, then block three, and so on to the current tip. This Python sketch shows how quickly a chain verifies and how violently it detects edits:
import hashlib
import json
def block_hash(block: dict) -> str:
payload = json.dumps(block, sort_keys=True).encode()
return hashlib.sha256(payload).hexdigest()
def make_block(index, data, previous_hash, nonce=0):
return {
"index": index,
"timestamp": index * 600,
"previousHash": previous_hash,
"nonce": nonce,
"data": data,
}
def validate_chain(chain):
for prev, cur in zip(chain, chain[1:]):
if cur["previousHash"] != block_hash(prev):
return False, f"broken link at block {cur['index']}"
if cur["index"] != prev["index"] + 1:
return False, f"gap in heights at block {cur['index']}"
return True, "ok"
genesis = make_block(0, "first", "0" * 64)
b1 = make_block(1, "alice pays bob", block_hash(genesis))
b2 = make_block(2, "bob pays carol", block_hash(b1))
chain = [genesis, b1, b2]
print(validate_chain(chain)) # (True, 'ok')
b2["data"] = "bob pays mallory" # quiet edit
print(validate_chain(chain)) # (False, 'broken link at block 2')
The second call is the whole security story in one line: a single unnoticed edit is caught by the next block's pointer, and every confirmation added afterward buries the tampered block deeper under fresh, network-agreed work.
Proof of work in ten lines
Nakamoto consensus lets any node propose the next block, so it needs a rule that makes proposing expensive â otherwise everyone would broadcast conflicting blocks for free. Proof of work does that by requiring the proposer to find a nonce whose hash starts with a run of zeros. Finding one is brute-force luck; checking one is trivial, which is exactly the asymmetry the system needs.
def proof_of_work(block, difficulty=5):
target = "0" * difficulty
nonce = 0
while True:
block["nonce"] = nonce
digest = block_hash(block)
if digest.startswith(target):
return nonce, digest
nonce += 1
n, h = proof_of_work(make_block(3, "reward to miner", block_hash(b2)))
print(f"nonce={n} hash={h}")
Difficulty is retargeted on a schedule so that blocks keep arriving roughly every ten minutes regardless of how much hardware joins the network. That feedback loop is what keeps the ledger's heartbeat steady and what converts energy expenditure into a direct cost for any attacker.
Proof of stake: same rules, different cost
Ethereum replaced mining with validators that lock a 32 ETH deposit as collateral instead of burning electricity. A validator is pseudo-randomly chosen to propose each block, and a committee attests to it; proposing or attesting against the chain you already attested to triggers slashing, which destroys part of the stake. The economic asymmetry that proof of work gets from hardware, proof of stake gets from the threat of burning your own capital.
Neither design is free. Proof of work converts electricity into security and concentrates production where power is cheap. Proof of stake converts locked capital into security and concentrates influence among large holders unless delegation spreads it out. Both then inherit the same fork-choice logic on top: honest participation must be cheaper than defection, which is the only property that actually matters when you compare consensus designs.
When the network disagrees: forks
Two honest miners can solve a block within seconds of each other. Nodes see one first, adopt it, and briefly hold a competing branch. The fork-choice rule is simple: follow the branch with the most accumulated work, and reorganize when a competing branch overtakes yours. Transactions in the abandoned branch become pending again and are usually re-included.
| Scenario | Typical outcome | What a user should do |
|---|---|---|
| Two blocks mined near-simultaneously | Resolves within one or two blocks | Wait for 1 confirmation |
| Node briefly partitions | Heals when the partition closes; longest-work branch wins | Wait for 6 confirmations on large value |
| Client accepts an invalid block | Rejected locally by rule verification regardless of peer votes | Nothing; rules are enforced locally |
| True consensus split (rule disagreement) | Two chains persist until the community coordinates | Treat as an incident; do not move funds |
Finality differs by consensus family. Proof-of-work chains offer probabilistic finality â confidence grows with depth but never reaches certainty. Proof-of-stake chains such as post-merge Ethereum can finalize explicitly, after which reversing a block requires validators to be slashed for destroying a large stake.
Choosing the network type that fits
The consensus machinery above can run with open membership or restricted membership, and that single choice reshapes almost every other property.
| Network | Who may join | Who may read | Typical use | Example |
|---|---|---|---|---|
| Public permissionless | Anyone with a client | Anyone | Censorship-resistant value transfer | Bitcoin, Ethereum |
| Private permissioned | Invited nodes only | Configured parties | Internal settlement, audit trails | Hyperledger Fabric |
| Consortium | A group of organizations | Members, sometimes public | Interbank clearing, trade finance | R3 Corda |
| Hybrid | Public read, gated write | Mixed | Token issuance with compliance gates | Permissioned rollups |
Public networks win on neutrality and censorship resistance and pay for it with slow finality and volatile fees. Permissioned networks deliver throughput, privacy, and known counterparties, but reintroduce the trusted operator that a public chain removes. Pick based on whether your users need to trust each other or need to trust nobody.
đĄDebugging trick
When a transaction "disappears," check the block height it landed in before suspecting the wallet. Many reported failures are a node that is still on a lower-height fork; comparing your node's tip hash against two independent explorers settles the question in seconds.
Common Mistakes
Treating a single confirmation as proof of settlement
Fix: Scale confirmations to value: one for a coffee purchase, six or more before crediting a large deposit
Assuming immutability means data cannot be removed or changed
Fix: Immutability means changes are visible and expensive, not impossible; plan retention and privacy rules before you write
Believing encryption protects data stored on a public chain
Fix: Hashing is not encryption â anything written to a public ledger should be assumed permanently readable
Judging a chain by transactions per second in isolation
Fix: Read throughput together with finality time, fee behavior under load, and how decentralized block production actually is
Best Practices
- Store only hashes or commitments on-chain when off-chain data can be kept private or large
- Verify headers locally with your own node instead of trusting a third-party explorer for critical decisions
- Model fork risk explicitly in application logic: treat unconfirmed balances as pending, never as spendable
- Document which consensus rules your contract depends on, including fee market and finality assumptions
Interview Questions
Q1: Why does proof of work make history hard to rewrite?
Each block commits to the hash of the previous one, so changing an old block changes every descendant hash. An attacker must redo all the proof of work for the altered blocks and then outpace the honest chain's accumulated work, which grows continuously as new blocks are added.
Q2: What is the difference between immutability and finality?
Immutability describes tamper evidence: any edit is detectable because hashes no longer line up. Finality describes certainty that a block will never be reverted. A work-based chain can be immutable while still having reversible recent blocks; a finalized proof-of-stake block is both.
Q3: Who decides which fork wins?
Nobody centralizes the decision. Each node applies the same fork-choice rule â most accumulated work for proof of work, or the finalized checkpoint for proof of stake â and convergence emerges because rational miners and validators extend the branch that their peers already accept.
Key Takeaways
- A block header binds height, timestamp, previousHash, and nonce into one hash that anyone can recompute
- Chained hashes convert data tampering into a requirement to rewrite the entire suffix of the chain
- Proof of work makes block production costly to spam while keeping verification nearly free
- Forks are routine; the fork-choice rule, not an authority, resolves them deterministically
- Finality guarantees differ by consensus family, so confirmation policy must match the chain you build on