B++ Logo

Address Types

Bitcoin has evolved through several address formats, each offering different features, security properties, and transaction costs. Understanding these types is essential for wallet development.

Overview

TypePrefixExample StartIntroduced
P2PKH11BvBMSEYstW...2009 (Genesis)
P2SH33J98t1WpEZ7...2012 (BIP16)
P2WPKHbc1qbc1qw508d6q...2017 (BIP141)
P2WSHbc1qbc1qrp33g0q...2017 (BIP141)
P2TRbc1pbc1p5cyxnux...2021 (BIP341)

P2PKH (Pay-to-Public-Key-Hash)

The original Bitcoin address format, also known as "legacy" addresses.

Structure

scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
scriptSig: <signature> <publicKey>

Address Generation

Characteristics

  • Size: 34 characters
  • Input size: ~148 vB
  • Output size: 34 vB
  • Script type: Standard pay-to-pubkey-hash

P2SH (Pay-to-Script-Hash)

Introduced in BIP16, P2SH allows complex scripts to be represented by a simple hash.

Structure

scriptPubKey: OP_HASH160 <scriptHash> OP_EQUAL
scriptSig: <data> <redeemScript>

Common Uses

  • Multisig addresses (before SegWit)
  • Nested SegWit (P2SH-P2WPKH)
  • Time-locked scripts

Address Generation (P2SH-P2WPKH)

Characteristics

  • Size: 34 characters
  • Input size: ~91 vB (for P2SH-P2WPKH)
  • Output size: 32 vB
  • Script type: Pay-to-script-hash

P2WPKH (Native SegWit)

Introduced with SegWit in BIP141, P2WPKH provides significant fee savings.

Structure

scriptPubKey: OP_0 <20-byte-pubkey-hash>
witness: <signature> <publicKey>

Address Generation

Characteristics

  • Size: 42 characters (bc1q + 39 chars)
  • Input size: ~68 vB
  • Output size: 31 vB
  • Encoding: Bech32

P2WSH (Pay-to-Witness-Script-Hash)

P2WSH is the SegWit version of P2SH, used for complex scripts like multisig.

Structure

scriptPubKey: OP_0 <32-byte-script-hash>
witness: <data...> <witnessScript>

Characteristics

  • Size: 62 characters (bc1q + 59 chars)
  • Input size: Variable (depends on witness script)
  • Output size: 43 vB
  • Encoding: Bech32

P2TR (Pay-to-Taproot)

Introduced in BIP341, Taproot provides the best combination of privacy, efficiency, and flexibility.

Structure

Key path spend:

scriptPubKey: OP_1 <32-byte-tweaked-pubkey>
witness: <signature>

Script path spend:

witness: <script input> <script> <control block>

Address Generation

Characteristics

  • Size: 62 characters (bc1p + 59 chars)
  • Input size: ~58 vB (key path)
  • Output size: 43 vB
  • Encoding: Bech32m

Comparison

Transaction Size and Fees

TypeInput (vB)Output (vB)Relative Cost
P2PKH14834100% (baseline)
P2SH-P2WPKH913262%
P2WPKH683146%
P2TR584339%

Feature Comparison

FeatureP2PKHP2SHP2WPKHP2TR
MultisigNoYesVia P2WSHYes (MuSig)
Fee efficiencyLowMediumHighHighest
PrivacyLowMediumMediumHigh
Script flexibilityNoYesLimitedHigh
EncodingBase58Base58Bech32Bech32m

Best Practices

For New Wallets

  1. Default to P2WPKH for single-sig (best balance of compatibility and fees)
  2. Use P2TR when Taproot support is widespread
  3. Avoid P2PKH for new addresses (higher fees)

For Compatibility

  • Support receiving on all address types
  • Prefer SegWit (bc1q) for sending when possible
  • Some older services only support legacy addresses

Address Validation

Always validate addresses before sending:

  • Check length and prefix
  • Verify checksum (Base58Check or Bech32)
  • Confirm network (mainnet vs testnet)

Summary

Bitcoin address types have evolved to provide:

  • P2PKH: Original format, highest fees
  • P2SH: Script flexibility, moderate fees
  • P2WPKH: Native SegWit, lower fees
  • P2TR: Taproot, lowest fees and best privacy

Choose the appropriate type based on your use case, required features, and compatibility needs.