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
| Type | Prefix | Example Start | Introduced |
|---|---|---|---|
| P2PKH | 1 | 1BvBMSEYstW... | 2009 (Genesis) |
| P2SH | 3 | 3J98t1WpEZ7... | 2012 (BIP16) |
| P2WPKH | bc1q | bc1qw508d6q... | 2017 (BIP141) |
| P2WSH | bc1q | bc1qrp33g0q... | 2017 (BIP141) |
| P2TR | bc1p | bc1p5cyxnux... | 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
| Type | Input (vB) | Output (vB) | Relative Cost |
|---|---|---|---|
| P2PKH | 148 | 34 | 100% (baseline) |
| P2SH-P2WPKH | 91 | 32 | 62% |
| P2WPKH | 68 | 31 | 46% |
| P2TR | 58 | 43 | 39% |
Feature Comparison
| Feature | P2PKH | P2SH | P2WPKH | P2TR |
|---|---|---|---|---|
| Multisig | No | Yes | Via P2WSH | Yes (MuSig) |
| Fee efficiency | Low | Medium | High | Highest |
| Privacy | Low | Medium | Medium | High |
| Script flexibility | No | Yes | Limited | High |
| Encoding | Base58 | Base58 | Bech32 | Bech32m |
Best Practices
For New Wallets
- Default to P2WPKH for single-sig (best balance of compatibility and fees)
- Use P2TR when Taproot support is widespread
- 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.
Related Topics
- Bitcoin Wallets - Introduction to Bitcoin wallets
- HD Wallets - Hierarchical deterministic key derivation
- Coin Selection - How address types affect transaction fees
- Address Generation - Developer guide to address generation
