What Is an xpub? Extended Public Keys and HD Wallets Explained
What is an xpub: the extended public key at the top of an HD wallet that derives every address without exposing a private key. How xpub, ypub and zpub work, why balances derive from one key, and how to check them safely.
By the BitcoinDatabase team
July 2026 · 8 min read
The short answer
An xpub is an extended public key: the master public key at the top of a hierarchical deterministic (HD) wallet. From it, the wallet mathematically derives every receive and change address it will ever use, without ever exposing a private key. That means you can share an xpub to let a tool watch a wallet's whole balance and history, but nobody can spend from it. The prefix tells you the address type: xpub for legacy, ypub for wrapped SegWit, zpub for native SegWit (bech32).
If you have ever looked at a modern Bitcoin wallet and wondered how it produces an endless stream of fresh addresses that all belong to you, the xpub is the answer. Understanding it explains how watch-only tracking, hardware wallets and portfolio tools work.
What does xpub stand for?
xpub stands for extended public key. "Extended" means it carries more than a normal public key: alongside the key itself it holds a chain code, an extra piece of entropy that lets the wallet derive a whole tree of child keys from this one parent. That derivation is deterministic, so the same xpub always produces the same sequence of addresses in the same order. This is the HD (hierarchical deterministic) wallet standard defined in Bitcoin Improvement Proposals BIP32, BIP44 and their successors, and it is why you only back up one seed phrase even though your wallet uses hundreds of addresses.
How does an xpub derive addresses?
An xpub derives addresses by combining its public key and chain code with an index number, producing a child public key for each index, which is then hashed into an address. Wallets split this into two branches: one for receiving payments and one for change that comes back to you when you spend. So index 0 of the receive branch is your first address, index 1 the second, and so on, all the way down. Because the math only needs the public key, a piece of software holding just your xpub can compute every address you will use next, watch them on the chain, and total your balance, without any ability to sign a transaction.
xpub vs ypub vs zpub
The three prefixes encode the same kind of key for different address formats, which matters because a wallet's balance only shows up if you derive the right address type.
| Prefix | Address type | Address starts with |
|---|---|---|
| xpub | Legacy (P2PKH) | 1... |
| ypub | Wrapped SegWit (P2SH) | 3... |
| zpub | Native SegWit (bech32) | bc1q... |
People often see "zero balance" when they paste an xpub into a tool that only derives legacy addresses while their coins sit on native SegWit addresses. Matching the prefix to the format the wallet actually uses fixes it. The underlying key material is the same; only the address-encoding rules differ.
Is it safe to share your xpub?
Sharing an xpub cannot cost you your coins, because it holds no spending power: it can reveal addresses and read their history, but it cannot sign a transaction. It is a privacy exposure, not a security one. Anyone with your xpub can see every address the wallet has used and will use, your full balance, and all your past and future transactions on those addresses. So treat it as sensitive personal data, share it only with services you trust, and never post it publicly, but understand that a leaked xpub does not let a thief move your funds. To track balances, a wallet or an xpub balance API uses exactly this watch-only property: it reads without ever needing a key that can spend.
How do you check an xpub balance?
You check an xpub balance by deriving the wallet's addresses from the key, looking up each one on the blockchain, and summing what they hold. In practice you rarely do this by hand: a watch-only wallet or an API takes the xpub, derives addresses across the receive and change branches, scans them to the gap limit (the run of consecutive unused addresses that signals the end of the wallet), and returns the combined total. The gap limit matters because if you skip too far past a stretch of empty addresses, you can miss funds sitting beyond them. A tool that indexes the whole chain can do the full scan in one request and give you the wallet total to the satoshi, along with a per-address breakdown for reconciliation.
Why HD wallets use one key for everything
HD wallets derive everything from one seed for two practical reasons: privacy and backup simplicity. Using a fresh address for every payment makes it harder for observers to link your transactions and estimate your total holdings, and deriving those addresses deterministically means you never have to back up each one, just the single seed. The xpub is the public half of that design, the piece you can hand to a watch-only tool so it tracks the wallet without ever touching the secret that controls it. If you want to follow balances and movements across an HD wallet in real time, that is what a Bitcoin wallet tracker is built to do.
The xpub is the quiet workhorse of every modern Bitcoin wallet: one public key that maps a whole wallet's worth of addresses, safe to watch, impossible to spend from. Once it clicks, watch-only tracking and hardware-wallet workflows stop being mysterious.
Hit Run to query the fully-indexed Bitcoin blockchain.
BTC
30-day trend
informational on-chain data · not financial advice
Query the Bitcoin blockchain yourself
Pull balances, UTXOs, transactions, on-chain metrics and fund flows from the fully indexed Bitcoin blockchain by REST API, SQL and dashboards. Indexed since 2009, new blocks within seconds, no node to run.