Bitcoin SegWit Weight and Virtual Size: Exact Fee Calculation
Bitcoin transaction fees are paid in satoshis, but fee rates are commonly quoted in sat/vB. SegWit introduced weight units so witness bytes count less toward the block weight limit than non-witness bytes.
The consensus weight formula
Transaction weight = stripped size × 4 + witness size, where witness size is total serialized size minus stripped serialized size. Equivalently, weight = stripped size × 3 + total size. Stripped size is the serialized transaction without marker, flag, or witness data; total size includes them when witness serialization is used.
Virtual size (vsize) = ceiling(weight / 4). Virtual size is an integer number of virtual bytes. The ceiling is important: 561 weight units correspond to 141 vB, not 140.25 vB for fee-rate calculations using integer vsize.
Worked example
Suppose a transaction has a stripped size of 120 bytes and a total size of 230 bytes. Its witness size is 110 bytes. Weight is (120 × 4) + 110 = 590 WU; vsize is ceiling(590 / 4) = 148 vB. At a target fee rate of 5 sat/vB, a fee of 740 sat corresponds to that vsize.
Actual wallet construction must account for the final input types, witness signatures, script paths, change outputs, and any size variation before broadcasting. A target fee rate is not a guarantee of inclusion in the next block.
Block weight versus transaction fee
The SegWit consensus maximum block weight is 4,000,000 WU. A fee rate is a transaction or package selection metric, not a consensus rule requiring a fixed fee. Miners and nodes apply their own policies when selecting and relaying transactions.
Common pitfalls
Do not confuse raw byte length with vsize. Do not multiply every witness byte by four. Do not assume a Taproot script-path spend has the same weight as a key-path spend. Do not round weight down when calculating vsize.
Primary references
Bitcoin Developer Reference — Transactions: https://developer.bitcoin.org/reference/transactions.html
BIP141 — Segregated Witness: https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki
BIP144 — Segregated Witness Peer Services: https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki
