Appendices Appendix B

Transaction Size Calculator

A transaction's weight is base_size \(\times\) 3 + total_size.BIP 141

Fee estimation requires knowing a transaction's virtual size (vsize) before broadcasting. This appendix provides closed-form formulas for every transaction type covered in this book. All formulas assume compressed public keys (33 bytes) and standard DER-encoded ECDSA signatures (72 bytes average, 73 bytes worst case) or 64-byte Schnorr signatures where applicable. The interactive calculator below applies them to any input/output mix.

The Calculator

Stripped size
Total size
Weight
vsize
Fee

B.1Core Formulas

Weight and Virtual Size

For any transaction with stripped size \(S\) (serialization without witness data) and total size \(T\) (full serialization including witness):

\[ \text{Weight} = S \times 3 + T \]

\[ \text{vsize} = \left\lceil \frac{\text{Weight}}{4} \right\rceil \]

For legacy transactions (no witness), \(S = T\) and \(Weight = 4T\), so \(vsize = T\).

B.2Legacy Transactions

B.2.1P2PKH (\(n\) Inputs, \(m\) Outputs)

ComponentFormulaTypical (1-in, 2-out)
Overhead\(10\) bytes10
Per input\(148\) bytes148
Per output\(34\) bytes68
Total\(10 + 148n + 34m\)226 bytes = 226 vB

B.2.2P2SH 2-of-3 Multisig (\(n\) Inputs, \(m\) Outputs)

ComponentFormulaTypical (1-in, 2-out)
Overhead\(10\) bytes10
Per input\(297\) bytes297
Per output\(34\) bytes68
Total\(10 + 297n + 34m\)375 bytes = 375 vB

B.3SegWit Transactions

B.3.1P2WPKH (\(n\) Inputs, \(m\) Outputs)

ComponentFormulaTypical (1-in, 2-out)
Overhead (non-witness)\(10\) bytes10
Marker + flag\(2\) bytes2
Per input (non-witness)\(41\) bytes41
Per output\(31\) bytes62
Per input (witness)\(108\) bytes108
Stripped size \(S\)\(10 + 41n + 31m\)113
Total size \(T\)\(S + 2 + 108n\)223
Weight\(S \times 3 + T\)\(339 + 223 = 562\)
vsize\(W/4\)\(\lceil 562/4 \rceil = \textbf{141}\) vB
Witness Size Range

The witness for a P2WPKH input ranges from 107 to 109 bytes depending on whether the DER-encoded \(r\) and \(s\) values require high-bit padding. The 72-byte average signature gives 108 bytes. The Chapter 9 specimen (block 600,000) has a 71-byte signature (no padding on either \(r\) or \(s\)), yielding a 107-byte witness—but the 1-in-2-out vsize rounds to 141 vB in both cases.

B.3.2P2WSH 2-of-3 Multisig (\(n\) Inputs, \(m\) Outputs)

ComponentFormulaTypical (1-in, 2-out)
Stripped size \(S\)\(10 + 41n + 43m\)137
Total size \(T\)\(S + 2 + 254n\)393
Weight\(S \times 3 + T\)\(411 + 393 = 804\)
vsize\(W/4\)\(\lceil 804/4 \rceil = \textbf{201}\) vB

B.3.3P2TR Key Path (\(n\) Inputs, \(m\) Outputs)

ComponentFormulaTypical (1-in, 2-out)
Stripped size \(S\)\(10 + 41n + 43m\)137
Total size \(T\)\(S + 2 + 66n\)205
Weight\(S \times 3 + T\)\(411 + 205 = 616\)
vsize\(W/4\)\(\lceil 616/4 \rceil = \textbf{154}\) vB

B.4Wrapped SegWit

B.4.1P2SH-P2WPKH (\(n\) Inputs, \(m\) Outputs)

ComponentFormulaTypical (1-in, 2-out)
Stripped size \(S\)\(10 + 64n + 34m\)142
Total size \(T\)\(S + 2 + 108n\)252
Weight\(S \times 3 + T\)\(426 + 252 = 678\)
vsize\(W/4\)\(\lceil 678/4 \rceil = \textbf{170}\) vB

B.5Comparative Summary

The following table compares the standard 1-input, 2-output transaction across all types:

TypeStrippedTotalWeightvsizeSavings vs. P2PKH
P2PKH (legacy)226226904226
P2SH 2-of-33753751500375
P2SH-P2WPKH (wrapped)14225267817024.8%
P2WPKH (native SegWit)11322356214137.6%
P2WSH 2-of-3137393804201(vs. P2SH: 46.4%)
P2TR (key path)13720561615431.9%
Fee Estimation Quick Rule

For a transaction with \(n\) inputs and \(m\) outputs at feerate \(r\) sat/vB: \[ \text{Fee} = r \times \text{vsize}(n, m) \text{ sats} \] At 10 sat/vB, a P2WPKH 1-in-2-out transaction costs \(10 \times 141 = 1,410\) sats (\(\approx\) $1.41 at $100k/BTC). A P2TR key-path spend costs \(10 \times 154 = 1,540\) sats—about 9% more, the price of Taproot's larger 43-byte outputs (vs. 31 bytes for P2WPKH).

← Appendix A Appendix C →