The UTXO model
Suggest an editIn a bank account, in PayPal, and in every other traditional payment system, a balance is a number stored somewhere, and you change the number to move value around. Bitcoin stores individual coins instead, each with a value and an owner, and your balance is a sum you compute by adding up the coins that are yours. This lesson is about why Bitcoin makes that choice and what it buys.
Two ways to track money
Imagine you want to build a digital payment system. There are two natural ways to do it.
The first way is the account model, and it's the one almost every traditional system uses. The system keeps a table. Each row has a user and a balance. To send money, you decrement one row and increment another. To check a balance, you look up the row.
The second way is the UTXO model, and it's the one Bitcoin uses. The system doesn't keep a table of users and balances. It keeps a set of coins. Each coin has a specific value and a specific owner. To send money, you don't update any balances. You destroy some of your coins and create new ones for the recipient. To check a balance, you scan for every coin still belonging to you and add them up.
UTXO stands for Unspent Transaction Output. Every coin in Bitcoin started life as the output of some past transaction and has not yet been spent by being used as the input of a later one. The set of every UTXO across the chain, the UTXO set, is what Bitcoin nodes track. There is no balance ledger.
In the account model, "Alice has 2.5 BTC" is a fact stored in one place. In the UTXO model, Alice has 2.5 BTC because she happens to hold two unspent coins worth 1.0 and 1.5. The chain doesn't know who Alice is or what her total is. It just knows about those two specific coins.
A node validates a spend with three checks
If you're meeting the UTXO model for the first time, your reaction is probably "this is a complicated way to do something simple." Why not just update Alice's balance and Bob's balance directly, like every database in the world?
The answer goes back to the Bitcoin design philosophy lesson. Bitcoin is designed for a network where there's no operator, every node has to validate every transaction independently, and the validation has to be cheap and deterministic. UTXOs are a way of structuring state that makes that validation easy.
To validate a UTXO transaction, a node has to check three things. The coins it spends exist as unspent outputs in the current UTXO set. Each of them comes with a valid signature from its owner. The values of the new coins add up to no more than the values of the old ones. Each check involves only the coins the transaction names and is independent of everything else happening on the chain.
Suppose Alice signs two transactions that spend her 1.0 BTC coin, one paying Bob and one paying Carol. Only one of them is included in a block, and it removes the coin from the UTXO set. From then on the other transaction fails the first check on every node, because the coin it points at is no longer there. Each coin can only be spent once, so a node finds out whether money has already been spent with one lookup.
In the account model the transaction would say "move 1.0 BTC from Alice to Bob" and point at no particular coin. A node has to look up Alice's balance, and that is not enough. If her balance is 2.5 BTC, the same signed message is still valid after it has been applied once, and someone could submit it again. Blockchains that use accounts add a counter to every account to stop this, the nonce from the transaction flow lesson. A UTXO transaction needs no counter, because the coins it names are gone after the first time.
A payment destroys coins and creates new ones
The UTXO model produces a way of paying that feels strange the first time you see it. A transaction takes one or more existing coins as inputs, destroys them, and creates one or more new coins as outputs. The total value of the new coins has to equal the total value of the old coins, minus a small fee that goes to whoever includes the transaction in a block.
Now imagine Alice wants to send 0.3 BTC to Bob. She holds the 1.0 BTC coin from the first diagram. There is no operation called "subtract 0.3 from Alice and add 0.3 to Bob." There is only "destroy old coins, create new coins." So her transaction takes her 1.0 BTC coin as the input, and that coin is destroyed in the process. She creates two new coins as outputs: one worth 0.3 BTC, owned by Bob, and one worth a little less than 0.7 BTC, owned by Alice herself. The difference between the input value and the output value is the fee.
That second output, the one going back to Alice, is called a change output. It exists for the same reason change exists in cash. If you owe someone three dollars and you only have a ten in your wallet, you don't tear the ten in pieces. You hand over the ten and the other party hands you back seven. In the same way, you don't split a coin. You hand the whole coin to the transaction and the transaction hands you a new, smaller coin in return.
An input points at one earlier output
A transaction is a record with a list of inputs and a list of outputs. Each input points back to the specific coin being spent, by naming the past transaction that created it and the number of the output in that transaction. In the diagram below these two values are labelled prev_txid and prev_vout. The input also carries the unlocking script, the data that satisfies the coin's lock, typically a signature and the public key that the signature was produced from.
Each output has the value of the new coin, stored as an integer in satoshis (the smallest unit of Bitcoin, one hundred-millionth of one BTC), and a locking script, a small program defining the condition the future spender will have to satisfy. The typical condition is "prove ownership of the private key corresponding to this address." The output sets the condition, and the input of a later transaction satisfies it. Locking scripts are written in Bitcoin Script, the deliberately limited language from the previous lesson.
The fee paid to the miner is not its own field in the transaction. It's the difference between the total input value and the total output value. If a transaction has 1.0 BTC of inputs and 0.999 BTC of outputs, the 0.001 BTC difference goes to whoever includes the transaction in a block. If Alice's wallet left out the change output, the whole 0.7 BTC would go to the miner.
What the model gives and what it costs
Validating each transaction by its own coins pays off in three more ways.
Parallelism. Two transactions that touch different UTXOs are independent. The network can validate them in parallel without coordination. Two account-model transactions that both touch Alice's balance may conflict, so they have to be processed one after the other.
Privacy, within limits. Each coin has its own owner condition, and the chain doesn't have a permanent identifier for a user. Alice can have a hundred different addresses, each holding different coins, and there's no on-chain record that they're all hers. In an account model, every transaction Alice makes is tied to the same account identifier, so her whole history is linked together. The limit is that every transaction is public, and a transaction that spends coins from two of Alice's addresses links those addresses to each other.
Audit clarity. Every coin's history can be traced. This specific coin was created by this transaction, which was funded by these earlier coins, which were created by these even earlier transactions, all the way back to a mining reward.
The trade is that the UTXO model uses more storage for the same number of users, because the chain has to track every unspent coin separately rather than a single balance per user. Reading a balance means scanning the UTXO set and summing coins, where the account model does one lookup, and every payment means choosing coins and making change. A set of locked coins also has nowhere for a program to keep its own data between transactions, so an application that many users share, such as a token with a million balances, is hard to build on it. Bitcoin accepts that trade, and several other chains, Ethereum among them, made the opposite one and use account models, as the account model lesson of the Ethereum course explains.