I'm very, very interested in one thing. I have already asked that and nobody gave me a distinct answer: how do transaction fees and mining correlate? Why is everyone saying that fees go to reward miners? Mining is a process of supporting and simultaneous generation of Bitcoins. Where on earth did fees appear in this scheme?
Who pays them and to whom exactly? And how they decide who deserves most?
Please answer me, because everyone who is talking about that is like implying this is something obvious.
A transaction has inputs (formerly received coins you now use) and outputs (coins you send to someone else or yourself). The fee is the sum of all inputs minus the sum of all outputs.
Let assume you have 1 BTC you received via 2 transactions for 0.5. You want to send 0.9 to Alice and pay a 0.01 BTC fee.
You would use both your inputs, create one output for 0.9 to alice's address and one output for 0.09 for one of your change addresses.
Sum of inputs = 0.5 + 0.5
Sum of outputs = 0.9 + 0.09
inputs - outputs = 0.01 (the fee you pay)
When your transaction is confirmed the "missing" 0.01 btc becomes available in the coinbase transaction for the miner (or pool) that found that block which includes your transaction into the blockchain. Miners can not cheat here, because it would make the block invalid and you cant cheat because it would make your transaction invalid.
Edit: changed the fee to 0.01 because I constantly messed up the number of 0's