TeachMeBitcoin

Script Serialization & Addresses

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

Script Serialization and Addresses

A Bitcoin Address is simply a human-readable representation of a ScriptPubKey. Understanding how the script is serialized into bytes—and how those bytes become an address—is key to understanding the network's identity system.

1. Serialization in the Output

In the raw binary of a transaction, a script is prefixed by its length using a VarInt.

Example of a P2PKH output:

  1. Value: 00e1f50500000000 (1 BTC)

  2. Length: 19 (25 bytes in hex)

  3. Script: 76a914[20-byte hash]88ac

2. From Script to Address

The network doesn't actually use "Addresses" internally. It only uses ScriptPubKeys. Your wallet converts the script into an address for your convenience using specific encoding rules.

3. The "Silent" Script

When you give someone your address, you are effectively giving them the blueprint for a ScriptPubKey.

  1. You give Address 1ABC....

  2. The sender's wallet decodes 1ABC... back into the pattern OP_DUP OP_HASH160 <Hash> OP_EQUALVERIFY OP_CHECKSIG.

  3. The wallet places that raw byte pattern into the transaction output.

4. Why Encapsulate?

We use addresses instead of raw scripts to:

  1. Reduce Errors: Checksums prevent you from sending money to a mistyped address.

  2. Shorten Data: Base58/Bech32 are more compact than raw hex.

  3. Future Proofing: We can change the underlying script pattern (like moving from Legacy to Taproot) while keeping a similar address format.

Format Internal Representation External Representation
Script Raw Opcodes \u0026 Hash 76a914...88ac
Address Human-readable string 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa

In the final section, we will build a Python ScriptPubKey Decoder to identify these patterns.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!