<p>AFAIK there are 5 different standard non-SegWit transaction types, and 4 SegWit ones.</p>

<p>Non-SegWit:</p>

<p><strong>Pay to public key (P2PK)</strong></p>

<pre><code>PUSH (1 byte) + &lt;compressed/uncompressed_pk&gt; (33/65 bytes) + OP_CHECKSIG (1 byte)
</code></pre>

<p><strong>Pay to public key hash (P2PKH)</strong></p>

<pre><code>OP_DUP (1 byte) + OP_HASH160 (1 byte) + PUSH (1 byte) + &lt;hash_160(PK)&gt; (20 bytes) + OP_EQUALVERIFY (1 byte) + OP_CHECKSIG (1 byte)
</code></pre>

<p><strong>Multisig (P2MS)</strong></p>

<pre><code>&lt;number_of_PKs&gt; (1 byte) PUSH (1 byte) &lt;PK_0&gt; (33/65 bytes) PUSH (1 byte) &lt;PK_1&gt; (33/65 bytes)  ... PUSH (1 byte) &lt;PK_n-1&gt; (33/65 bytes) OP_CHECKMULTISIG (1 byte)
</code></pre>

<p>P2MS allow up to 15-15 scripts, however only up to 3-3 are standard. </p>

<p><strong>Pay to script hash (P2SH)</strong></p>

<pre><code>OP_HASH160 (1 byte) + PUSH (1 byte) + &lt;hash160(redeem_script)&gt; (20 bytes) + OP_EQUAL (1 byte)
</code></pre>

<p><strong>OP_Return</strong></p>

<pre><code>OP_RETURN (1 byte) PUSH (1 byte) &lt;0 to 83 bytes of data&gt;
</code></pre>

<p>SegWit:</p>

<p>Regarding segwit types, there are two non-native and two native ones.</p>

<p><strong>Native Pay to witness public key hash (P2WPKH)</strong></p>

<pre><code>OP_0 (1 byte) PUSH (1 byte) &lt;hash 160(PK*)&gt; (20 bytes)
</code></pre>

<p><strong>Native Pay to witness script hash (P2WSH)</strong></p>

<pre><code>OP_0 (1 byte) PUSH (1 byte) &lt;script_hash&gt; (32 bytes)
</code></pre>

<p><strong>Pay to witness public key hash encapsulated in a pay to script hash (P2SH-P2WPKH)</strong></p>

<p>The redeem script follows the same structure than native P2WPKH:</p>

<p><code>redeem_script = OP_0 (1 byte) PUSH (1 byte) &lt;hash_160(PK*)&gt; (20 bytes)</code></p>

<p>While the external structure of the script (<code>scriptPubKey</code>) is as any other P2SH:</p>

<pre><code>OP_HASH160 (1 byte) + PUSH (1 byte) + &lt;hash_160(redeeem_script)&gt; (20 bytes) + OP_EQUAL (1 byte)
</code></pre>

<p><strong>Pay to witness script hash encapsulated in a pay to script hash (P2SH-P2WSH)</strong></p>

<p>The redeem script follows the same structure than native P2WSH:</p>

<p><code>redeem_script = OP_0 (1 byte) PUSH (1 byte) &lt;script_hash&gt; (32 bytes)</code></p>

<p>While the external structure of the script (<code>scriptPubKey</code>) is as any other P2SH:</p>

<pre><code>OP_HASH160 (1 byte) + PUSH (1 byte) + &lt;hash_160(redeeem_script)&gt; (20 bytes) + OP_EQUAL (1 byte)
</code></pre>

<p>*In P2WPKH scripts the hash 160 should correspond to a compressed public key, otherwise the funds will be lost.</p>

CC BY-SA 3.0
2018-04-11T16:42:03.150Z
Thank you. But I do not understand your last sentence: "Non-native pay to witness script hash encapsulated in a pay to script hash (P2SH-P2WPKH) have the same structure." Can you elaborate on that? As far as I understood, non-native segwit outputs are indistinguishable from P2SH-outputs.
Thorkil Værge
CC BY-SA 3.0
2018-04-11T19:43:04.477Z
What I ment is that in P2SH-P2WPKH the redeem script follows the structure of the native P2WPKH and in the P2SH-P2WSH the redeem script follows the structure of the native P2WSH. I'll edit it for clarification.
sr_gi
CC BY-SA 3.0
2018-04-20T09:36:09.467Z
Reviewing the answer I realized that the OP_Return script was not up to date. The max amount of data to be pushed is 83 bytes since Bitcoin Core 0.12. I've updated the answer to correct it.
sr_gi
CC BY-SA 4.0
2021-07-21T08:33:21.957Z
Could this answer be updated with P2TR outputs?
Thorkil Værge
CC BY-SA 4.0
2018-04-11T16:02:07.580Z
2018-09-27T17:03:19.230Z
2018-09-27T17:03:19.230Z
sr_gi
<p>A transaction output can have the type</p>

<ul>
<li><p>Pay to public key hash, P2PKH, where the ScriptPubKey field has the format:</p>

<p>76 a9 14 &lt;20-byte hash of pubkey> 88 ac</p></li>
<li><p>Pay to script hash, P2SH, used for e.g. multisig:</p>

<p>a9 14 &lt;20-byte hash of script> 87</p></li>
</ul>

<p>There is also something called P2WPKH and P2WSH. Can you show me how these outputs are formatted, and are there any more possible output formats than these four?</p>

