<p>BIP 32 specifies a serialization format for extended public keys. This format has the prefix <code>xpub</code> and is generic for all public keys that can be used with BIP 32, regardless of the address type or the derivation path.</p>
<p>BIP 84 added an additional serialization which results in the prefix <code>zpub</code> to indicate that keys derived from that extended public key should only be used in native segwit addresses.</p>
<p>It is correct for a wallet to output xpubs for keys used in segwit addresses. It is also correct for a wallet to output zpubs for the same keys. It just depends on the implementation. The serialization is only used for some metadata to the wallet, the derived keys will all be the same. In order to get the same addresses, you need a wallet which will derive the keys and use them in the address type that you are expecting.</p>
<hr />
<p><code>tpub</code> is a prefix used for extended public keys that were created in a testnet wallet.</p>

CC BY-SA 4.0
2021-10-04T20:14:10.590Z
Thank you for this answer but now I must ask, how would I know how my Nano is deriving keys? I assume it's using Bip84, no? Should I assume it's using Bip32 since the key is an xpub? If so, why would the derivation path start with 84? Should I be converting this "xpub" to a "zpub" and use Bip84??
mike-a
CC BY-SA 4.0
2021-10-04T20:34:53.187Z
xpub and zpub are different encodings of the same key zpub encodes the additional information that the specific key should be used to derive a P2WPKH address (you can also derive P2PKH address from it if you want). Ledger uses bip84 to derive the keys/addresses but it doesnt bother to encode it to zpub it uses the more generic xpub.
Mike D
CC BY-SA 4.0
2021-10-05T02:17:57.270Z
@mike-a BIP 32 is the only derivation method. It specifies the way to derive keys and how derivation paths work. It does not specify any specific derivations paths. BIP 84 only specifies specific derivation paths to use, in addition to zpub. Your device is using both bips - it is using BIP 32 to derive keys specified with the BIP 84 derivation path.
Ava Chow
CC BY-SA 4.0
2022-11-20T01:23:37.300Z
@AndrewChow Thanks for this answer! Do you know of an API where I could fetch the total balance of a zpub address? https://bitcoin.stackexchange.com/questions/116038/how-to-retrieve-total-btc-held-in-ledger-wallet/116040#116040 Thanks.
Ryan
CC BY-SA 4.0
2021-10-04T16:01:18.853Z
2021-10-04T16:01:18.853Z
Ava Chow
<pre><code>{
  &quot;xpub&quot;: &quot;tpub-big-long-key-that-starts-with-tpub&quot;,
  &quot;index&quot;: 1,
  &quot;freshAddressPath&quot;: &quot;84'/1'/1'/0/0&quot;,
  &quot;id&quot;: &quot;libcore:1:bitcoin_testnet:tpub-big-long-key-that-starts-with-tpub:native_segwit&quot;,
  &quot;blockHeight&quot;: 2097540
}
</code></pre>
<p>When I copy the &quot;xPub&quot; from a Ledger Nano S Bitcoin Testnet wallet I find exactly this (key obviously obfuscated). I'm confused because in my novice research my understanding is that the derivation path 84'/1'/1'/0/0 is for zpub keys and segwit wallets. Indeed, my wallets in my ledger are labeled &quot;segwit&quot;. But here the extended key is labeled &quot;xpub&quot; and the key starts with &quot;xpub&quot;, or in the case of the Bitcoin Testnet, it starts with a &quot;tpub&quot;. Why?</p>
<p>Can somebody explain to me why this seems mixed up? Is this key an xpub or a zpub? Is a tpub and an xpub the same thing? Should I use Bip32, Bip44 or Bip84 to derive child keys (and thus addresses) that will match my ledger nano?</p>
<p>I have found a clever python class that will convert xpub to zpub. Is this the correct thing to do in this case?</p>
<p><a href="https://gist.github.com/jleo84/97fc58c6174f146642b2c215c20f88f5" rel="nofollow noreferrer">https://gist.github.com/jleo84/97fc58c6174f146642b2c215c20f88f5</a></p>
<p>Thanks in advance! This is my very first question (don't worry, I have more) on this Stack Exchange and I really appreciate any support or advice I can get.</p>

<segregated-witness><ledger-hardware-wallet><xpub>
Does Ledger Nano S Have an xPub or a zPub for Bitcoin wallets?
mike-a
# Does Ledger Nano S Have an xPub or a zPub for Bitcoin wallets?

(Asked by: username_0 on 2021-10-04)

```
{
  "xpub": "tpub-big-long-key-that-starts-with-tpub",
  "index": 1,
  "freshAddressPath": "84'/1'/1'/0/0",
  "id": "libcore:1:bitcoin_testnet:tpub-big-long-key-that-starts-with-tpub:native_segwit",
  "blockHeight": 2097540
}

```

When I copy the "xPub" from a Ledger Nano S Bitcoin Testnet wallet I find exactly this (key obviously obfuscated). I'm confused because in my novice research my understanding is that the derivation path 84'/1'/1'/0/0 is for zpub keys and segwit wallets. Indeed, my wallets in my ledger are labeled "segwit". But here the extended key is labeled "xpub" and the key starts with "xpub", or in the case of the Bitcoin Testnet, it starts with a "tpub". Why?

Can somebody explain to me why this seems mixed up? Is this key an xpub or a zpub? Is a tpub and an xpub the same thing? Should I use Bip32, Bip44 or Bip84 to derive child keys (and thus addresses) that will match my ledger nano?

I have found a clever python class that will convert xpub to zpub. Is this the correct thing to do in this case?

<https://gist.github.com/jleo84/97fc58c6174f146642b2c215c20f88f5>

Thanks in advance! This is my very first question (don't worry, I have more) on this Stack Exchange and I really appreciate any support or advice I can get.

**Tags:** segregated-witness, ledger-hardware-wallet, xpub


---

## 1 answers

### Answer by username_1 on 2021-10-04. Score: 1 | Accepted answer

BIP 32 specifies a serialization format for extended public keys. This format has the prefix `xpub` and is generic for all public keys that can be used with BIP 32, regardless of the address type or the derivation path.

BIP 84 added an additional serialization which results in the prefix `zpub` to indicate that keys derived from that extended public key should only be used in native segwit addresses.

It is correct for a wallet to output xpubs for keys used in segwit addresses. It is also correct for a wallet to output zpubs for the same keys. It just depends on the implementation. The serialization is only used for some metadata to the wallet, the derived keys will all be the same. In order to get the same addresses, you need a wallet which will derive the keys and use them in the address type that you are expecting.

---

`tpub` is a prefix used for extended public keys that were created in a testnet wallet.

> **Comments:**
> **username_0**: Thank you for this answer but now I must ask, how would I know how my Nano is deriving keys? I assume it's using Bip84, no? Should I assume it's using Bip32 since the key is an xpub? If so, why would the derivation path start with 84? Should I be converting this "xpub" to a "zpub" and use Bip84??  
> **username_2**: xpub and zpub are different encodings of the same key zpub encodes the additional information that the specific key should be used to derive a P2WPKH address (you can also derive P2PKH address from it if you want). Ledger uses bip84 to derive the keys/addresses but it doesnt bother to encode it to zpub it uses the more generic xpub.  
> **username_1**: @username_0 BIP 32 is the only derivation method. It specifies the way to derive keys and how derivation paths work. It does not specify any specific derivations paths. BIP 84 only specifies specific derivation paths to use, in addition to zpub. Your device is using both bips - it is using BIP 32 to derive keys specified with the BIP 84 derivation path.  
> **username_3**: @AndrewChow Thanks for this answer! Do you know of an API where I could fetch the total balance of a zpub address? https://bitcoin.stackexchange.com/questions/116038/how-to-retrieve-total-btc-held-in-ledger-wallet/116040#116040 Thanks.  

---

