Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article examines BIP-32, which standardizes hierarchical deterministic (HD) wallets. Backing up a single seed allows a wallet to regenerate and selectively share a hierarchy of keys.
This explanation translates, summarizes, and expands on the original proposal.
I have also written about other proposals.
Abstract
A hierarchical deterministic wallet derives multiple public and private key pairs in a hierarchy from one seed. Given the same seed and derivation paths, a compatible implementation can regenerate the same keys, simplifying backups and selective sharing.
BIP-32 defines a standard to enable interoperability between HD wallet clients. It describes several capabilities, not all of which every client must support.
The specification has two parts:
- Deriving a tree of key pairs from a single seed.
- Defining a wallet layout on top of that tree.
Motivation
Early official Bitcoin clients generated keys randomly. New keys were required as transactions were made, so users needed frequent backups. Clients addressed this by pre-generating and caching 100 spare keys, but this approach still had limitations, particularly when sharing a wallet between different systems.
HD wallets address this problem. Elliptic-curve cryptography enables certain child public keys to be derived without knowing the corresponding private keys. An online shop, for example, can generate a fresh receiving address on its web server for every payment without exposing its spending keys.
Earlier deterministic wallets could generate only a single chain of keys. Selectively sharing a subset of keys with another system was therefore difficult: sharing was effectively all or nothing.
HD wallets derive multiple chains from a root key. An online shop can give its web server access to the receiving addresses while keeping information about change addresses and spending keys private.
The hierarchy thus provides flexibility without requiring every system to hold the wallet's private keys.
Specification
HD wallet key derivation
Terminology
The specification uses Bitcoin's public-key cryptography, based on the secp256k1 elliptic curve. The relevant objects include:
- Points on the elliptic curve (public keys).
- The order of the curve's generator, which determines the private-key range.
- Byte sequences.
Elliptic-curve point addition is defined by the curve's group operation rather than ordinary integer addition.
The specification also uses the following conversion functions:
point(p)- Computes the public key (curve point) corresponding to private key
p.
- Computes the public key (curve point) corresponding to private key
ser_32(i)- Serializes the 32-bit integer
iinto four bytes.
- Serializes the 32-bit integer
ser_256(p)- Serializes the 256-bit integer
pinto 32 bytes.
- Serializes the 256-bit integer
ser_P(P)- Serializes public key
Pin compressed SEC1 format.
- Serializes public key
parse_256(p)- Interprets the 32-byte sequence
pas a 256-bit integer.
- Interprets the 32-byte sequence
Extended keys
HD wallets manage each key together with an additional value called a chain code. The pair is called an extended key.
- Extended private key
(k, c), wherekis the private key andcis a 32-byte chain code.
- Extended public key
(K, c), whereKis the public key corresponding tokandcis the same chain code.
Each parent has possible child indices. Half () are non-hardened indices and half are hardened indices.
Child key derivation
Deriving a child private key from a parent private key
CKDpriv((k_parent, c_parent), i) derives the extended private key for child index i.
- Indices at least are hardened, and lower indices are non-hardened.
- Hardened derivation computes HMAC-SHA512 over input containing the parent private key.
- Non-hardened derivation uses the corresponding parent public key instead.
- The output is split into two halves. The left half contributes to the child private key, and the right half becomes the new chain code.
If the derivation produces an invalid result, such as a zero child private key or an out-of-range intermediate scalar, the next index is tried.
Deriving a child public key from a parent public key
CKDpub((K_parent, c_parent), i) computes a child public key from a parent extended public key. This is possible only for non-hardened children.
- Derivation fails for an index at least and can proceed for lower indices.
- HMAC-SHA512 provides a scalar used to calculate a curve point. Adding that point to the parent public key yields the child public key.
Obtaining a public key from a private key (neutered key)
The operation N((k, c)) converts extended private key (k, c) into extended public key (K, c). This produces a neutered key that retains public derivation capability but cannot itself sign transactions.
Only non-hardened children can be derived using public key material alone. This lets systems manage addresses without holding private keys.
Public keys do not reveal private keys
Under the elliptic-curve security assumption, recovering a private key from its corresponding public key is computationally infeasible.
Key tree structure
Keys form a tree rooted at the master key. Repeated applications of CKDpriv(m, i) derive successive levels of child keys.
A path can be written as follows:
m/3H/2/5- Derive hardened child index 3 from the master, then non-hardened child index 2, then non-hardened child index 5.
A public derivation path can similarly be written as M/3/2/5. Hardened derivation requires private key material, so an extended public key alone cannot cross a hardened derivation boundary.
Key identifiers
An extended public key can be identified by hashing its public key with SHA-256 followed by RIPEMD-160, yielding a 160-bit identifier. This resembles the hash used in Bitcoin addresses, but displaying the identifier as a payment address is discouraged to avoid accidental transfers.
The first 32 bits form the key fingerprint, which helps identify parent-child relationships. Fingerprints are not guaranteed to be unique.
Serialization format
Extended keys are serialized with the following fields and encoded using Base58Check:
- Version (mainnet: xpub/xprv; testnet: tpub/tprv).
- Depth (0 for the master key, 1 for a first-level child).
- Parent key fingerprint.
- Child number (index).
- Chain code (32 bytes).
- Key data (compressed public key, or a 0x00 prefix followed by the 32-byte private key).
The serialized payload is 78 bytes. After appending a checksum, Base58 encoding produces a 111-character string beginning with a prefix such as xpub or xprv.
Generating the master key

