4. How Bitcoin transactions work
In its simplest form, a Bitcoin transaction consists of four parts.
- Input. If Bob is sending BTC to Alice, this is Bob's address.
- Output. This is the address of the recipient – in our case, Alice;
- Bob’s digital signature.
In reality, things are more complicated, and most transactions have more than one input and output. Let's see why.
The amount of BTC you have in your wallet is the sum of all the Bitcoins that you received from other people. When you login to your wallet, you'll see its total balance – for example, 1.2 BTC. But in reality what you have are lots of separate pieces – all those past incoming transactions, or outputs.
When Bob sends BTC to Alice, he must take some of his past incoming transactions (outputs) and turn them into inputs. In short, he sends what he received in the past. The key thing to understand is that you can’t split an input. Incoming transactions are indivisible.
Think of each incoming Bitcoin transaction as a physical coin or banknote. Let's say you have twelve coins in your wallet of $0.1 each. In total you have $1.2. Now imagine you need to pay $0.25 to Alice. You don't have a separate $0.05 coin, though. Can you take one 10-cent coin, break it in two, and give Alice one half of that coin? No – because coins aren't physically divisible.
What you do is give Alice 3 $0.1 coins and receive a 5-cent coin as change. And that's exactly what happens with Bitcoin.
If in the past you received 12 incoming transactions of 0.1 BTC each, you'll have 1.2 BTC in total, but in 12 separate indivisible chunks. So if you want to send 0.25 BTC to Alice, your wallet will take 3 of those transactions for a total of 0.3 BTC. And at the same time, the system will generate a payment of 0.05 BTC and place it back into your wallet as change.
(Actually, there's also a network fee that you add on top of the amount. So in fact you'd have to send something like 0.3001 BTC, and the fee would go to the miners. For more on mining, see the next section.)
How many inputs and outputs would this transaction generate? Well, you used coins from 3 separate transactions, so that's 3 inputs. There's one output for Alice and one for you as change. So it's 2 outputs.
Just to reiterate: you can’t split an input. But even when you send just one input, it usually results in more than one output.
Once you realize that paying with Bitcoin is just like paying with bank notes and coins, it becomes much easier to understand.
One final thing to note is that to make any Bitcoin transactions, you'll need a pair of keys: one public, one private. Both keys consist of numbers and letters. The public key is the address you give to other people so that they can send you BTC. You'd need Alice's public key, for example. The private key is the one you use to sign (authorize) the payment. You have to keep it secret at all times.