user63569: I'm trying to calculate SegWit transaction fees in bytes, I have two Segwit inputs and 2 segwit outputs. can anyone calculate this transaction fees if I'm paying 100 Sat per byte?

user208: That depends on what those inputs and outputs look like.
The formula, as specified in BIP141, is:

Call base_size the number of bytes needed to serialize the transaction in legacy format (which does not include the witnesses).
Call total_size the number of bytes needed to serialize the transaction including witnesses.
The weight of the transaction equals 3*base_size + total_size
The virtual size of the transaction (which is what feerates are usually expressed against) equals weight/4 or 0.75base_size + 0.25total_size.

Some reference numbers:

Outputs:
A P2PKH (1... address) output is 34 vbytes.
A P2SH (3... address) output is 32 vbytes.
A P2WPKH (bc1q... address of length 42) output is 31 vbytes.
A P2WSH (bc1q... address of length 62) output is 43 vbytes.
Inputs:
A P2PKH spend with a compressed public key is 148 vbytes.
A P2WPKH spend is 68 vbytes.
A P2SH-P2WPKH spend is 91 vbytes.


63569: <p>I'm trying to calculate SegWit transaction fees in bytes, I have two Segwit inputs and 2 segwit outputs. can anyone calculate this transaction fees if I'm paying 100 Sat per byte?</p>
 208: <p>That depends on what those inputs and outputs look like.</p>
<p>The formula, as specified in BIP141, is:</p>
<ul>
<li>Call <strong>base_size</strong> the number of bytes needed to serialize the transaction in legacy format (which does not include the witnesses).</li>
<li>Call <strong>total_size</strong> the number of bytes needed to serialize the transaction including witnesses.</li>
<li>The <strong>weight</strong> of the transaction equals <strong>3*base_size + total_size</strong></li>
<li>The <strong>virtual size</strong> of the transaction (which is what feerates are usually expressed against) equals <strong>weight/4</strong> or <strong>0.75<em>base_size + 0.25</em>total_size</strong>.</li>
</ul>
<p>Some reference numbers:</p>
<ul>
<li>Outputs:</li>
<li>A P2PKH (1... address) output is 34 vbytes.</li>
<li>A P2SH (3... address) output is 32 vbytes.</li>
<li>A P2WPKH (bc1q... address of length 42) output is 31 vbytes.</li>
<li>A P2WSH (bc1q... address of length 62) output is 43 vbytes.</li>
<li>Inputs:</li>
<li>A P2PKH spend with a compressed public key is 148 vbytes.</li>
<li>A P2WPKH spend is 68 vbytes.</li>
<li>A P2SH-P2WPKH spend is 91 vbytes.</li>
</ul>
