Home › Glossary › P2SH

P2SH

Also called: Pay to Script Hash, pay-to-script-hash, 3 address, P2SH address, redeem script, nested SegWit, P2SH-P2WPKH.

P2SH (Pay to Script Hash), defined in BIP 16, locks bitcoin to the hash of a script. Its addresses start with 3, and it carried most early multisig.

P2SH, Pay to Script Hash, lets a sender pay to a short hash of a script instead of the script itself. The receiver reveals the full script, called the redeemScript, only when spending. P2SH addresses start with 3.

How it works

BIP 16, by Gavin Andresen, defines the output script:

OP_HASH160 <20-byte script hash> OP_EQUAL

To spend, the scriptSig provides the signatures (or other data) followed by the serialized redeemScript. Nodes check that the script hashes to the stored value, then run it against the remaining data. BIP 13 defines the address: Base58Check with version byte 5 on mainnet (a leading 3) and 196 on testnet (a leading 2). The P2SH rules were enforced from April 2012 as a soft fork.

Why it mattered

Before P2SH, a sender had to put a long multisig script into their own transaction and pay for its size. BIP 16 moved that cost and complexity to the receiver: any policy, however complicated, fits behind a fixed 20-byte hash that is easy to paste or scan as a QR code. P2SH became the standard home for multisig (see BIP 45 and BIP 67), limited to 15 compressed keys because the redeemScript must fit in 520 bytes.

Nested SegWit

P2SH can also wrap a SegWit program. P2SH-P2WPKH and P2SH-P2WSH (BIP 141) gave older wallets a 3... address they could pay, while the receiver still got SegWit savings. BIP 49 defines the m/49' path and ypub keys for wrapped single-key wallets. Native SegWit addresses are cheaper to spend, but P2SH remains valid everywhere. More in the address types guide.

BIPs that define P2SH

Related terms

  • Multisig: Multisig (multi-signature) locks bitcoin so that M of N chosen keys must sign to spend it, for example any 2 of 3 keys kept in different places.
  • P2WSH: P2WSH (Pay to Witness Script Hash) is the native SegWit output for scripts such as multisig: a 32-byte script hash with a 62-character bc1q address.
  • P2WPKH: P2WPKH (Pay to Witness Public Key Hash) is the native SegWit single-key output type. Its bc1q addresses are always 42 characters long.
  • Base58Check: Base58Check is the original text encoding for Bitcoin addresses and keys: Base58 characters plus a 4-byte checksum from double SHA-256.
  • Soft fork: A soft fork is a backward-compatible change to Bitcoin's consensus rules that only tightens them, so old nodes still accept the new blocks.

Learn more

Guides