The 0x in Publish0x - BTC Addresses
TheNextWeb BTC fork Image

The 0x in Publish0x - BTC Addresses

By bar93 | KBC | 10 Mar 2020

Image source:

The concept of using a long address code for payments are a function similar to e-mail. For instance - PayPal uses e-mail addresses to send money between registered users. BTC wallets do the same in conceptual terms. I am not going to show you how to generate different kinds of addresses. If you need one, you can generate it from Electrum Wallet. Don't lose it. Always ensure you keep your seed phrase/mnemonic phrase/private keys or get a hardware wallet.

Bitcoin address is a 160-bit hash of the public portion of a public/private ECDSA keypair. Using public-key cryptography, you can "sign" data with your private key and anyone who knows your public key can verify that the signature is valid. Pubkey Privkey


P2PKH addresses begin with the number '1' and are also known as version 1 addresses or legacy addresses. P2PKH is an abbreviation of "Pays To PubKey Hash". Legacy address transactions are usually large and fees are higher than other types of addresses.


A "Pay To Script Hash", my personal favorite. They begin with the number '3' and has more functions than legacy addresses. P2SH have a multisig protocol which specifies that multiple digital signatures are required to authorize a transaction. Funds can be sent to P2PKH and bech32 addresses from this wallet. It makes use of a redeem script in order to get paid. If someone having a P2SH address hasn't paid you, it might be an issue with the multisig, segwit (Segregated Witness) or consensus layer.

P2SH Scripts


Addresses are longer than legacy or P2SH. They are also known as 'bc1-addresses'. This type of address is not so highly adopted than the two named above - see the adoption stats here. This makes it difficult to do transactions over exchanges. Some exchanges accept payments from bech32 but do not allow payment to bech32. It is relatively 'new' {December'17}. Bech32 addresses are cheaper to spend from and offer better protection against typing errors. Unspent outputs save 22 bytes as their ScriptSigs are empty instead of 0x0014{20-byte-key-hash}. So, the amount of saving is insignificant. The newer checksum algorithm is faster with a higher probability of error detection guaranteed. For more information, you can read this thread.

How addresses are generated

The correct way of generating bitcoin addresses must be followed, otherwise you will lose your funds in the process. You will generally lose it when funds are paid into an invalid/non-existent wallet address. This is an example of how the process works:

  • Step 0 - Having a private ECDSA key
  • Step 1 - Take the corresponding public key generated with it (33 bytes, 1 byte 0x02 (y-coord is even), and 32 bytes corresponding to X coordinate)
  • Step 2 - Perform SHA-256 hashing on the public key
  • Step 3 - Perform RIPEMD-160 hashing on the result of SHA-256
  • Step 4 - Add version byte in front of RIPEMD-160 hash (0x00 for Main Network)

(note that below steps are the Base58Check encoding, which has multiple library options available implementing it)

  • Step 5 - Perform SHA-256 hash on the extended RIPEMD-160 result
  • Step 6 - Perform SHA-256 hash on the result of the previous SHA-256 hash
  • Step 7 - Take the first 4 bytes of the second SHA-256 hash. This is the address checksum
  • Step 8 - Add the 4 checksum bytes from stage 7 at the end of extended RIPEMD-160 hash from stage 4. This is the 25-byte binary Bitcoin Address.
  • Step 9 - Convert the result from a byte string into a base58 string using Base58Check encoding. This is the most commonly used Bitcoin Address format

Code Source:

For an overview on how the Public Key is converted to a BTC address, check out this process diagram.

PubKey to Address Conversion


It's complicated, but I often find myself coming back to the basics to determine where my BTC went, how to get paid in BTC, or where the 0x fits in.


Firm believer in liberty and commercial freedom. Crypto enthusiast.


This blog solely provides information on the blockchain and cryptocurrencies

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.