The idea: a puzzle that is hard to solve and easy to check
A block is some data plus a small number called the nonce. The miner hashes the block header and looks at the result. If the hash is below a target, the block is done. If not, the miner changes the nonce and hashes again. A good hash function gives a result that looks random, so there is no way to aim: the only way to find a good nonce is to try, one hash per try. Anyone who receives the block checks it with one hash. That gap, many hashes to make and one to check, is the proof of work.
On the canvas the header is the string index|prev|data|nonce, hashed with real SHA-256. The page
keeps only the first 6 hex digits (24 bits) so the numbers stay readable; you can recompute every hash shown
with any SHA-256 tool. Press Mine to mine the next block, Tamper to edit an
old one and Check chain to verify it the way a node does.
Nonce, target and difficulty
The target is a number; a valid hash must be smaller. A smaller target means fewer valid
hashes, so more tries. On the page, difficulty d is the number of leading hex zeros
the hash needs: the target is 166−d. Each extra zero cuts the target by 16, so the expected number
of tries grows 16× (Demo 2: difficulty 1 vs 3).
| difficulty | target (6 hex) | valid hash looks like | chance per try | expected tries |
|---|---|---|---|---|
| 1 | 100000 | 0e20ff | 1 in 16 | 16 |
| 2 | 010000 | 00485a | 1 in 256 | 256 |
| 3 | 001000 | 000e6c | 1 in 4,096 | 4,096 |
The count is an average, not a promise. Block #2 at difficulty 2 needs only 5 tries, block #1 needs 595: a miner can be lucky or unlucky, but over many blocks the average holds (Demo 3: build a chain). Bitcoin uses the same rule with bigger numbers: a double SHA-256 of an 80-byte header, a 256-bit target that today needs about 19 leading hex zeros, a 32-bit nonce plus other fields to change when the nonce runs out, and the whole network trying about 1021 hashes per second. Every 2,016 blocks the network adjusts the target so that a block takes about 10 minutes on average.
Chaining the blocks
Each header also holds prev, the hash of the block before it. Block #0, the
genesis block, has prev = 000000. When the miner starts block #k it copies the hash of
block #k−1 into the header, so the work for block #k is done on top of that exact history
(Demo 1: mine one block). The links make the chain tamper-evident: a block's hash depends
on its prev, which depends on the block before, all the way back to genesis. The same idea, a hash that covers
other hashes, is behind Merkle trees.
Tampering forces redoing the work
Change one character of an old block and its hash changes completely. Two things break at once (Demo 4: tamper with block #1):
- The block's own proof fails: with the old nonce the new hash is almost surely not below the target.
- The next block's
prevstill holds the old hash, so the link breaks.
To hide the edit the attacker must find a new nonce for the edited block. That gives it a new hash, which breaks the next block's link, so that block must be re-mined too, and so on to the end of the chain (Demo 5: redo the work). Checking stays cheap: Check chain walks the blocks with one hash each and stops at the first one that fails.
Longest chain and the 51% attack
On the page the attacker redoes three small blocks in a few seconds. In a real network the honest miners keep adding blocks while the attacker works, and nodes follow the chain with the most total work (usually called the longest chain). The attacker's copy only wins if it catches up and overtakes, which needs more hashing power than all honest miners together: the 51% attack. A block buried under k newer blocks gets exponentially harder to replace as k grows, which is why exchanges wait for several confirmations.
Proof of work vs voting (PBFT)
| proof of work | PBFT-style voting | |
|---|---|---|
| who takes part | anyone, no list of members | a known set of n replicas |
| what stops cheating | the cost of hashing (energy) | quorums: up to f of 3f + 1 may lie |
| finality | probabilistic: safer with each new block | final once a quorum commits |
| throughput | low (one block per ~10 min in Bitcoin) | high, but messages grow with n² |
Voting among a fixed group is on Byzantine Fault Tolerance: PBFT. How SHA-256 works inside is on Inside AES-128 and SHA-256; why a deliberately slow hash protects passwords is on Password Hashing, and how transactions are signed on Digital Signatures.
The merkle root field of the header is explained on Bitcoin Merkle Trees and SPV Proofs.
What the page leaves out
The hash is cut to 24 bits and the header is a text string, not Bitcoin's binary header with version, Merkle
root of the transactions, timestamp and compact target bits. The page has one miner, no network,
no competing chains or forks, no block reward or fees, no difficulty adjustment, no extra-nonce, and no mining
pools or ASICs. Each block keeps the difficulty it was mined at; the nonce search always starts at 0, so the
results are deterministic.