The master key is derived from a seed rather than generated directly.
- Generate a random seed of 128 to 512 bits (256 bits is recommended).
- Apply HMAC-SHA512 to the seed using
"Bitcoin seed"as the HMAC key to obtain a 64-byte output. - Use the first 32 bytes as the master private key and the remaining 32 bytes as its chain code.
- If the resulting private key is invalid, generate a new seed and try again.
This provides a reproducible root extended key.
HD wallet structure
Introduction to the wallet layout
As described above, an HD wallet can derive a hierarchy of keys from one seed. The next question is how a wallet organizes that tree.
The following layout is a default, not a requirement for every client. Following it helps different wallet implementations interoperate.
Default wallet layout
An HD wallet is organized into numbered accounts, with account 0 as the default. In the original model, clients without multi-account support use only account 0.
Each account contains two key chains.
- External chain
- Generates new public receiving addresses.
- Addresses for incoming payments are derived from this chain.
- Internal chain
- Used primarily for internal wallet purposes.
- Examples include change addresses and receiving mining proceeds without using publicly advertised receiving addresses.
The key paths are as follows (m is the master key, i the account number, and k the child index):
m/iH/0/k- Child index
kof accounti's external chain.
- Child index
m/iH/1/k- Child index
kof accounti's internal chain.
- Child index
iH denotes a hardened index. A wallet that does not support an internal chain may derive all keys through the external chain instead.
Use cases
Sharing an entire wallet (m)
Two systems that need to use the same wallet and both make payments can share its master extended private key. Both systems must be trusted with the resulting spending authority.
Wallet clients can cache a number of public keys in advance to monitor incoming payments efficiently. External chains may contain gaps in used addresses and therefore require a larger look-ahead range than internal chains.
Clients can also discover additional accounts as new accounts are used. Account names, however, are not synchronized on-chain and must be configured separately.
Auditing (N(m/*))
For accounting audits, a wallet can share the extended public keys of all its accounts. An auditor can track incoming and outgoing addresses without receiving the corresponding private keys.
Managing branches or departments (m/iH)
A company with several branches or departments can assign each its own account while managing the hierarchy from a single master key. The head office can monitor all accounts and, where authorized, move funds between departments.
Recurring business-to-business payments (N(m/iH/0))
Companies that frequently send payments to one another can share an extended public key for an account's external chain, such as N(m/1H/0). The payer can generate fresh receiving addresses without requesting one for every payment, helping avoid address reuse.
The same approach can be used for mining pool payouts.
Receiving payments on a less trusted system (N(m/iH/0))
An online shop may want its web server to generate payment addresses without giving it authority to spend funds.
By giving the server only the external chain's extended public key, the wallet permits address generation and monitoring of incoming payments without disclosing private keys. The server cannot spend funds using that extended public key alone, nor derive other accounts or the internal chain. Its access is limited to the shared branch.
Backward compatibility
At a minimum, a client implementing this HD wallet standard must be able to import extended public or private keys and access their immediate children.
The master-to-account-to-chain-to-child layout described by BIP-32 is recommended rather than mandatory. Clients that do not distinguish accounts or internal and external chains can still provide basic compatibility.
Following a common layout improves interoperability, while applications needing more complicated structures may extend the design.
Security considerations
BIP-32 relies on the security assumptions of elliptic-curve cryptography. Recovering a private key from its public key requires solving the elliptic-curve discrete logarithm problem, with an estimated complexity of around 2 to the power of 128 group operations.
Additional security assumptions stated by the standard include:
- Given a child extended private key and its index, finding the parent private key is assumed to require work comparable to 2 to the power of 256 HMAC-SHA512 evaluations.
- Given two or more child extended private keys and their indices, determining whether they share a parent is assumed to require a comparable amount of work.
The specification also identifies properties it does not guarantee:
- Given a parent extended public key and a child public key, the child index is not guaranteed to be hard to discover.
- Given a parent extended public key and a non-hardened child private key, recovery of the parent private key is not guaranteed to be hard.
The Japanese original describes these latter properties as difficult. This contradicts its own following warning and the distinction in the specification between assumed properties and properties that are not guaranteed.
Important precautions
Exposing private keys can lead to loss of funds. An extended public key alone does not grant spending authority, but it can expose address relationships. Extended keys represent entire branches of descendant keys, so they require particular care.
One important risk is easy to overlook.
If a parent extended public key and a corresponding non-hardened child private key are both exposed, the parent private key can be recovered. This compromises all descendants of that parent and potentially a substantial part of the wallet.
The specification therefore recommends hardened derivation at the account level. This helps contain exposure within a compromised account rather than allowing it to propagate to sibling accounts or the master key.
Citation
This BIP is licensed under the 2-clause BSD license.
Conclusion
BIP-32 standardizes HD wallets, allowing a single seed to generate a hierarchy of keys that can be backed up and selectively shared.
If you have questions, feel free to contact me via Twitter.
I also share technical content on the following platforms.