CC BY-SA 3.0
2018-04-11T13:29:30.497Z
the SegWit formats: https://en.bitcoin.it/wiki/Segregated_Witness, or here: https://bitcoincore.org/en/segwit_wallet_dev/. And then there was in early times "pay to public key", and the old "multisig" types (non-P2SH). Not sure if they are still valid today.
pebwindkraft
CC BY-SA 3.0
2018-04-11T13:48:34.787Z
I didn't know the pay to public key format. Interesting! I had heard about the "multisig" type but never encountered it or a description of it.
Thorkil Værge
CC BY-SA 3.0
2018-04-11T15:32:16.720Z
I think it was called bare multisig. And was BIP0011. A quick search in the forum: https://bitcoin.stackexchange.com/questions/29708/multi-signature-and-pay-to-script-hash-vs-pay-to-pub-key-hash/29819#29819
pebwindkraft
<segregated-witness><utxo><transaction-input><output><standard>
What are the standard formats of transaction outputs?
Thorkil Værge
# What are the standard formats of transaction outputs?

(Asked by: username_0 on 2018-04-11)

A transaction output can have the type

* Pay to public key hash, P2PKH, where the ScriptPubKey field has the format:

  76 a9 14 <20-byte hash of pubkey> 88 ac
* Pay to script hash, P2SH, used for e.g. multisig:

  a9 14 <20-byte hash of script> 87

There is also something called P2WPKH and P2WSH. Can you show me how these outputs are formatted, and are there any more possible output formats than these four?

**Tags:** segregated-witness, utxo, transaction-input, output, standard

> **Comments:**
> **username_1**: the SegWit formats: https://en.bitcoin.it/wiki/Segregated_Witness, or here: https://bitcoincore.org/en/segwit_wallet_dev/. And then there was in early times "pay to public key", and the old "multisig" types (non-P2SH). Not sure if they are still valid today.  
> **username_0**: I didn't know the pay to public key format. Interesting! I had heard about the "multisig" type but never encountered it or a description of it.  
> **username_1**: I think it was called bare multisig. And was BIP0011. A quick search in the forum: https://bitcoin.stackexchange.com/questions/29708/multi-signature-and-pay-to-script-hash-vs-pay-to-pub-key-hash/29819#29819  

---

## 1 answers

### Answer by username_2 on 2018-04-11. Score: 6 | Accepted answer

AFAIK there are 5 different standard non-SegWit transaction types, and 4 SegWit ones.
Non-SegWit:
Pay to public key (P2PK)
PUSH (1 byte) +  (33/65 bytes) + OP_CHECKSIG (1 byte)

Pay to public key hash (P2PKH)
OP_DUP (1 byte) + OP_HASH160 (1 byte) + PUSH (1 byte) +  (20 bytes) + OP_EQUALVERIFY (1 byte) + OP_CHECKSIG (1 byte)

Multisig (P2MS)
 (1 byte) PUSH (1 byte)  (33/65 bytes) PUSH (1 byte)  (33/65 bytes)  ... PUSH (1 byte)  (33/65 bytes) OP_CHECKMULTISIG (1 byte)

P2MS allow up to 15-15 scripts, however only up to 3-3 are standard. 
Pay to script hash (P2SH)
OP_HASH160 (1 byte) + PUSH (1 byte) +  (20 bytes) + OP_EQUAL (1 byte)

OP_Return
OP_RETURN (1 byte) PUSH (1 byte) <0 to 83 bytes of data>

SegWit:
Regarding segwit types, there are two non-native and two native ones.
Native Pay to witness public key hash (P2WPKH)
OP_0 (1 byte) PUSH (1 byte)  (20 bytes)

Native Pay to witness script hash (P2WSH)
OP_0 (1 byte) PUSH (1 byte)  (32 bytes)

Pay to witness public key hash encapsulated in a pay to script hash (P2SH-P2WPKH)
The redeem script follows the same structure than native P2WPKH:
redeem_script = OP_0 (1 byte) PUSH (1 byte)  (20 bytes)
While the external structure of the script (scriptPubKey) is as any other P2SH:
OP_HASH160 (1 byte) + PUSH (1 byte) +  (20 bytes) + OP_EQUAL (1 byte)

Pay to witness script hash encapsulated in a pay to script hash (P2SH-P2WSH)
The redeem script follows the same structure than native P2WSH:
redeem_script = OP_0 (1 byte) PUSH (1 byte)  (32 bytes)
While the external structure of the script (scriptPubKey) is as any other P2SH:
OP_HASH160 (1 byte) + PUSH (1 byte) +  (20 bytes) + OP_EQUAL (1 byte)

*In P2WPKH scripts the hash 160 should correspond to a compressed public key, otherwise the funds will be lost.

> **Comments:**
> **username_0**: Thank you. But I do not understand your last sentence: "Non-native pay to witness script hash encapsulated in a pay to script hash (P2SH-P2WPKH) have the same structure." Can you elaborate on that? As far as I understood, non-native segwit outputs are indistinguishable from P2SH-outputs.  
> **username_2**: What I ment is that in P2SH-P2WPKH the redeem script follows the structure of the native P2WPKH and in the P2SH-P2WSH the redeem script follows the structure of the native P2WSH. I'll edit it for clarification.  
> **username_2**: Reviewing the answer I realized that the OP_Return script was not up to date. The max amount of data to be pushed is 83 bytes since Bitcoin Core 0.12. I've updated the answer to correct it.  
> **username_0**: Could this answer be updated with P2TR outputs?  

---

