Collin Rukundo

On Bitcoin's transaction fees

A week ago, I made a bitcoin transaction moving some sats to another wallet. My source wallet recommended a fee of 671 sats and while I knew I could update the fee before the transaction is confirmed, I was curious how long until a miner would add it to a block at that low low fee. I had one confirmation in roughly 12 minutes. Total fees paid: $0.21. So did I just move a little over $1000 for 20 cents? In under 15mins? Resisting all censorship? Yes! I wanted to understand transaction fees better, especially how they are estimated so I did some research.

In this article, I dive into Bitcoin transaction fees - specifically what they are, how they are estimated, and why they are important on the Bitcoin blockchain.

For any Bitcoin transaction, the fee is simply the difference between the sum total of the inputs and the sum total of the outputs.

Why include fees?

Every 10 minutes on average, a new block with potentially many transactions is mined and added to the blockchain. Each new block makes previously-confirmed transactions and blocks more secure. More on this in Section 11 of the Bitcoin whitepaper.

The primary reward for miners who successfully mine a block is new bitcoin. This is called the block subsidy and it halves programmatically every 210,000 blocks (or roughly every 4 years) to control supply. This is the only way new bitcoin is created.

The other reward for miners is transaction fees. Each block contains many transactions, each with fees attached to incentivize their confirmation.

The sum of these rewards is known as the block reward. As the block subsidy tends to zero in line with Bitcoin's monetary policy, the block reward will eventually constitute transaction fees only.

How transaction fees are calculated

Transaction fees are a function of the size of the transaction (in bytes, not the value sent) as well as the demand and supply market forces within the Bitcoin network at that time.

On market forces

On the supply side, Bitcoin has a cap on block size at 4 million weight units (WU) that limits the amount of transaction data that can be added to a block. However, Bitcoin's block discovery follows a Poisson distribution meaning that while the difficulty adjustment targets an average of one block every 10 minutes over long periods of time, the time within which blocks arrive over shorter periods of time, is unpredictable.

A new block may arrive in less than a second or more than 30 minutes after the previous block. It is important to understand that the waiting time between blocks is always 10 minutes. If you make a Bitcoin transaction now and check your node's log to find the previous block was mined 8 minutes ago, you are still expected to wait 10 minutes on average before the next block appears because mining is a memoryless process.

Regardless of when a new block is discovered, and since block size is limited, all the high fee transactions are drained out of the mempool first. Naturally, miners will prioritize transactions with high fee rates. I'll come back to this later on.

On the demand side, you have different users, each with their unique preferences. Some are willing to pay high fees on their transactions for faster confirmation while others are okay with waiting longer periods. More transactions also typically take place during business days. Furthermore, changes in bitcoin price can affect the level of congestion on the network as demand fluctuates.

On size of the transaction

Transaction size is usually calculated in virtual bytes (vB). Larger transactions take up more space in the block so it follows that they typically pay fees on a per-byte basis. Most wallets show users a fee rate which is calculated in satoshis per unit of data your transaction will consume on the blockchain and abbreviated as sats/vByte. The total fee paid by your transaction is then determined by multiplying the fee rate by the size of your transaction.

Analysing the size of “normal” transactions

All non-segwit transactions contain the following fields:

Field Size
Version 4 bytes
# of inputs 1 byte for up to 252 inputs
# of outputs 1 byte for up to 252 outputs
Outputs variable
Locktime 4 bytes

For each input, we find the following fields:

Field Size
Ref transaction hash 32 bytes
Ref Output index 4 bytes
Unlocking Script Length 1 byte for a scriptSig up to 252 bytes.
ScriptSig variable
Sequence 4 bytes

For each output, we find the following fields:

Field Size
Value/amount 8 bytes
Locking Script Length 1 byte for numbers 1 to 252
ScriptPubKey variable

For non-segwit transactions, each byte of data counts for 4 Weight Units.

So, let’s look at this non-segwit transaction as an example.

Here’s the transaction hex:


If we decode the hex, we get:

