• Hash256
  • Hash160
  • Reverse Bytes
  • Hexadecimal
  • Satoshis


An easy to share format of a locking script.

An address is what you give to people so that they can “send” you bitcoins.

When someone receives it, they can create a specific locking script based on the type of address you have given them.

Try it!

Public Key Hash
Script Hash

How do you create an address?

Well, that depends on how you’d like your bitcoins to be locked up.

But in general, an address contains:

  1. Some specific data that you would like included in the lock. For example, your public key hash.
  2. A prefix to indicate what kind of lock to create.
  3. And a checksum to help with catching any typos.

Finally, all of that gets converted to Base58, which makes it a little more user-friendly.

Pay To PubKey Hash (P2PKH)

P2PKH: This is a typical address that locks bitcoins to a public key (or to be more precise: the public key hash).

As mentioned, we append a prefix and prepend a checksum to our hashed public key, then encode it all in base58.

Now we have an address to give to people.


When someone creates a locking script from this address, they just decode the base58 to retrieve the hash160 inside it, then create a P2PKH lock around it, as follows:

So the prefix indicates what kind of lock to create, and the hash160 tells them what to put inside it.

Pay To Script Hash (P2SH)

P2SH: This lock includes the hash of a script. We provide the actual locking script later on (when we come to unlock it), which allows us to construct complex locking scripts without others having to worry about the details of it.

Same as before, except this time we’re including the hash of a script, and using the prefix 05 to indicate a P2SH.


And this is what a P2SH looks like:


As mentioned, the prefix you use will indicate the type of locking script to create.

Here are a list of common address prefixes:

Prefix Locking Script Leading Character Example Address
00 P2PKH 1 1AKDDsfTh8uY4X3ppy1m7jw1fVMBSMkzjP
05 P2SH 3 34nSkinWC9rDDJiUY438qQN1JHmGqBHGW7
6F P2PKH (testnet) m / n ms2qxPw1Q2nTkm4eMHqe6mM7JAFqAwDhpB
C4 P2SH (testnet) 2 2MwSNRexxm3uhAKF696xq3ztdiqgMj36rJo


The prefix will also alter the leading character of an address, so you can tell what kind of locking script has been used by just looking at the address itself.

Why do we use addresses?

An address is a short-hand way of writing locking scripts in a human-readable way. - echeveria (on IRC)

If we didn’t use addresses, we would have to send other people complete locking scripts, like this:

76a914662ad25db00e7bb38bc04831ae48b4b446d1269888ac # P2PKH script

But by using addresses, we can just send something like this instead:


They both achieve the same result, but addresses give us a more user-friendly format to pass around. Not to mention the fact that they contain a checksum, which means that errors can be detected if someone writes an address incorrectly.


Note: This code requires the checksum.rb and base58_encode.rb functions.

def hash160_to_address(hash160, type=:p2pkh)
  prefixes = {
    p2pkh: '00',         # 1address - For standard bitcoin addresses
    p2sh:  '05',         # 3address - For sending to an address that requires multiple signatures (multisig)
    p2pkh_testnet: '6F', # (m/n)address
    p2sh_testnet:  'C4'  # 2address

  prefix = prefixes[type]
  checksum = checksum(prefix + hash160)
  address = base58_encode(prefix + hash160 + checksum)

  return address

hash160 = '662ad25db00e7bb38bc04831ae48b4b446d12698'
puts hash160_to_address(hash160) # 1AKDDsfTh8uY4X3ppy1m7jw1fVMBSMkzjP

By Greg Walker,

Last Updated: 21 Jul 2020
  • 21 Jul 2020: redirected and renamed files from /guide/ to /technical/
  • 21 Jul 2020: renamed /guide/ to /technical/
Back to Top

Hey there, it's Greg.

I'll let you know about cool website updates, or if something seriously interesting happens in bitcoin.

Don't worry, it doesn't happen very often.