TeachMeBitcoin

PSBT Binary Format

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

PSBT Binary Format and Magic Bytes

If you open a PSBT file in a text editor, it usually looks like a long string of random characters (Base64). However, underneath that encoding is a strictly structured binary format.

1. The Magic Bytes

Every PSBT begins with a specific "Magic" identifier to help software recognize the file type:

If a file does not start with these 5 bytes, it is not a valid BIP 174 PSBT.

2. Key-Value Architecture

The internal structure of a PSBT is a series of Key-Value maps. It is divided into three sections:

  1. Global Map: Contains the unsigned raw transaction and overall metadata.

  2. Input Maps: One map for every input being spent. Contains signatures, scripts, and the full previous transaction.

  3. Output Maps: One map for every output being created. Contains information for the signer to verify "change" addresses.

3. Map Serialization

Each entry in a map follows a simple pattern:

4. Why Base64?

While the format is binary, it is almost always displayed in Base64 for humans. This makes it easy to:

Section Common Key Types Purpose
Global 0x00 (Unsigned TX) The foundation of the spend
Input 0x02 (Partial Sig), 0x04 (Sighash Type) Collecting the math proof
Output 0x01 (Redeem Script) Verifying the destination

In the next section, we will discuss Hardware Wallet Integration.

☕ 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!