PSBT Binary Format
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:
-
Hex:
70 73 62 74 ff -
ASCII:
psbt\u00ff
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:
-
Global Map: Contains the unsigned raw transaction and overall metadata.
-
Input Maps: One map for every input being spent. Contains signatures, scripts, and the full previous transaction.
-
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:
-
[Key Length]\u2192[Key Type]\u2192[Key Data]\u2192[Value Length]\u2192[Value Data] -
The map ends with a
0x00byte (the separator).
4. Why Base64?
While the format is binary, it is almost always displayed in Base64 for humans. This makes it easy to:
-
Copy and paste into a wallet.
-
Convert into a QR code for "Air-Gapped" communication.
-
Share via email or messaging apps without file corruption.
| 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.
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: