Reviewed Aug 2026
DE
BA-06 · LESSON 04

P2PKH and P2SH

KEY DEFINITIONS

Terms used in this lesson

P2PKH
Pay to Public Key Hash, a legacy Bitcoin output template that commits to the hash of a public key.
P2SH
Pay to Script Hash, a legacy Bitcoin output template that commits to a redeem script.
Hash160
SHA-256 followed by RIPEMD-160, producing the 20-byte hash used by several Bitcoin spending conditions.
Witness
Signatures, scripts, or other data supplied to satisfy a Bitcoin output’s spending condition.
CHECKSIG
The Bitcoin Script operation that checks whether a signature is valid for the required public key and transaction message.
OP_DUP
A Bitcoin Script operation that copies the top stack item.
OP_HASH160
A Bitcoin Script operation that replaces the top stack item with its Hash160 digest.
OP_EQUALVERIFY
A Bitcoin Script operation that compares two values and immediately fails if they differ.

Legacy templates separate address-friendly commitments from revealed spending scripts.

65 min Difficulty 2/5 Not started

Loading lesson visuals...

01

Learn the idea

P2PKH means Pay to Public Key Hash. Its output commits to HASH160 of a public key and a spend reveals the public key plus signature. P2SH means Pay to Script Hash. Its output commits to HASH160 of a redeem script and a spend reveals that script plus data that satisfies it. Both are legacy templates whose scriptSig participates in the transaction's non-witness serialization.

GUIDED EXPLANATION1/5 ideas inspected
1

Create a P2PKH commitment

The output script duplicates and hashes the supplied public key, compares it with a committed 20-byte key hash, then checks a signature.

Inspect each idea before the worked example.
The worked example follows the explanation

Inspect every idea above to open it.

Important distinctionP2SH makes Bitcoin consensus understand the business meaning of the redeem script.

Consensus verifies the script's bytecode behavior. Labels such as escrow or recovery are interpretations used by wallets and people.

02
FINISH LEARNING FIRST

The questions unlock after every required learning activity

Inspect every guided idea, open the worked example, rebuild its mechanism, and complete the deterministic lesson tool. Your progress is saved automatically.