Before you can calculate the transaction fee, you must first calculate the transaction
size because the total fee paid increases for transactions with more bytes.
There are two different transaction size formulas used by clients today, the first is the old "bytes" calculator which pre-segwit wallets (or wallets that just don't want to implement segwit) use, whose size is calculated like this:
number of inputs * 146 + number of outputs * 33 + 10 (
source)
The other size formula gives you the size in vbytes (virtual bytes), and this is the measurement unit now used by the bitcoin network, and also wallets that support segwit, instead of "bytes" (more on that later):
number of inputs * 68.5 + number of outputs * 31 + 10 (same source)
Now you might be wondering, what are vbytes? They are related to another tx size unit called Weight. vbytes is just Weight/4. To calculate weight, you count the size of the transaction in normal bytes but you multiply sizes of some parts of the transaction by 4:
(source:
https://learnmeabitcoin.com/technical/transaction-weight)
And as I mentioned earlier you divide the final result by 4 to go from Weight to vbytes.
Why all these complications for finding the transaction size? Well, developers wanted to make transaction sizes smaller so people would pay less overall in fees. The network fee
rate (e.g. 10 sats/byte) did not change with this, just the transaction sizes.
So you will generally see two different units for measuring fee rates: satoshis per byte and satoshis per
vbyte. Using 10 sats/byte and 10 sats/vbyte is functionally equivalent as far as the rate is concerned, but because of the way the transaction sizes are calculated by wallets supporting segwit vs wallets that don't support segwit, using fees in sats/bytes will cause you to pay
more in total fees than if you paid in sats/vbytes. This is a concern because the majority of wallets are paying in sats/vbyte and with a lot of transactions priced like that, you submitting a transaction with a fee in sats/bytes will cause you to overpay, paying more than what other wallets using the same sats/vbyte rate are paying.