As one of the earliest cryptocurrencies to emerge, Bitcoin adopted the UTXO model as its underlying storage data structure. Unspent Transaction Outputs (UTXOs) represent specific amounts of Bitcoin that you have received but have not yet spent. Think of each UTXO as a distinct bill in your wallet, each with its own unique value.
As implied by its name, a UTXO is an output from a Bitcoin transaction. It remains a UTXO until it is used as an input for a subsequent transaction. When you receive Bitcoin, what you are actually receiving is a UTXO. The balance displayed in your wallet is the sum of all UTXOs you have received.
The UTXO set encompasses all UTXOs present on the Bitcoin blockchain at any given time. Bitcoin nodes maintain this set to verify the existence and ownership of coins, thus helping to prevent double-spending, an issue that had undermined earlier efforts to create a decentralized digital currency.
Transactions based on the UTXO model consist of two parts: inputs and outputs. When a user initiates a new transaction, their wallet selects sufficient UTXOs to cover the required amount.In every valid transaction, the sum of all input values must be greater than the sum of all output values. The difference between these sums represents the transaction fee:
$$ \sum_{\text{inputs}} \text{value} = \sum_{\text{outputs}} \text{value} + \text{fee} $$
Similar to cash payments, a person can't pay someone $5 by tearing a $10 bill in half. Instead, they must use the $10 bill and receive the change. UTXOs function similarly; they must be spent in their entirety, and any Change is given back as a new UTXO.
$$ \text{Change} = \sum_{\text{inputs}}\text{value} -\text{Price} - \text{fee} $$
Transaction fees are a significant concern for BTC users during transactions. It's common to hear complaints within the community about small transactions necessitating additional fees, sometimes consuming up to 80% of the transaction amount. As mentioned earlier, the number of UTXOs involved in a transaction determines the transaction cost for the user.
$$ \text{Transaction size} = \text{input count} \times \text{input size} + \text{output count} \times \text{output size} + 10
$$
Where:
The total fee for a transaction is determined by multiplying the transaction size by the selected fee rate.
$$ \text{Total fee} = \text{Transaction size} \times \text{Fee rate} $$
Where: