Serialization and Prefixes (ypub, zpub)
Serialization and Prefixes (ypub, zpub)
While the original BIP32 standard only defined xpub and xprv, the evolution of Bitcoin (SegWit) required new ways to tell wallets which type of address to generate from an extended key. This led to the creation of the SLIP-132 standard.
1. The Standard Prefix: xpub
An xpub (Mainnet) always starts with the characters xpub.
- Default Behavior: In most older wallets, an
xpubwill generate Legacy (P2PKH) addresses starting with a1.
2. The SegWit Prefixes
To help wallets know they should generate SegWit addresses, different version bytes were introduced:
ypub (Nested SegWit)
zpub (Native SegWit)
-
Prefix:
zpub -
Address Type: Bech32 (P2WPKH) (Starts with
bc1q). -
Version Byte:
0x04b24746
3. Why the prefixes matter?
The internal math of the key is exactly the same whether it starts with x, y, or z. The only difference is the Version Byte at the beginning.
-
The Benefit: If you import a
zpubinto a wallet like Electrum or BlueWallet, the software automatically knows to show you yourbc1qbalances. -
The Problem: If you import an
xpubbut you were actually using Native SegWit, the wallet might show a balance of Zero because it is looking at the wrong set of (Legacy) addresses.
4. The Table of SLIP-132
| Prefix | Script Type | Address Format |
|---|---|---|
| xpub | P2PKH | 1... (Legacy) |
| ypub | P2SH-P2WPKH | 3... (Nested SegWit) |
| zpub | P2WPKH | bc1q... (Native SegWit) |
| Ypub | P2WSH | Multisig Nested SegWit |
| Zpub | P2WSH | Multisig Native SegWit |
In the final section, we will build a Python Extended Key Auditor.
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: