<p>The <a href="https://en.bitcoin.it/wiki/List_of_address_prefixes" rel="nofollow noreferrer">address prefix</a> determines how a wallet will <strong><em>interperet</em></strong> the address. Let's look at an example.</p>

<h2>Generate a P2PKH address</h2>

<ol>
<li><p>Take a public key, e.g. <code>023cba1f4d12d1ce0bced725373769b2262c6daa97be6a0588cfec8ce1a5f0bd09</code></p></li>
<li><p>Apply <code>HASH160</code>: <code>3a38d44d6a0c8d0bb84e0232cc632b7e48c72e0e</code></p></li>
<li><p>Prepend the version prefix for <code>P2PKH</code> (<code>0x00</code>): <code>003a38d44d6a0c8d0bb84e0232cc632b7e48c72e0e</code></p></li>
<li><p>Base58Check encode it: <code>16JrGhLx5bcBSA34kew9V6Mufa4aXhFe9X</code></p></li>
</ol>

<p>See <a href="https://medium.com/coinmonks/how-to-generate-a-bitcoin-address-step-by-step-9d7fcbf1ad0b" rel="nofollow noreferrer">How to Generate a Bitcoin Address — Step by Step</a> for command line steps.</p>

<h2>Prefixes</h2>

<p>Bitcoin has 2 main <a href="https://en.bitcoin.it/wiki/List_of_address_prefixes" rel="nofollow noreferrer">address prefixes</a> (mainnet):</p>

<p><strong>P2PKH</strong> (Pay to Public Key Hash): <code>1</code><br>
<strong>e.g.</strong>: <code>17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem</code></p>

<p><strong>P2SH</strong> (Pay to Script Hash): <code>3</code><br>
<strong>e.g.</strong>: <code>3EktnHQD7RiAE6uzMj2ZifT9YgRrkSgzQX</code></p>

<p>Addresses are just representations of the information necessary (<code>scriptPubKey</code>) to create a <a href="https://en.bitcoin.it/wiki/Transaction#Output" rel="nofollow noreferrer">transaction output</a>, which is part of the <a href="https://en.bitcoin.it/wiki/Transaction" rel="nofollow noreferrer">transaction</a> and which is validated and stored on the network. It is only used by wallet application software, addresses are not stored on the Blockchain in this format.</p>

<p>The wallet will determine, based on the address prefix, when it is decoded, how to construct this <code>scriptPubkey</code>. For <code>P2PKH</code> this would be in this form:</p>

<p><code>OP_DUP OP_HASH160 &lt;pubKeyHash&gt; OP_EQUALVERIFY OP_CHECKSIG</code></p>

<p>Where you will notice, the only info it needs is the <code>pubKeyHash</code> which is contained in the decoded address (step 2 above). However, the format for a <code>P2SH</code> <code>scriptPubkey</code> is <code>OP_HASH160 &lt;scriptHash&gt; OP_EQUAL</code>. If you used the wrong prefix, the wallet would create the wrong script and a tx will most likely burn those coins because no one will be able to guess keys/scripts that will successfully satisfy the <code>scriptPubkey</code>.</p>

CC BY-SA 4.0
2018-09-15T11:53:11.390Z
Thank you so much for the explanation. As you said "It is only used by wallet application software, addresses are not stored on the Blockchain in this format."  would you please show me what format address stored on the Blockchain? Using blockchain.info we can see the address prefix of 1, 3, bc1, where are they came?
yrm23
CC BY-SA 4.0
2018-09-15T04:57:13.180Z
2018-09-15T05:03:21.957Z
2018-09-15T05:03:21.957Z
JBaczuk
<p>In this post <a href="https://bitcoin.stackexchange.com/questions/67875/does-the-version-prefix-of-an-address-force-the-type-of-transactions-the-address">Does the version prefix of an address force the type of transactions the address may treat?</a>, I saw "the version byte doesn't actually appear in the final transaction."<br>
I don't understand why? Could anyone can help to tell more detail about that? </p>

<address><bitcoin-core-development>
Anyone could teach me more detail about version prefix
yrm23
# Anyone could teach me more detail about version prefix

(Asked by: username_0 on 2018-09-15)

In this post [Does the version prefix of an address force the type of transactions the address may treat?](https://bitcoin.stackexchange.com/questions/67875/does-the-version-prefix-of-an-address-force-the-type-of-transactions-the-address), I saw "the version byte doesn't actually appear in the final transaction."  
I don't understand why? Could anyone can help to tell more detail about that?

**Tags:** address, bitcoin-core-development


---

## 1 answers

### Answer by username_1 on 2018-09-15. Score: 3

The [address prefix](https://en.bitcoin.it/wiki/List_of_address_prefixes) determines how a wallet will ***interperet*** the address. Let's look at an example.

## Generate a P2PKH address

1. Take a public key, e.g. `023cba1f4d12d1ce0bced725373769b2262c6daa97be6a0588cfec8ce1a5f0bd09`
2. Apply `HASH160`: `3a38d44d6a0c8d0bb84e0232cc632b7e48c72e0e`
3. Prepend the version prefix for `P2PKH` (`0x00`): `003a38d44d6a0c8d0bb84e0232cc632b7e48c72e0e`
4. Base58Check encode it: `16JrGhLx5bcBSA34kew9V6Mufa4aXhFe9X`

See [How to Generate a Bitcoin Address — Step by Step](https://medium.com/coinmonks/how-to-generate-a-bitcoin-address-step-by-step-9d7fcbf1ad0b) for command line steps.

## Prefixes

Bitcoin has 2 main [address prefixes](https://en.bitcoin.it/wiki/List_of_address_prefixes) (mainnet):

**P2PKH** (Pay to Public Key Hash): `1`  
**e.g.**: `17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem`

**P2SH** (Pay to Script Hash): `3`  
**e.g.**: `3EktnHQD7RiAE6uzMj2ZifT9YgRrkSgzQX`

Addresses are just representations of the information necessary (`scriptPubKey`) to create a [transaction output](https://en.bitcoin.it/wiki/Transaction#Output), which is part of the [transaction](https://en.bitcoin.it/wiki/Transaction) and which is validated and stored on the network. It is only used by wallet application software, addresses are not stored on the Blockchain in this format.

The wallet will determine, based on the address prefix, when it is decoded, how to construct this `scriptPubkey`. For `P2PKH` this would be in this form:

`OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG`

Where you will notice, the only info it needs is the `pubKeyHash` which is contained in the decoded address (step 2 above). However, the format for a `P2SH` `scriptPubkey` is `OP_HASH160 <scriptHash> OP_EQUAL`. If you used the wrong prefix, the wallet would create the wrong script and a tx will most likely burn those coins because no one will be able to guess keys/scripts that will successfully satisfy the `scriptPubkey`.

> **Comments:**
> **username_0**: Thank you so much for the explanation. As you said "It is only used by wallet application software, addresses are not stored on the Blockchain in this format."  would you please show me what format address stored on the Blockchain? Using blockchain.info we can see the address prefix of 1, 3, bc1, where are they came?  

---

