Double spending is the risk that the same digital coin is spent twice, because digital data can be copied; Proof of Work prevents it by making every node accept only one ordered history of transactions, which is extremely costly to rewrite.
The problem. With physical cash, once you hand over a note you no longer have it. A digital token is just data. Without a central bank keeping one ledger, a user could send the same coin to two people at the same time, or pay a merchant and then broadcast a conflicting transaction sending the same coin back to himself.
How PoW solves it
- Public ledger and validation: every node checks each new transaction against the blockchain (the UTXO set in Bitcoin). A transaction spending an already-spent output is rejected.
- One order of transactions: if two conflicting transactions are broadcast, miners include only one of them in a block; the other becomes invalid.
- Mining with PoW: to add a block, a miner must find a nonce so that \(\mathrm{SHA256}(\mathrm{SHA256}(\text{header}))\) is below the target. This takes enormous computation but is easy to verify.
- Chained blocks: each block contains the hash of the previous one. To reverse a payment, an attacker must redo the PoW of that block and all later blocks.
- Longest (most-work) chain rule: nodes always follow the chain with the most cumulative work. An attacker's secret chain will be accepted only if it overtakes the honest chain.
- Confirmations: each block added after a transaction makes reversal exponentially less likely for an attacker with less than half the hash power. Merchants therefore wait for about 6 confirmations (about an hour in Bitcoin) for large payments.
Limitation: an attacker controlling more than 50% of the total hash power (a 51% attack) could build a longer chain and double-spend; for large networks like Bitcoin this is extremely expensive.