<p><strong>TL;DR:</strong><br />
A P2WPKH input should be conservatively estimated with <strong>68.0 vbytes</strong>. Standard P2WPKH inputs generally weigh 67.75 or 68.0 vbytes, depending on whether the r-value in the signature is low or high. A wallet using signature grinding (which is highly recommended) will always produce 67.75 vbyte inputs. 68.0 vbytes is the conservative estimate allowing for high-r signatures.</p>
<h2>Composition of a P2WPKH input</h2>
<p>Each input commits to spending a specific UTXO by providing its <em>transaction outpoint</em>:</p>
<pre><code>PREVOUT: hash (32 bytes)
         index (4 bytes)
</code></pre>
<p>The <em>scriptsig</em> for a P2WPKH input is empty, however, the scriptsig length must be provided as <code>0</code>:</p>
<pre><code>SCRIPTSIG: length (1 byte)
  &lt;no content&gt;
</code></pre>
<p>Each transaction input has its own <em>sequence</em> number:</p>
<pre><code>sequence (4 bytes)
</code></pre>
<p>A P2WPKH input requires a <em>witness stack</em> in the transaction's witness block:</p>
<pre><code>WITNESS STACK: 
item count (1 byte)
  signature length (1 byte)
  signature (71 or 72 bytes)¹
  pubkey length (1 byte)
  pubkey (33 bytes)
</code></pre>
<h2>Conservative weight, vsize, and size estimate</h2>
<p>A P2WPKH transaction input adds to a transactions…</p>
<p><strong>weight:</strong></p>
<pre><code>4 × (32 + 4 + 1 + 4) + 1 + 1 + 72 + 1 + 33 = 272 WU
</code></pre>
<p><strong>vsize:</strong></p>
<pre><code>32 + 4 + 1 + 4 + (1 + 1 + 72 + 1 + 33) / 4 = 68 vbytes
</code></pre>
<p><strong>serialized byte length:</strong></p>
<pre><code>32 + 4 + 1 + 4 + 1 + 1 + 72 + 1 + 33 = 149 bytes
</code></pre>
<p>If the signing wallet uses signature grinding, the r-value is always 32 bytes, reducing the signature to 71 bytes and the above maxima to 271 WU, 67.75 vbytes, and 148 bytes respectively.</p>
<hr />
<p>Note that using at least one segwit input adds <strong>2 witness bytes</strong> to the transaction header, the <em>witness marker</em> and <em>witness flag</em>.  Also, when there is at least one segwit input, the witness block must have a witness stack for <strong>every input</strong>, which must consist of at least a witness item counter indicating that the stack is empty provided as a <code>0x00</code> byte for non-segwit inputs.
The overall transaction elements of a segwit transaction therefore are:</p>
<pre><code>version (4 bytes)
witness marker (1 WU)
witness flag (1 WU)
input count (1 byte)
  inputs (variable size)
output count (1 byte)
  outputs (variable size)
witness stacks (as many as input count)
  witness item count (1 WU)
  witness items (0–n of variable weight)
locktime (4 bytes)
</code></pre>
<p>Mentioned for completeness, a P2WPKH input that has a non-standard signature with both high-s and high-r weighs 273 WU, 68.25 vbytes, and 150 bytes accordingly.</p>
<hr />
<p><sup>¹ also see <a href="https://bitcoin.stackexchange.com/a/77192/5406">What is the maximum size of a DER encoded ECDSA signature?</a>.</sup></p>

CC BY-SA 4.0
2020-11-23T16:57:04.363Z
2021-12-21T19:26:23.507Z
2021-12-21T19:26:23.507Z
Murch
<p>I'm investigating diverging P2WPKH input size calculations on two Bitcoin projects and some blog posts. I'm looking for a detailed explanation of the exact weight, vsize and serialized length of a P2WPKH input, in the same vein as <a href="https://bitcoin.stackexchange.com/q/48279/5406">How big is the input of a P2PKH transaction?</a>.</p>

<transaction-input><p2wpkh><transaction-weight>
What is the size and weight of a P2WPKH input?
Murch
# What is the size and weight of a P2WPKH input?

(Asked by: username_0 on 2020-11-23)

I'm investigating diverging P2WPKH input size calculations on two Bitcoin projects and some blog posts. I'm looking for a detailed explanation of the exact weight, vsize and serialized length of a P2WPKH input, in the same vein as [How big is the input of a P2PKH transaction?](https://bitcoin.stackexchange.com/q/48279/5406).

**Tags:** transaction-input, p2wpkh, transaction-weight


---

## 1 answers

### Answer by username_0 on 2020-11-23. Score: 6 | Accepted answer

**TL;DR:**  
A P2WPKH input should be conservatively estimated with **68.0 vbytes**. Standard P2WPKH inputs generally weigh 67.75 or 68.0 vbytes, depending on whether the r-value in the signature is low or high. A wallet using signature grinding (which is highly recommended) will always produce 67.75 vbyte inputs. 68.0 vbytes is the conservative estimate allowing for high-r signatures.

## Composition of a P2WPKH input

Each input commits to spending a specific UTXO by providing its *transaction outpoint*:

```
PREVOUT: hash (32 bytes)
         index (4 bytes)

```

The *scriptsig* for a P2WPKH input is empty, however, the scriptsig length must be provided as `0`:

```
SCRIPTSIG: length (1 byte)
  <no content>

```

Each transaction input has its own *sequence* number:

```
sequence (4 bytes)

```

A P2WPKH input requires a *witness stack* in the transaction's witness block:

```
WITNESS STACK: 
item count (1 byte)
  signature length (1 byte)
  signature (71 or 72 bytes)¹
  pubkey length (1 byte)
  pubkey (33 bytes)

```

## Conservative weight, vsize, and size estimate

A P2WPKH transaction input adds to a transactions…

**weight:**

```
4 × (32 + 4 + 1 + 4) + 1 + 1 + 72 + 1 + 33 = 272 WU

```

**vsize:**

```
32 + 4 + 1 + 4 + (1 + 1 + 72 + 1 + 33) / 4 = 68 vbytes

```

**serialized byte length:**

```
32 + 4 + 1 + 4 + 1 + 1 + 72 + 1 + 33 = 149 bytes

```

If the signing wallet uses signature grinding, the r-value is always 32 bytes, reducing the signature to 71 bytes and the above maxima to 271 WU, 67.75 vbytes, and 148 bytes respectively.

---

Note that using at least one segwit input adds **2 witness bytes** to the transaction header, the *witness marker* and *witness flag*. Also, when there is at least one segwit input, the witness block must have a witness stack for **every input**, which must consist of at least a witness item counter indicating that the stack is empty provided as a `0x00` byte for non-segwit inputs.
The overall transaction elements of a segwit transaction therefore are:

```
version (4 bytes)
witness marker (1 WU)
witness flag (1 WU)
input count (1 byte)
  inputs (variable size)
output count (1 byte)
  outputs (variable size)
witness stacks (as many as input count)
  witness item count (1 WU)
  witness items (0–n of variable weight)
locktime (4 bytes)

```

Mentioned for completeness, a P2WPKH input that has a non-standard signature with both high-s and high-r weighs 273 WU, 68.25 vbytes, and 150 bytes accordingly.

---

¹ also see [What is the maximum size of a DER encoded ECDSA signature?](https://bitcoin.stackexchange.com/a/77192/5406).


---

