Skip to content
DonateБГ

Bitcoin Script

P2PKH

P2PKH locks a bitcoin output to the hash of a public key. It is the classic address type that starts with 1. See the hex and the stack steps.

By Dimitar Zurnov · Updated 4 Nov 2026
Adapted from Learn Me a Bitcoin by Greg Walker.

P2PKH, short for pay to public key hash, is the lock behind the classic Bitcoin address, the one that starts with 1. It locks an output to the HASH160 of a public key rather than to the key itself. To spend, you show the full public key and a signature made with its private key. P2PKH is a legacy type. The SegWit type P2WPKH works the same way, and it is now the usual choice for new payments.

What does a P2PKH locking script look like?

A P2PKH lock: duplicate the key, hash it, check the hash, then check the signature. The P2PKH locking script OP_DUP: copy the top item 76 OP_HASH160: hash the copy, 20 bytes out a9 push the next 20 bytes 14 the public key hash 55ae5168…2eb64105 OP_EQUALVERIFY: check both match 88 OP_CHECKSIG: check the signature ac 25 bytes: 1 + 1 + 1 + 20 + 1 + 1.
Each row is one element of the script. The public key hash is the part that changes from one lock to the next.

The scriptPubKey holds a public key hash between a fixed set of opcodes. The whole script is 25 bytes:

76a91455ae51684c43435da751ac8d2173b2652eb6410588ac

76 is OP_DUP, and a9 is OP_HASH160. 14 pushes the next 20 bytes, which is the hash. 88 is OP_EQUALVERIFY, and ac is OP_CHECKSIG. Output 1 of 0b6461de422c46a221db99608fcbe0326e4f2325ebf2a47c9faf660ed61ee6a4 is one such lock.

What does the unlocking script look like?

The scriptSig pushes a signature and then the public key:

483045022100c233c3a8a510e03ad18b0a24694ef00c78101bfd5ac075b8c1037952ce26e91e02205aa5f8f88f29bb4ad5808ebc12abfd26bd791256f367b04c6d955f01f28a7724012103f0609c81a45f8cab67fc2d050c21b1acd3d37c7acfd54041be6601ab4cef4f31

48 pushes the 72-byte signature, and 21 pushes the 33-byte public key, which starts with 03 because it is compressed. Input 0 of 40e331b67c0fe7750bb3b1943b378bf702dce86124dc12fa5980f975db7ec930 is a spend of this form.

The key may be compressed (33 bytes) or uncompressed (65 bytes). What matters is that it hashes to the value in the lock. A compressed key does not match an uncompressed hash, and the other way round.

How does a P2PKH script run?

The scriptSig runs first, then the scriptPubKey. The script overview has an animated stack that shows each step. In short:

  1. The scriptSig pushes the signature, then the public key.
  2. OP_DUP copies the public key.
  3. OP_HASH160 hashes the copy.
  4. The lock pushes the 20-byte hash from the output.
  5. OP_EQUALVERIFY checks that the two hashes match, then removes both. If they differ, the script fails.
  6. OP_CHECKSIG checks the signature against the public key and leaves OP_1 if it is valid.

Step 5 is the extra work compared with P2PK. It proves that the key shown in the spend hashes to the key the output was locked to.

What is the address for P2PKH?

P2PKH has an address. It is the Base58Check encoding of the public key hash, with a one-byte prefix in front: 00 on mainnet and 6f on testnet. Mainnet addresses start with 1, and testnet addresses start with m or n.

How a public key becomes a P2PKH address: hash it, add a prefix and checksum, then Base58 encode. From public key to address public key, uncompressed, 65 bytes 04283338ffd784c1…4d8cde20 HASH160 public key hash, 20 bytes bc73550c1612ee81155d29254217cbd60084a6d1 prefix and checksum prefix, hash and checksum 00bc73550c1612ee81155d29254217cbd6 0084a6d1691c58b9 Base58 encode address, starts with 1 1JBSCVF6VM6QjFZyTnbpLjoCJTQEqVbepG
A worked example from an uncompressed public key. The address is for illustration, so do not send coins to it.

The example uses an uncompressed public key that starts with 04283338. Its HASH160 is bc73550c1612ee81155d29254217cbd60084a6d1. The prefix and hash are followed by a 4-byte checksum, the first four bytes of the double SHA-256 of what came before. Base58 encoding then gives the address 1JBSCVF6VM6QjFZyTnbpLjoCJTQEqVbepG.

A wallet that receives a 1 address decodes it, takes out the hash, and builds this lock. The address page explains the other address types.

Why does P2PKH hash the public key?

Hashing gives a shorter address. Base58 encoding a compressed public key gives an address of 51 characters. Hashing the key first gives 34 characters, which is easier to copy and share. Hashing also keeps the public key out of sight until the coins are spent. The checksum makes a typing mistake easy to catch.

Until around 2016, most wallets paid addresses with P2PKH locks. Sending to an address that starts with 1 still creates this lock.

Which P2PKH transactions can you check on our explorer?

The next page, P2MS, covers locks that need several signatures. For the other address types, see the address page.

In this section: Bitcoin Script

All of Bitcoin from zero

Something look wrong? Tell us