TL;DR
Proof of work is a rule that a message counts only if it carries a number, called a nonce, that makes the hash of the message fall below a target value. Finding such a number takes many guesses, so it costs real computing time. Anyone can check the answer with a single hash. The idea makes spam and fake identities expensive, and Bitcoin uses it to decide who may add the next block to its ledger.
Builds on: Cryptographic Hash Function, Geometric Distribution, Expected Value · Leads to: Blockchain, Distributed Consensus
Where it's used
Bitcoin block production. Each new block of the Bitcoin ledger must come with a nonce that makes the block's hash fall below a target. The network adjusts that target over time so that a new block appears, on average, about every ten minutes, however much computing power joins or leaves. The effort, not a vote or a stake, is what gives a miner the right to propose the next block.
Stamping email. Hashcash, a scheme built for email, attaches a small proof-of-work stamp to each message. One stamp costs a sender almost nothing. Sending a million messages, each with its own stamp, costs a spammer a great deal of computing time, which is the point.
Slowing bots. Some websites ask a visitor's browser to solve a small puzzle before accepting a form. A person notices a fraction of a second. A bot that submits thousands of forms per minute notices the cost in full.
How it works
Use a toy hash whose outputs are the 8 values 0 to 7, which is a 3-bit hash. The puzzle is: find a nonce whose digest is 0. The block data is the string "alice pays bob 5".
-
Try nonce 0. Compute the digest of the data together with nonce 0. Suppose it is 5. The target is 0, so 5 is too large and the block is rejected. Check: 5 is not 0.
-
Try nonce 1. Suppose the digest is 3. Still too large, so reject. Check: the miner changed only the nonce, so the data is the same and the digest changed.
-
Try nonce 2. Suppose the digest is 6. Reject again. Check: three tries so far, none valid.
-
Try nonce 3. Suppose the digest is 0. It is below the target, so the block is accepted. Check: the miner needed four hashes to get here.
-
Verify. Anyone who receives the block hashes the data with nonce 3, gets 0, and accepts. Check: the verifier spent one hash; the miner spent four.
-
Why guessing is random. Each digest looks unrelated to the others, so each try has the same chance, 1 in 8, of being 0. The number of tries until the first success is therefore a geometric count, with an average of 8.
flowchart TD
A[Pick data and nonce] --> B[Hash data with nonce]
B --> C{Digest below target?}
C -- no --> D[Increase nonce]
D --> B
C -- yes --> E[Valid block: broadcast it]
E --> F[Anyone checks with one hash]
Making the target smaller makes each try less likely to succeed, so the average number of tries goes up. That single knob is how the network controls the rate at which blocks appear.
The math
Let be a cryptographic hash function whose digests have bits, read as integers in the range to , where . Given block data and a target with , a nonce is valid when . Finding a valid is the proof of work. Checking takes one evaluation of .
Step 2 in symbols: the chance one try succeeds
If digests behave like independent, independent uniform values over the possible outputs, then each try succeeds with probability
In the toy, and the target is , which accepts only the digest 0. So , matching step 4.
Step 5 in symbols: how many tries
Let be the random number of tries up to and including the first valid nonce. The tries are independent with success probability , so is geometric:
Its mean is . In the toy, . The miner's expected work is hashes, and the verifier's work is one hash.
Step 6 in symbols: time
Suppose the whole network computes hashes per second, and is the same for every try. The expected time to the next valid block is
When is tiny, , so the chance that no valid nonce appears in seconds is approximately . This is the exponential approximation: the time to the next block behaves roughly like an exponential waiting time.
Worked examples
Take and , so .
- The chance that the first try succeeds: .
- The chance that the first success is on try 3: .
- Numerically, .
- The chance that none of the first 8 tries succeeds: . Compute , then , then .
- Check: the average is 8 tries, and about a third of the time the first 8 tries all fail. That is plausible for a 1-in-8 event.
Answer: the first valid nonce appears on try 3 with probability about 0.096, and about 34 percent of the time, 8 tries find nothing.
Use a 256-bit hash, so . Require the digest to start with 20 zero bits. That means , so and
- .
- Expected tries: .
- Suppose the network computes hashes per second. Expected time: seconds.
- The chance of no valid nonce in tries, which is twice the average, is . Since is tiny, this is about .
- Check: .
Answer: each block takes about a second at this rate, but about 13.5 percent of the time a single run of tries still finds nothing. The rate per second is an assumption chosen to make the arithmetic concrete.
This example is illustrative. Suppose the network computes hashes per second in total, and the target is set so that the expected number of tries per block is . Then .
- Expected time per block: seconds.
- seconds is 10 minutes, the target spacing in this example.
- A block that takes more than 20 minutes is twice the expected time. The chance of that is about , from the same exponential approximation as before.
- Try it: what is the chance that a block takes more than 30 minutes? Use .
Answer: , about 5 percent. Long gaps happen, but they are rare, and the average gap is still set by the target.
Common mistakes and tradeoffs
It is tempting to think that proof of work proves the computation was useful. In fact the puzzle is arbitrary. It proves only that a search was done, and the search has no value outside the puzzle.
It is tempting to think that the fastest machine always wins. In fact the search is a lottery. A machine with twice the hash rate has twice the chance per second, so over many blocks its share of wins matches its share of total power, but any single block can go to anyone.
It is tempting to think that checking a proof is as costly as producing one. In fact the verifier does one hash, while the prover does about hashes. That gap is what makes the scheme useful, and it is also what the target controls.
The tradeoffs are real. Proof of work spends electricity and hardware on a puzzle with no other output. It works best when honest participants cannot cheaply fake effort. Its alternatives change what the scarce resource is: Byzantine fault tolerant consensus protocols that rely on votes among known members need no puzzle at all, and proof-of-stake systems choose proposers by a stake instead of by computing.
| Situation | Proof of work fits? | Why |
|---|---|---|
| Open network with no identities | Often yes | Effort gives a cheap, anonymous way to decide who speaks |
| Permissioned network of known members | Usually no | Voting or a known leader is cheaper and faster |
| Latency-sensitive service | Usually no | Random waits add delay that a deterministic rule avoids |
When to use it. Use proof of work when you need a rate limit or a fair lottery among anonymous participants and can accept the energy cost.
When not to. Do not use it when a simple registry, an account, or a known set of voters already solves the problem.
History
In 1992, Cynthia Dwork and Moni Naor proposed making junk email cost the sender a modest amount of computation, so that honest users barely notice and bulk senders pay.
Adam Back's Hashcash, proposed in 1997, attached hash-based stamps to email and gave the approach its popular name.
In 2008, the Bitcoin white paper used proof of work to order transactions in a ledger that no one controlled. The network started in 2009, and proof of work became the best-known use of the idea.
Recap
- A nonce is valid when hashing the data with it gives a digest below a target.
- Each try succeeds with probability , so the number of tries is geometric with mean .
- Finding a valid nonce costs about hashes, and checking one costs a single hash.
- The expected time to a valid block is , so the target sets the pace.
- Read Distributed Consensus to see why a network needs a rule like this, and Blockchain to see how valid blocks are chained together.
Check yourself
QuestionRecall: what makes a nonce valid under proof of work?Show answer
The nonce is valid when hashing the block data together with the nonce gives a digest that, read as an integer, is below the target .
QuestionComputation: a hash has 256 possible digests and the target accepts only the digest 0, so . What is the probability that the first valid nonce is on try 2?Show answer
The chance is . The expected number of tries is 256, so a success on try 2 is unlikely, at under 0.4 percent.
QuestionWhy: why does doubling the network's total hash rate halve the expected time to a block, but not guarantee that the next block comes sooner?Show answer
The expected time is , so doubling halves it. But each try is random, so the time to the next block is still a random variable, and a long wait can still happen. Only the average moves.
QuestionApplied: a network sets its target for an expected block time of 10 minutes. Overnight the total hash rate doubles and the target does not change. What is the new expected block time?Show answer
Expected time is . With doubled and unchanged, the new time is minutes. The network would then need to raise the target to restore the 10-minute pace, which is why real systems adjust it.