One seed can reproduce a whole tree of keys. Sharing a branch can let another system derive receiving keys while the spending keys stay private.
A wallet needs fresh keys as it receives payments. Backing up every key separately would make that wallet harder to preserve. BIP 32 lets a single seed reproduce a whole tree of keys, so the backup does not have to grow with the tree.1,2,3
The tree can also be shared in parts. A server can derive receiving keys from an extended public key without holding the private keys that spend the money. Hardened branches set a boundary on what that public key can reach.4,5,6
This chapter is an independent explanation, not the proposal itself. Preamble fields are shown as the
pinned files record them, without author e-mail addresses. Status is the proposal’s own field. It is not
an endorsement or a sign of consensus.
HMAC-SHA512 turns a seed into 64 bytes. The left half becomes the master private key; the right half becomes the master chain code.7,8
Keys with an extra 32 bytes
Every node in the tree is an extended key: an ordinary key plus a chain code, 32 more bytes of entropy. BIP 32 adds the chain code so that a node’s children do not depend on the key alone. The chain code is the same in the private and the public version of a node.9
A public key alone is not enough to derive child public keys. The derivation also needs the chain code. Together, the public key and chain code form an extended public key, or xpub.3,9
An extended private key is the pair (k, c): private key and chain code. Its public counterpart is (K, c), where K is the public key for k. Turning the first into the second is called neutering it, because the result can no longer sign transactions.10,11
An extended key is a key and a chain code. Neutering swaps the private key for its public key and keeps the very same chain code.9,10,11
One step down the tree
To derive child number i, use the parent’s chain code as the key for HMAC-SHA512. Split the 64-byte output into two halves. Add the left half to the parent’s private key, modulo the curve order, to obtain the child’s private key. The right half becomes the child’s chain code.12,13
What goes into the HMAC depends on the index. Indices 0 to 2³¹ − 1 are normal, and the input is the parent’s public key followed by the index. Indices from 2³¹ upward are hardened, and the input is the parent’s private key, padded with a zero byte, followed by the index. Paths mark hardened indices with an H: m/0H/1 is normal child 1 of hardened child 0 of the master.13,14,15,16
The same 37 bytes of HMAC data, filled two ways. A normal child hashes the parent’s public key; a hardened child hashes its private key, padded with a zero byte.13,14,15
Switch from holding the extended private key to holding only the extended public key. Then toggle the normal and hardened branch. Watch which keys that holder can derive and which branches it cannot reach.3,5,6,8
FIG. A02.4
Fig. A02.4 Who can derive what
Static view: the tree held as m, with branch m/0H/1 opened. With JavaScript you can switch to holding only M, make branch 1 hardened, and open any branch.
Holding m, the extended private key. Branch m/0H/1 is normal. HMAC-SHA512 keyed by m/0H’s chain code hashes its public key and 00000001; the left half is added to its private key.
80000001 (no other value of m/1H can be derived from M)
Exact values for this branch
Child number
00000000 (no other value of m/1H/0 can be derived from M)
Seed: BIP 32 test vector 1 (line 220). Every key here is public test material; never use it for funds.
A hardened edge is a wall for public keys. Holding M, you can follow normal edges down to M/1/0, but you cannot cross into m/0H: deriving it needs a private key you do not have.3,5,6,8When derivation skips a child
In rare cases a step produces an invalid key, and the wallet moves on to the next index. BIP 32 puts the odds below one in 2¹²⁷.15,17
What an extended public key can do
Normal derivation uses the parent’s public key in the HMAC input. An extended public key therefore supplies everything needed to derive a normal child’s public key and chain code. Convert the HMAC output’s left half to a public point and add it to the parent’s public key. The right half supplies the child’s chain code. BIP 32 states that public and private derivation produce corresponding keys for the same child.5,18
Two ways to the same child public key. Only the left one needs the private key; the build checks that both agree for every normal child in the tree.5,18
BIP 32 gives a webshop as an example. Its server can use an extended public key to generate a fresh address for each order without holding the spending keys. Disclosure of that xpub reveals incoming payments but does not enable spending existing outputs. There is a separate operational risk: an attacker who controls the server can replace the receiving addresses it displays. That can divert future payments without revealing a private key.4,19,20
BIP 32 lists other kinds of partial sharing too. An auditor can be given every account’s extended public key and see all transactions without a single secret key. A business partner can be given one account’s external chain and use it as a kind of super address, without asking for a new address for each payment.21,22
FIG. A02.6
Fig. A02.6 Sharing without spending
BIP 32’s examples of sharing part of a wallet. Each party holds an extended public key; none of them holds a key that can spend.4,19,21,22
Hardened children are different. Their HMAC input contains the parent’s private key, so public derivation is simply not defined for them. There is also no way at all from a public parent to a private child. An extended public key reaches the public keys of descendants that are linked to it by normal steps only, and nothing else.3,5,6,23
Why hardened keys exist
Normal derivation has a specific risk. An attacker may obtain a parent xpub and a descendant private key connected to it through normal steps only. Together, these let the attacker recover the parent’s extended private key and derive every key below it.24
For a normal child, the parent xpub reveals the HMAC value added during derivation. Anyone who also obtains that child’s private key can subtract the value again to recover the parent’s private key. The example below shows the recovery on BIP 32’s published vector.24,25
FIG. A02.7
Fig. A02.7 An xpub plus one leaked key
01 Someone holds m/0H’s extended public key, and the private key of its normal child m/0H/1 has leaked.
02 The xpub alone is enough to recompute I_L for child 1: the HMAC input is public.
03 Subtract: k = k₁ − I_L (mod n).
04 That is m/0H’s private key, and with c every key below it. The hardened edge above m/0H stops the climb.
BIP 32’s warning, recomputed on the published vector. A leaked child key and its parent’s xpub give back the parent’s private key; the hardened edge above the parent stops the climb there.24,25,26
BIP 32 uses hardened derivation at the account level to limit this risk. A leaked account private key cannot reveal the master key or keys in other accounts through this recovery method. BIP 32 therefore requires more care with extended public keys than with ordinary public keys. Recovering a parent private key requires both its xpub and a leaked descendant private key connected through normal steps. The xpub alone derives only public keys.3,24,26
Caveat
Sharing an extended public key is also a privacy decision. It lets the holder see every public key reached from it by normal steps, and with them the payments. BIP 32’s auditor use case relies on exactly that.3,21,27
Writing a key down
An extended key travels as 78 bytes: a version, the depth in the tree, the parent’s fingerprint, the child number, the chain code and the key. Base58Check adds four checksum bytes and produces exactly 111 characters, beginning xpub or xprv on mainnet.28
Only the version and the key data differ. Depth, parent fingerprint, child number and chain code are identical: they describe the node’s place in the tree, and the chain code is shared by both forms. The checksum differs only as a consequence.9,28
The fingerprint is the first four bytes of the Hash160 of a key’s public key. It only helps software spot parents and children quickly. Different keys can share a fingerprint, and BIP 32 says software must be willing to deal with such collisions.29,30
Checks when importing an extended public key
Importing an extended public key also requires a check that its X coordinate corresponds to a point on the curve. BIP 32’s fifth test vector is a list of malformed keys of this and other kinds, and the decoder behind this page rejects all sixteen of them, each for its stated reason.8,31
A tree, not a wallet layout
BIP 32 suggests accounts as hardened children of the master, each with an external chain for receiving and an internal chain for change: m/iH/0/k and m/iH/1/k. It explicitly allows other layouts. Later path conventions build on the same derivation mechanism, so an unfamiliar path does not by itself mean a wallet is broken.32
Back to the seed
BIP 32 asks for a seed of 128 to 512 bits from a random number generator, and advises 256. The 64-byte seed that BIP 39 produces, described in the previous chapter, fits. The test vector file referenced by BIP 39 also lists the master extended key for each of its 24 English seeds. The tests behind this page reproduce all of them.7,33
Every node can have 2³¹ normal and 2³¹ hardened children. The seed can reproduce every node in the tree, so one seed backup covers all those keys.3,7,14
The wallet-backup problem BIP 32 addressed
When BIP 32 was written, the reference wallet generated each key at random. To avoid needing a new backup after every transaction, it kept a pool of a hundred spare keys. Every key was independent, so every key had to be saved.2
BIP 32, assigned in 2012 and recorded as deployed, takes another route: derive every key from one seed, arranged as a tree. Branches of that tree can be shared with other systems, entirely or in part, with or without the ability to spend.1,34,35
The seed preserves the tree. The branch you share determines which descendants another system can derive, and whether it can derive public keys or private ones.1,3,5,6
Evidence
Each numbered marker in the text points here, and the ↩ links lead back to the text. Quotes are verbatim
from the BIP files at commit 3a10b5b, wiki markup
included. Links open the exact lines. Labels say what kind of statement each entry is: a rule, the
author’s rationale, history, a test vector, or our own inference.
↩ a b c Author’s rationale HD wallets can be shared partially or entirely with different systems, each with or without the ability to spend.
wallets which can be shared partially or entirely with different systems, each with or without the ability to spend coins.
↩ a b History When BIP32 was written, the reference client used randomly generated keys and cached 100 reserve keys to avoid a backup after every transaction.
The Bitcoin reference client uses randomly generated keys. In order to avoid the necessity for a backup after every transaction, (by default) 100 keys are cached in a pool of reserve keys.
↩ a b c d e f g h i Rule An extended private key reconstructs all descendant keys; an extended public key reconstructs all descendant non-hardened public keys.
knowing an extended private key allows reconstruction of all descendant private keys and public keys, and knowing an extended public key allows reconstruction of all descendant non-hardened public keys.
This permits for example a webshop business to let its webserver generate fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).
↩ a b c d e f g Rule CKDpub is only defined for non-hardened children; the child public key is point(I_L) + K_par.
====Public parent key → private child key==== This is not possible.
↩ a b c Rule The seed is 128 to 512 bits from a (P)RNG, 256 advised; I = HMAC-SHA512("Bitcoin seed", S); I_L is the master secret key and I_R the master chain code.
Generate a seed byte sequence S of a chosen length (between 128 and 512 bits; 256 bits is advised) from a (P)RNG.
Calculate I = HMAC-SHA512(Key = "Bitcoin seed", Data = S)
Use parse<sub>256</sub>(I<sub>L</sub>) as master secret key, and I<sub>R</sub> as master chain code.
↩ a b c d Test vector BIP32 embeds test vectors, including vectors for leading zeros and a list of invalid extended keys; the tested implementation reproduces all 17 valid chains and rejects all 16 invalid keys.
These vectors test for the retention of leading zeros.
These vectors test that invalid extended keys are recognized as invalid.
↩ a b c d Rule Both private and public keys are extended with a 32-byte chain code, identical for corresponding private and public keys, so children do not depend solely on the key.
In order to prevent these from depending solely on the key itself, we extend both private and public keys first with an extra 256 bits of entropy. This extension, called the chain code, is identical for corresponding private and public keys, and consists of 32 bytes.
↩ a b Rule An extended private key is (k, c); an extended public key is (K, c) with K = point(k).
We represent an extended private key as (k, c), with k the normal private key, and c the chain code. An extended public key is represented as (K, c), with K = point(k) and c the chain code.
↩ a b Rule N() gives the extended public key of an extended private key; it removes the ability to sign transactions.
In case parse<sub>256</sub>(I<sub>L</sub>) ≥ n or k<sub>i</sub> = 0, the resulting key is invalid, and one should proceed with the next value for i. (Note: this has probability lower than 1 in 2127.)
↩ a b Rule Computing a normal child's public key from the private or the public parent gives the same result; this is what makes non-hardened keys useful.
The fact that they are equivalent is what makes non-hardened keys useful (one can derive child public keys of a given parent key without knowing any private key)
↩ a b Author’s rationale BIP 32 says someone who illegally obtains access to the webserver can at most see incoming payments, not steal them.
This means someone illegally obtaining access to the webserver can at most see all incoming payments but will not be able to steal the money
↩ Editorial inference Our operational inference: control of a server that presents receiving addresses can let an attacker substitute their own addresses and divert future payments without deriving the merchant’s private keys. This is separate from disclosure of the xpub alone.
Deterministic wallets do not require such frequent backups, and elliptic curve mathematics permit schemes where one can calculate the public keys without revealing the private keys. This permits for example a webshop business to let its webserver generate fresh addresses (public key hashes) for each order or for each customer, without giving the webserver access to the corresponding private keys (which are required for spending the received funds).
↩ a b c Author’s rationale Sharing account extended public keys lets an auditor see all transactions but not a single secret key.
one can use the extended public key for the external chain of a specific account (M/i h/0) as a sort of "super address", allowing frequent transactions that cannot (easily) be associated, but without needing to request a new address for each payment.
↩ Rule N(m/aH) cannot be rewritten as N(m)/aH, because the latter is not possible.
However, N(m/a<sub>H</sub>) cannot be rewritten as N(m)/a<sub>H</sub>, as the latter is not possible.
↩ a b c d Rule A parent extended public key plus the private key of any descendant reached from it by non-hardened steps is equivalent to the parent extended private key; extended public keys must be treated more carefully than regular public keys.
knowledge of a parent extended public key plus any non-hardened private key descending from it is equivalent to knowing the parent extended private key (and thus every private and public key descending from it). This means that extended public keys must be treated more carefully than regular public keys.
↩ a b Test vector From test vector 1's xpub for m/0H and the private key of m/0H/1, the tested implementation recomputes m/0H's private key exactly.
knowledge of a parent extended public key plus any non-hardened private key descending from it is equivalent to knowing the parent extended private key
↩ a b Author’s rationale This weakness is why hardened keys exist and are used at the account level, so a leak of account-level or lower private keys never compromises the master or other accounts.
It is also the reason for the existence of hardened keys, and why they are used for the account level in the tree. This way, a leak of account-specific (or below) private keys never risks compromising the master or other accounts.
↩ Rule Leaking a private key means access to coins; leaking a public key can mean loss of privacy.
33 bytes: the public key or private key data (ser<sub>P</sub>(K) for public keys, 0x00 || ser<sub>256</sub>(k) for private keys)
This 78 byte structure can be encoded like other Bitcoin data in Base58, by first adding 32 checksum bits (derived from the double SHA-256 checksum), and then converting to the Base58 representation. This results in a Base58-encoded string of exactly 111 characters.
↩ Rule A key is identified by the Hash160 of its public key; the first 32 bits are its fingerprint.
Note that the fingerprint of the parent only serves as a fast way to detect parent and child nodes in software, and software must be willing to deal with collisions.
↩ Rule When importing an extended public key, implementations must verify that its X coordinate is on the curve.
When importing a serialized extended public key, implementations must verify whether the X coordinate in the public key data corresponds to a point on the curve. If not, the extended public key is invalid.
↩ Author’s rationale BIP32's default layout uses hardened account nodes with an external chain (m/iH/0/k) and an internal chain (m/iH/1/k); it is a default and advisory, and implementations may deviate.
The layout defined in this section is a default only, though clients are encouraged to mimic it for compatibility, even if not all features are supported.
m/i<sub>H</sub>/0/k corresponds to the k'th keypair of the external chain of account number i of the HDW derived from master m.
m/i<sub>H</sub>/1/k corresponds to the k'th keypair of the internal chain of account number i of the HDW derived from master m.
However, implementations may deviate from it for specific needs; more complex applications may call for a more complex tree structure.
↩ Test vector BIP39 seeds feed BIP32. The trezor vector file referenced by BIP39 also lists each seed's master extended key; the tested implementation reproduces all 24 English entries.
In the first part, a system for deriving a tree of keypairs from a single seed is presented. The second part demonstrates how to build a wallet structure on top of such a tree.