2

I am reading the book Mastering Bitcoins 2nd Edition by O'Reilly, and it says:

Alice buys a coffee from Bob's Cafe for $1.50, or 0.015 Bitcoin

So Alice pays 0.015 Bitcoin, and Bob gets 0.015 Bitcoin, but there is a transaction fee, paid to the miner.

There are some questions:

  1. Does Alice pay more or does Bob get less? (the fee has to come from somebody)
  2. The way to calculate the fee seems to be a whole essay. Typically, what kind of percentage can the fee be, if it is a $1.5 coffee, or if somebody sends another person US$1 million dollar worth of Bitcoin, or if it is exchanging Bitcoin for US$1 million? But one person mentioned that it is voluntary (even the link above said the spender "may" include a fee, suggesting they can choose not to), but who would want to pay a fee if they don't have to? I can understand if they send over US$1 million and the fee is $13, then they probably don't mind and "want" to include a fee.
  3. The miner gets the fee -- is that the miner who originally did the mining of the coin, or is it that somehow, the fee (or transaction) gets encrypted and a new miner has to mine it. It is described as: all the miners compete to find the next new Bitcoin, but there is also Proof of Work (to get a fraction of Bitcoin), but there is no mentioning of the miner getting a transaction fee. How does it factor into the flow or procedure?

3 Answers 3

3

Does Alice pay more or does Bob get less? (the fee has to come from somebody)

Alice pays more.

It works like this: Alice submits a transaction with inputs adding up to, for example, 0.016 BTC. This transaction includes outputs totaling 0.015 BTC to Bob. The difference, in this example 0.001 BTC, would be the transaction fee in this case.

The way to calculate the fee

The fee of Bitcoin transactions is calculated on the size of the transaction, not the value being transacted. For each byte of your transaction, you are bidding a certain number of satoshi, known as the "fee rate" -- so for example, if you chose a 100 sat/byte fee rate, and your transaction is 600 bytes, then your transaction fee would be 600*100=60000 sat (0.0006 BTC).

You are bidding for space in a block. Because only a certain amount of transactions can go into each block, most miners will select the transactions with the highest satoshi per byte fee rate, because it is more profitable for them to collect these fees.

Technically you could choose a 0 sat/byte fee rate, making your transaction free of fees, but nowadays miners will probably not include your transaction in a block because they'd be losing money (and nodes will probably not propagate it), so your transaction will never confirm. However, it's still a valid transaction, and indeed, earlier in Bitcoin's history when transaction volume was much lower and block space wasn't so competitive, most transactions included 0 fees.

I can understand if they send over US$1 million and the fee is $13, then they probably don't mind and "want" to include a fee.

The price of the transaction is completely irrelevant to the fees. Since it's by the size of your transaction... if your $10 USD transaction is very complicated and results in a large transaction, you may end up paying a hilariously large fee to have it confirmed. By contrast, if your $1M transaction is very simple and the transaction is very small, then the fees for that transaction will be low, despite it being a high value transaction.

The miner gets the fee -- is that the miner who originally did the mining of the coin, or is it that somehow, the fee (or transaction) gets encrypted and a new miner has to mine it. It is described as: all the miners compete to find the next new Bitcoin, but there is also Proof of Work (to get a fraction of Bitcoin), but there is no mentioning of the miner getting a transaction fee. How does it factor into the flow or procedure?

The miner who mines the block that first includes your transaction gets your transaction fee. Let's say your transaction was included in block #123. The miner who mined block #123 receives your transaction fee.

3
  • Good answer. It would be great if you distinguished "fee" and "feerate", it's often a source of confusion when people talk about feerates but call it the fee, just like the absolute fee. Also note that most nodes run with the default minRelayTxFeeRate of 1 sat/vB, so they'll not add any transactions with feerates below that to their mempool and corollary also not relay it. If you wanted to pay less, you'd likely have to find a miner that accepts that and submit to them directly.
    – Murch
    Commented Jan 26, 2021 at 16:30
  • @Prayank why edit it? that sentence is relevant to the answer.
    – ieatpizza
    Commented Jan 26, 2021 at 17:48
  • The question is about "Bitcoin transaction fees". There was no need to mention altcoins in it in my opinion. The way it was mentioned looked wrong. Also if at all you need to suggest low few options in answer there are layer 2 options in Bitcoin.
    – user103136
    Commented Jan 26, 2021 at 17:55
