B++ Logo

HD Wallets

Hierarchical Deterministic (HD) wallets generate all keys from a single master seed, enabling organized key management and simple backups. This is the foundation of modern Bitcoin wallet architecture.

Overview

HD wallets, defined in BIP32, allow a wallet to derive an unlimited number of key pairs from a single master seed. Combined with BIP39 (mnemonic phrases) and BIP44 (account structure), this creates a powerful and standardized wallet system.

Key Benefits:

  • Single backup (seed phrase) for all keys
  • Organized account and address structure
  • Watch-only wallets using extended public keys
  • Deterministic key generation across devices

BIP39: Mnemonic Seed Phrases

BIP39 defines how to generate human-readable seed phrases from random entropy.

Mnemonic Generation Process

  1. Generate random entropy (128-256 bits)
  2. Calculate checksum (first bits of SHA256 hash)
  3. Append checksum to entropy
  4. Split into 11-bit groups
  5. Map each group to a word from the 2048-word list
Entropy (bits)Checksum (bits)Words
128412
160515
192618
224721
256824

Generating a Mnemonic


BIP32: Key Derivation

BIP32 defines how to derive child keys from parent keys using a hierarchical structure.

Extended Keys

Extended keys contain additional metadata for derivation:

  • Extended Private Key (xprv): Can derive child private and public keys
  • Extended Public Key (xpub): Can only derive child public keys
xprv = [4 bytes version][1 byte depth][4 bytes fingerprint][4 bytes child index][32 bytes chain code][33 bytes key]

Derivation Paths

Derivation paths use slash-separated indices:

m / purpose' / coin_type' / account' / change / address_index

Examples:

  • m/44'/0'/0'/0/0 - First receiving address (BIP44 legacy)
  • m/84'/0'/0'/0/0 - First receiving address (BIP84 native SegWit)
  • m/86'/0'/0'/0/0 - First receiving address (BIP86 Taproot)

The apostrophe (') indicates hardened derivation.

Hardened vs Normal Derivation

TypeIndex RangeSecurityUse Case
Normal0 to 2^31-1Child xpub can derive siblingsReceiving addresses
Hardened2^31 to 2^32-1Child xpub cannot derive siblingsAccount separation

Security Note: Always use hardened derivation for account-level keys. If a normal child private key is compromised along with the parent xpub, all sibling private keys can be derived.

Deriving Keys from Seed


BIP44: Multi-Account Hierarchy

BIP44 defines a standard account structure for HD wallets.

Path Structure

m / purpose' / coin_type' / account' / change / address_index
LevelHardenedDescription
purposeYesBIP number (44, 49, 84, 86)
coin_typeYesCoin identifier (0 = Bitcoin)
accountYesAccount index (0, 1, 2...)
changeNo0 = external (receiving), 1 = internal (change)
address_indexNoAddress index within chain

Purpose Values by Address Type

BIPPurposeAddress TypePrefix
BIP4444'P2PKH (Legacy)1...
BIP4949'P2SH-P2WPKH (Nested SegWit)3...
BIP8484'P2WPKH (Native SegWit)bc1q...
BIP8686'P2TR (Taproot)bc1p...

Watch-Only Wallets

Extended public keys (xpubs) enable watch-only wallets that can:

  • Generate receiving addresses
  • Monitor incoming transactions
  • Calculate balances

Without being able to spend funds (no private keys).

Creating a Watch-Only Wallet


Security Best Practices

Seed Phrase Storage

  • Physical backup: Write on paper or metal, store securely
  • Never digital: Don't store on computers, phones, or cloud
  • Multiple copies: Keep backups in separate locations
  • Test recovery: Verify you can restore from backup

Passphrase (25th Word)

BIP39 supports an optional passphrase that:

  • Creates a completely different wallet
  • Provides plausible deniability
  • Adds another layer of security

Warning: A forgotten passphrase means permanent loss of funds.

Extended Public Key Exposure

Exposing an xpub reveals:

  • All past and future addresses
  • Complete transaction history
  • Total balance

Never share xpubs publicly unless intentional (e.g., donation addresses).


Gap Limit

The gap limit determines how many unused addresses to scan before stopping. Default is typically 20.

Important for wallet recovery: If you used addresses beyond the gap limit without using intermediate addresses, those funds may not appear in a recovered wallet.


Summary

HD wallets provide:

  • Single backup: One seed phrase backs up all keys
  • Organized structure: Hierarchical account and address management
  • Watch-only capability: Monitor without spending ability
  • Standardization: BIP32/39/44 ensure wallet interoperability
  • Security: Hardened derivation protects account-level keys

Understanding HD wallets is essential for building modern Bitcoin wallet applications.