# What is the way that fee is calculated in post-segwit bitcoin?

In pre-segwit bitcoin, process of calculating transaction fee was easy. Actually everything was based on the fact that the byte has its own value/price (estimated by network) and then fee is obtained as `number_of_bytes * proce_of_single_byte`. So, for example, if the price of one `byte` is 10 sats, then the fee for a transaction of 250 bytes is 2500 sats.

But what about calculating a fee in post-segwit Bitcoin?

In post-Segwit Bitcoin, bytes have a different value/price depending on the type of byte. So, if the byte is segwit then it is worth 4 times less than a non-segwit byte, that is its price is 4 times smaller. The question is: how is the transaction fee calculated in this case?

Is it done by not using `bytes` now, but `vbytes` and then they have a value (price)? And at that, each byte of `non-segwit is one vbyte`, while each byte of `segwit is 0.25 vbyte`? So, for example, if the price of one `vbyte` is 10 sats, then the fee for a transaction of 250 bytes (150 non-segwit, 100 segwit) is (150 * 10 sats) + (100/4 * 10 sats) = 1750 sats. So, in post-segwit bitcoin for calculating transaction fee we use `(number_of_nonsegwit_bytes * price_of_single_vbyte) + (number_of_segwit_bytes / 4 * price_signle_vbyte)`

Is this how software and miners calculate transaction fee?

I'm asking because here `Pieter Wuille` said that `vsize has no meaning except for humans`, while bitcoin uses weight because of integer numbers. If this is true and vbytes are not actually used in softwares for calculating fee, how is the fee then calculated?

• – Murch
Sep 14 at 23:47
• @Murch I saw it, but still not clear to me whether `weight` or `vbyte` are used for calculating fee. In the second answer to the question you left the link for `zono` said the following `Miners consider fee(in satoshi) **per weight** of each transaction in order to maximize their profit.` However, you said the following `The virtual size corresponds to the blockweight which determines the fees`. Pieter Wuille (I linked in question) said that `vsize has no meaning except for humans` and that Bitcoin uses weight because of integer numbers. So what does bitcoin softwares use? Sep 15 at 8:06
• If Pieter Wuille said "Bitcoin uses weight because of integer numbers", I would assume that is what Bitcoin core software uses. Sep 15 at 8:38

So far as I can tell, it doesn't matter whether some software uses vbytes or weight to calculate a fee.

Neither the network nor the blockchain store fee rates. Even fees per transaction are implicit rather than explicit.

I believe some fee related rules such as minimum fee for relaying are node specific and don't affect consensus.

Fee rates are not fixed, each node is free to make its own estimates. Fees are simply a bid in a repeating auction of block space so rounding errors don't matter much.

That auction is conducted by miners who want to maximise revenue while keeping within block size limits. If those size limits are expressed in weight units (WU), that is what I presume miners would be wise to use in calculations.

I don't know of any broader problem that would arise if some software estimates fee rates using floating point arithmetic based on vbytes while other software estimates fee rates using integer arithmetic based on weight.

Related:

Before the activation of segwit, the block was limited to 1,000,000 bytes. This limit got replaced by a blockweight limit of 4,000,000 weight units (WU) with the activation of segwit.

• Yes, the blockweight limit is forward compatible to the blocksize limit. I think it’s easier to sum up integers to 4,000,000 than it is to sum up fractions to 1,000,000, though.
– Murch
Sep 15 at 18:37