Skip to content
buybitcoinsmart

Glossary / Addresses & keys

P2PKH address

Also known as Pay-to-Public-Key-Hash, P2PKH output.

Definition
P2PKH is the output type that locks coins to a 20-byte hash of a public key, so the key itself stays hidden until the moment you spend.

Pay to public key hash is the script pattern behind every address that begins with 1. Its locking script is exactly 25 bytes and runs five operations when the coins move. Because the output commits to a fingerprint rather than to the key, an unspent P2PKH output tells an observer nothing about the public key behind it.

How it works

A P2PKH output carries one locking script, always the same shape: OP_DUP OP_HASH160 <20-byte hash> OP_EQUALVERIFY OP_CHECKSIG. That 20-byte hash is HASH160, meaning RIPEMD-160 applied to the SHA-256 of the compressed public key, which is how a 33-byte key becomes a 20-byte commitment.

Spending supplies two items in the input's scriptSig: a signature, then the public key. Execution proceeds in order. OP_DUP copies the key, OP_HASH160 reduces the copy to 20 bytes, OP_EQUALVERIFY compares that against the committed value and aborts if they differ, and OP_CHECKSIG verifies the signature against the transaction. Both checks have to pass; failing either makes the whole transaction invalid, not merely that input.

The sizes follow from the layout. A P2PKH output costs 34 bytes on chain, made of an 8-byte amount, a 1-byte length and the 25-byte script. An input costs roughly 148 vbytes, because a DER-encoded ECDSA signature runs 71 to 72 bytes, the compressed key adds 33 more, and all of it sits outside the witness where each byte is weighted four times.

Where you see it

Every address starting with 1 is a P2PKH address, which covers most coins that moved before SegWit activated at block 481,824 in August 2017. Block explorers label the type on each output, so you can check what you are looking at without decoding anything.

The detail worth carrying away is when your public key becomes public. Until you spend, the chain holds only the hash. The first spend publishes the key in the scriptSig, permanently. If you then reuse that address, any later balance sits behind a key that is already visible to everyone, which removes a layer of protection that cost you nothing. That is a privacy problem immediately, and it is the reason the long-running discussion about future attacks on elliptic curve cryptography focuses on reused and already-spent addresses rather than on fresh ones.

Practically: let your wallet hand you a new receive address for every payment, and let the change go to a fresh address too. Modern software does both by default.

P2PKH address vs P2WPKH

P2PKH and P2WPKH commit to the same thing and cost very different amounts. Both lock coins to a 20-byte HASH160 of a single compressed public key, and both are unlocked by one signature from that key. What separates them is where the unlocking data is written. P2PKH keeps the signature and key in the scriptSig, counted at four weight units per byte; P2WPKH moves them into the witness, counted at one. That is why the same secret can produce a 1 address and a bc1q address that look nothing alike, hold coins independently, and differ by more than a factor of two in what they cost to empty.

Not to be confused with

Frequently asked questions

Is a P2PKH address the same as a legacy address?

In practice yes, with a wrinkle. Every P2PKH address starts with 1 and is a legacy address, but people often stretch the word legacy to cover Base58 strings starting with 3 as well, which are P2SH rather than P2PKH.

When does my public key become visible on the chain?

The first time you spend from the address. Until then the chain holds only a 20-byte hash. After that spend the key is public forever, which is one reason wallets hand you a fresh address for every payment.

Read next

Related terms

More in Addresses & keys