Unspent Transaction Outputs or UTXOs serve as globally-accessible evidence that you have Bitcoin in your digital wallet.
A bitcoin transaction has both an input and an output. The input is the address where the bitcoin is sent from; the output is the address where it is sent to.
If an output has already been spent, it cannot be spent again. However, an Unspent Transaction Output can be used, or spent, as an input in another transaction. If you don’t have a UTXO, that means you don’t have any bitcoins in your wallet.
Before going further into how a UTXO works, we have to understand first how bitcoin transactions are designed.
Basically, to create a new transaction, you have to use the output of a previous transaction as input to the new one. The following example will illustrate this point.
Suppose John wants to send Jane 1 BTC and has to pay a transaction fee of 0.20 BTC. The input of that transaction would look like this:
- Input 1 — 0.20 BTC
- Input 2 — 0.20 BTC
- Input 3 — 0.20 BTC
- Input 4 — 0.20 BTC
- Input 5 — 0.20 BTC
- Input 6 — 0.20 BTC
Taking into account the 0.20 BTC transaction fee, the output of the transaction — the amount Jane will receive — will look like this:
- Output 1 — 0.20 BTC
- Output 2 — 0.20 BTC
- Output 3 — 0.20 BTC
- Output 4 — 0.20 BTC
- Output 5 — 0.20 BTC
Thus, if John had a balance of 10.852 at the beginning of the transaction, his balance will be 9.652 after the transaction is completed.
How Do UTXOs Work?
As mentioned earlier, UTXOs are globally accessible; they are listed in a global database, the UTXO set, where you can see all the spendable accounts available for use in bitcoin transactions. If you want to create a new transaction, you have to use some unspent output from the UTXO, causing the UTXO to shrink. Or if you create a new unspent output, the UTXO will grow.
How do you track the total of all your existing unspent outputs?
That’s the job of bitcoin full nodes, the type of node that completely validates all the transactions and blocks given to it, after making sure that they — the blocks and transactions — adhere to the network’s consensus rules.
Full nodes make sure that you are not spending non-existent bitcoins, and that you are not double-spending — using bitcoins that you have already spent.
Your bitcoin balance is the total of all the individual outputs that your private key can spend. When you initiate a transaction, you actually need to use all of the outputs in your UTXO.
Let’s say you have a UTXO worth 5 BTC and you have to pay someone 2 BTC. You can’t simply spend the 2 BTC but must spend everything you have and create two outputs.
The first output will be the 2 BTC payment to the person you owe and the second output will be the 3 BTC which goes back to your wallet as change.
In fact, when you pay someone, it does not register on your wallet that you made two transactions. That’s because everything happens behind the scenes. You will also notice that every time you make a transaction, the transaction fee is sent to a new address, called the change address, which is automatically generated by HD wallets, or Hierarchical Deterministic wallets, which generate a pattern of public and private keys that are difficult to guess.
The sizes of transactions can vary. Smaller transactions can incur a fee 1/3 greater than the value of the transaction. Transactions whose fees are greater than their value are called dust.
If you have received several small inputs, you combine them to create a large output. However, this can incur a high transaction fee. When users realize they have to pay high transaction fees, they often blame the wallet they are using. In fact, it is the small payments they are receiving that incur these fees.
While the outputs we’ve discussed above are spendable outputs, there are also unspendable outputs, outputs from before the Bitcoin Core client version 0.9.
Unspendable outputs arose when Bitcoin developers used the programming language called Script to build applications like digital records and smart contracts. These applications produced outputs that were unspendable but were still included in the UTXO set.
The existence of unspendable outputs meant that the UTXO kept on growing, keeping full nodes busy monitoring all the outputs in the UTXO set. As a result, running a full node became expensive.
Bitcoin Core client versions later than the 0.9 version include a return operator (OP_RETURN) that enables operators to create unspendable outputs outside the UTXO set. Although these unspendable outputs are not stored in the UTXO set, they are still recorded on the blockchain.