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.

Top: the miner hashes the header with nonce 0, 1, 2 and so on; each hash is compared with the target 010000 and fails until nonce 594 gives 00485a. Bottom: a node that receives the block hashes it once and checks 00485a is below 010000.
Mining block #1 at difficulty 2 took 595 hashes; checking it takes one.

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).

difficultytarget (6 hex)valid hash looks likechance per tryexpected tries
11000000e20ff1 in 1616
201000000485a1 in 256256
3001000000e6c1 in 4,0964,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 prev still holds the old hash, so the link breaks.
Before: four green blocks, each prev equal to the hash before it. After editing block 1 from Alice to Bob 5 to 500: block 1's hash is no longer below the target and block 2's prev no longer matches, so blocks 1 to 3 are red. To fix it the attacker re-mines block 1, then block 2, then block 3.
One edit turns its block and every later block invalid; hiding it means mining all of them again.

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 workPBFT-style voting
who takes partanyone, no list of membersa known set of n replicas
what stops cheatingthe cost of hashing (energy)quorums: up to f of 3f + 1 may lie
finalityprobabilistic: safer with each new blockfinal once a quorum commits
throughputlow (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.