It is incredibly fascinating how Bitcoin transactions work, very similar to a cash transaction.
In many ways, Bitcoin mirrors how we transact in cash offline. With cash, you can transact in a fully peer-peer manner. If you go to buy a pack of biscuits in a shop, that transaction is only known to you and the shop attendant at that point in time.
Before Bitcoin, we didn’t have that online, all transactions have to go through one third-party which is usually a bank or a financial institution.
But what happens in your wallet before a transaction is sent out?
Let us see how a typical transaction happens in a shop.
You buy a loaf of bread for N550, let’s assume that what you have is N700, a N200 and a N500 note.
You pay the shop attendant N700 from which they then give you ‘change’ of N150.
For them to give you this change, they will be able to give you in different denominations as long as it sums up to N150.
E.g N100 + N50 notes, three N50 notes, fifteen N10 notes etc.
Now this is how a Bitcoin wallet ‘gathers’ funds from your wallet to be sent out.
When you receive Bitcoins in your wallet, that transaction is referred to as an unspent transaction output (UTXO) and is recorded on the Bitcoin ledger.
The sum of the UTXOs in your wallet is your balance. When you’re transferring Bitcoin to another address, the wallet, gathers UTXOs that are equal to or greater than that amount and sends it.
If Precious has 0.5BTC in her wallet, it’s most likely a collection of UTXOs of different amounts. Let us assume she has that from three UTXOs with 0.1BTC, 0.2BTC and 0.2BTC.
If she needs to send 0.25BTC to Tumise, the wallet combines 0.1BTC + 0.2BTC to get 0.3BTC from which 0.25BTC is sent to Tumise and 0.05BTC to her wallet.
This creates two new UTXOs, one for 0.25BTC and another for 0.05BTC.
The concept of sending back change also happens here, if the UTXOs gathered are more than the amount you’re sending, the remaining amount will be returned to your wallet via a change address, this is now a new UTXO that you can go ahead to spend. In the example above, the 0.05BTC sent back to Precious is the ‘change’ she has gotten from that transaction
If you haven’t read about Bitcoin, the whitepaper https://bitcoin.org/bitcoin.pdf is a good place to start from.