A UTXO (Unspent Transaction Output) is an output of a previous transaction that has not yet been spent; in Bitcoin a user's balance is the sum of their UTXOs. Since each UTXO can be used as input only once and nodes reject any transaction that spends an already-spent output, double spending is prevented.
How the UTXO model works
- Each transaction has inputs (references to earlier UTXOs, each unlocked with the owner's digital signature) and outputs (new amounts locked to recipients' addresses).
- A UTXO must be spent completely. Any amount left over is sent back to the sender as a change output.
- Sum of inputs = sum of outputs + transaction fee.
- Every full node keeps the UTXO set: the list of all outputs not yet spent.
Example. Alice owns one UTXO of 5 BTC. She pays Bob 3 BTC:
- Input: Alice's 5 BTC UTXO (now spent)
- Output 1: 3 BTC to Bob (new UTXO)
- Output 2: 1.99 BTC change to Alice (new UTXO)
- Fee: 0.01 BTC to the miner
How it prevents double spending
- When a node receives a transaction, it checks that every input exists in the UTXO set and that the signature is valid.
- Once a transaction is accepted into a block, its inputs are removed from the UTXO set and its outputs are added.
- If Alice tries to send the same 5 BTC UTXO to Carol, that UTXO is no longer in the set, so nodes reject the transaction.
- If both conflicting transactions are broadcast at the same time, a miner can include only one in a block; after it is mined, the other becomes invalid everywhere. Proof of Work and confirmations then make it extremely hard to reverse.
Advantages: simple verification, easy parallel validation, better privacy (new addresses for change). Ethereum uses an account model instead, where it prevents replay and double spending with an account nonce (transaction counter).