Progress pill
Creation of Bitcoin Wallets

Wallet Structure and Derivation Paths

Bitcoin Wallet Architecture

Wallet Structure and Derivation Paths

  • The Depths of Derivation of an HD Wallet
  • Notation of Derivation Paths
  • Summary of the derivation structure
The hierarchical structure of HD wallets in Bitcoin allows for the organization of key pairs in various ways. The idea is to derive, from the master private key and master chain code, several levels of depth. Each added level corresponds to the derivation of a child key pair from a parent key pair.
Over time, different BIPs have introduced standards for these derivation paths, aiming to standardize their use across different software. So, in this chapter, we will discover the meaning of each level of derivation in HD wallets, according to these standards.

The Depths of Derivation of an HD Wallet

Derivation paths are organized into layers of depth, ranging from depth 0, which represents the master key and master chain code, to layers of sub-levels for deriving addresses used to lock UTXOs. The BIPs (Bitcoin Improvement Proposals) define the standards for each layer, which helps to harmonize practices across different wallet management software.
A derivation path, therefore, refers to the sequence of indices used to derive child keys from a master key.
Depth 0: Master Key (BIP32)
This depth corresponds to the wallet's master private key and master chain code. It is represented by the notation .
Depth 1: Purpose (BIP43)
The purpose determines the logical structure of derivation. For example, a P2WPKH address will have at depth 1 (according to BIP84), while a P2TR address will have (according to BIP86). This layer facilitates compatibility between wallets by indicating index numbers corresponding to the BIP numbers.
In other words, once you have the master key and the master chain code, these serve as a parent key pair to derive a child key pair. The index used in this derivation can be, for example, if the wallet is intended to use SegWit v0 type scripts. This key pair is then at depth 1. Its role is not to lock bitcoins, but simply to serve as a waypoint in the derivation hierarchy.
Depth 2: Currency Type (BIP44)
From the key pair at depth 1, a new derivation is performed to obtain the key pair at depth 2. This depth allows differentiating Bitcoin accounts from other cryptocurrencies within the same wallet.
Each currency has a unique index to ensure compatibility across multi-currency wallets. For example, for Bitcoin, the index is (or 0x80000000 in hexadecimal notation). Currency indexes are chosen in the range from to to ensure hardened derivation.
To give you other examples, here are the indexes of some currencies:
  • (0x80000001) for testnet bitcoins;
  • (0x80000002) for Litecoin;
  • (0x8000003c) for Ethereum...
Depth 3: Account (BIP32)
Each wallet can be divided into several accounts, numbered from , and represented at depth 3 by for the first account, for the second, and so on. Generally, when referring to an extended key xpub, it refers to keys at this depth of derivation.
This separation into different accounts is optional. It aims to simplify the organization of the wallet for users. In practice, often only one account is used, usually the first by default. However, in some cases, if one wishes to clearly distinguish key pairs for different uses, this can be useful. For example, it is possible to create a personal account and a professional account from the same seed, with completely distinct groups of keys from this depth of derivation.
Depth 4: Chain (BIP32)
Each account defined at depth 3 is then structured into two chains:
  • The external chain: In this chain, what are known as "public" addresses are derived. These receiving addresses are intended to lock UTXOs coming from external transactions (that is, originating from the consumption of UTXOs that do not belong to you). To put it simply, this external chain is used whenever one wishes to receive bitcoins. When you click on "receive" in your wallet software, it is always an address from the external chain that is offered to you. This chain is represented by a pair of keys derived with the index .
  • The internal chain (change): This chain is reserved for receiving addresses that lock bitcoins coming from the consumption of UTXOs that belong to you, in other words, change addresses. It is identified by the index .
Depth 5: Address Index (BIP32)
Finally, depth 5 represents the last step of derivation in the wallet. Although it is technically possible to continue indefinitely, current standards stop here. At this final depth, the pairs of keys that will actually be used to lock and unlock the UTXOs are derived. Each index allows distinguishing between sibling key pairs: thus, the first receiving address will use the index , the second the index , and so on.

Notation of Derivation Paths

The derivation path is written by separating each level with a slash (). Each slash thus indicates a derivation of a parent key pair (, , ) to a child key pair (, , ). The number noted at each depth corresponds to the index used to derive this key from its parents. The apostrophe () sometimes placed to the right of the index indicates a hardened derivation (, ). Sometimes, this apostrophe is replaced by an . In the absence of an apostrophe or , it is therefore a normal derivation (, ). As we have seen in the previous chapters, hardened key indexes start from , or 0x80000000 in hexadecimal. Therefore, when an index is followed by an apostrophe in a derivation path, must be added to the indicated number to obtain the actual value used in the HMAC-SHA512 function. For example, if the derivation path specifies , the actual index will be:
In hexadecimal, this is 0x8000002C.
Now that we have understood the main principles of derivation paths, let's take an example! Here is the derivation path for a Bitcoin receiving address:
In this example:
  • indicates the P2WPKH (SegWit v0) standard;
  • indicates the Bitcoin currency on the mainnet;
  • corresponds to the second account in the wallet;
  • indicates that the address is on the external chain;
  • indicates the 8th external address of this account.

Summary of the derivation structure

DepthDescriptionStandard Example
0Master Key
1Purpose (P2TR)
2Currency (Bitcoin)
3Account (First account)
4Chain (external) or (change)
5Address Index (first address)
In the next chapter, we will discover what "output script descriptors" are, a recently introduced innovation in Bitcoin Core that simplifies the backup of a Bitcoin wallet.
Quiz
Quiz1/5
What does depth 0 represent in the hierarchy of HD wallets?