Data Detail Raw bytes Multiplier Total WU Cumulative total
01000000 Version 1 4 4x 16 16
01 # of inputs (1) 1 4x 4 20
c8 ... 3a Ref output hash 32 4x 128 148
05000000 Ref output index 4 4x 16 164
fc Script length 1 4x 4 168 P2SH Script 252 4x 1008 1176
ffffffff Sequence 4 4x 16 1192
02 # of outputs (2) 1 4x 4 1196
80a2190000000000 Value for output #1 8 4x 32 1228
22 Script length for output #1 1 4x 4 1232
002...76ce P2WSH Script for output #1 36 4x 144 1376
0500000000002200 Value for output #2 8 4x 32 1408
20 Script length for output #2 1 4x 4 1412
212...048 P2WSH Script for output #2 32 4x 128 1540
00000000 Locktime(0) 4 4x 16 1556

The total size of the transaction is 1556 Weight Units. We can divide this by 4 to get the transaction size in virtual bytes which is 389vB.

Analysis: With the total input of 0.02118974 BTC and a combined output of 0.02060534, the total fees paid for this transaction is 0.0005844 BTC or 58,440 sats. From that, we can deduce the fee rate as 150 sats/vB. Given that this is a non-segwit transaction, the transaction size could have been smaller, therefore, requiring less fees.

Before segwit, each block was limited to 1MB of data. Segwit's activation introduced a block size limit increase to a realistic 2MB or 4MB theoretically, depending on the types of transactions in the block. Since block weight is calculated in weight units, and one byte of a transaction's non-witness data is worth 4 weight units while one byte of witness data is worth 1 weight unit, it is critical to understand that if a block contains only non-segwit transactions, the 4 million weight unit limit will be equivalent to the old 1MB limit.

Analysing the size of segwit transactions

Segwit transactions include extra fields like segwit marker, segwit flag, and Witness Data. All segwit data only counts for 1 WU for each byte of data which is why transaction size is smaller.

Let's dissect a segwit transaction. Here's the transaction hex:


If we decode the hex, we get the following data:

Data Detail Raw bytes Multiplier Total WU Cumulative total
02000000 Version 2 4 4x 16 16
00 segwit marker 1 1x 1 17
01 segwit flag 1 1x 1 18
01 # of inputs (1) 1 4x 4 22
cab ... 2cf Ref output hash 32 4x 128 150
14000000 Ref output index 4 4x 16 166
fd Script length 1 4x 4 170
00 (empty) P2WPKH Script 0 4x 0 0
fdffffff Sequence 4 4x 16 186
02 # of outputs (2) 1 4x 4 190
6406010000000000 Value for output #1 8 4x 32 222
16 Script length for output #1 1 4x 4 226
001...40f P2SH Script for output #1 22 4x 88 314
60361e0000000000 Value for output #2 8 4x 32 346
17 Script length for output #2 1 4x 4 350
a91...587 P2WSH Script for output #2 23 4x 92 442
0247 ... 4976 Witness Data 107 1x 107 549
2b550900 Locktime(0) 4 4x 16 565

The total size of this transaction is 565 WU or 142vB. If we review the transaction again, you can see that the total input is 0.02118172 BTC and the combined output value is 0.02047172 BTC. The fee paid therefore is 0.00071 BTC or 71,000 sats. We can deduce that the fee rate is 500 sats/vB. This is quite expensive. However, we can also see that the transaction opted into Replace By Fee (RBF) - BIP125 so it is possible the user bumped the fees to get the transaction mined into a block faster.

On Fee Rate

Miners will prioritise transactions with high fee rates rather than fees. The difference is crucial, because a large transaction (in terms of WU) could have a massive fee, but still have a lower fee rate than a load of smaller sized transactions. In this case, the miner would fill the block with many smaller, high fee-rate transactions.


The variations in demand and supply established a dynamic fee market which introduced fee estimation algorithms making it possible for users to make trade-offs between confirmation time and transaction cost. The algorithms make recommendations for how much fees are necessary to get a specific transaction of predetermined size confirmed in the shortest possible time, while taking into consideration prevailing market conditions. However, this attempt to predict the future is not without its shortcomings.


Thoughts? Leave a comment