1

I found out more and wanted to post what I found out:

  1. The sender pays the fee

  2. The sender can choose how much fees to pay, but if the fee is low, then the transaction can sit there for a while before it can go through (nobody wants to process it), meaning that it can be 5 minutes or up to 72 hours or more. So for this reason, it seems you wouldn't want to buy a coffee and add a fee, when you can use a credit card and earn 2% cash instead. Also, I think nobody would like to buy a coffee and wait at the cash register for 5 or 10 minutes before they can finally drink the coffee.

  3. The miner mines Bitcoin, and they can also process the transaction. If that transaction involved a lot of misc Bitcoin pieces, it will be bigger data size. The size means it will occupy their block, so they would like to process all the transaction with little data, but higher fee first. Some wallets are said to automatically estimate what fee to pay so that your transaction can go through fast.

1

How is the fee specified?

The transaction fee is paid by the sender.

Bitcoin transactions consist of three parts. The inputs specify which unspent transaction outputs (UTXOs) get consumed and satisfy the corresponding locking scripts, the outputs define which new UTXOs are created by the transaction per amounts and addresses, and the header keeps track of metadata like the version field, the locktime, the input and output counts.

The transaction fee is only specified implicitly, by the difference of the input amounts and output amounts:

transaction fee = Σ(inputs) – Σ(outputs)

How do miners collect fees?

When a miner finds a valid block, they pay themselves the block reward. The block reward consists of the block subsidy (new coins), and the fees of the transactions included in the block.
When Bitcoin users submit transactions, the nodes on the network relay the transactions and collect them in their mempools, their queue of unconfirmed transactions. Miners select transactions for their block templates from their nodes' mempools. A block is limited to 4,000,000 weight units, which translates to about 2,500 to 4,000 transactions, depending on the transactions' weights. Given the limit, miners prefer transactions higher feerates (fee per weight), since that will yield the greatest block reward.

How do users pick fees to get confirmed?

When users send transactions, they must consider how urgently they want their transactions to be confirmed. Depending on their choice, their wallet software estimates a feerate. As their wallet software picks a set of inputs to fund the transaction, the wallet keeps track of the weight the inputs and outputs will incur, and allocates the absolute fee that results in the targeted feerate. As the transaction then queues, this fee functions as a bid for the necessary blockspace to include the transaction.

You may have noticed that the fee is not related to the payment's value at all. A transaction with one input and one output will cost the same whether you send $10 or $10M. The fee is purely a function of the weight of the transaction and the urgency of the user. This results in larger payments having a lower relative cost and Bitcoin's base layer being poorly suited for micropayments. The slow confirmations, high cost for micropayments, and scalability concerns provide some of the motivations for the development of the Lightning Network, a second-layer instant payment system on-top of Bitcoin's base layer.

A main challenge for feerate estimation is that it's unpredictable when the next block will be found and how many transactions will get queued until then. The probabilistic nature of mining and varying demand causes interesting dynamics for the global transaction queue. Some of these problems can be sidestepped by issuing replaceable transactions which can be reprioritized by overwriting them with transactions of bidding a higher fee. Note that most nodes will not relay transactions sent with feerates of less than 1 sat/vB.

3
  • so 1 Bitcoin is many many blocks? Finding a block is the same time every year, but just that every 4 years, the number of blocks double? Commented Jan 26, 2021 at 19:27
  • I am also just interested in the range of percentage of fees... can it be 10%, 15%, 3% when you buy a coffee or when you send or sell $1 million worth of BTC? Commented Jan 26, 2021 at 19:53
  • 1
    I'm not sure I understand what you mean with "1 Bitcoin is many many blocks". Blocks are found about every ten minutes, and every new block creates 6.25 fresh bitcoins at this time. Beyond that, each "piece" of bitcoin is tracked as a uniquely identifiable UTXO. I'll amend my text to address your question about relative fees.
    – Murch
    Commented Jan 26, 2021 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.