TeachMeBitcoin

VarInt vs. Fixed-Width Integers

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

VarInt vs. Fixed-Width Integers

Why does Bitcoin use VarInt for some numbers and fixed-width (Uint32/Uint64) for others? The choice depends on the predictability and the mathematical role of the data.

1. When Fixed-Width is Better

Transaction Amounts (Satoshis) are always 8-byte fixed-width integers.

2. When VarInt is Better

Script Lengths are always VarInts.

3. The Performance Trade-off

4. Disk Space vs. Processing Speed

In 2009, Satoshi prioritized disk space. Every byte counts on a hard drive. In modern high-frequency trading, processing speed is prioritized. Bitcoin remains a "Disk-First" protocol. The consensus is that it is better to have a slightly slower parser if it means the blockchain is 30% smaller.

5. Summary Table

Field Type Why?
Amount (Sats) Fixed (8b) Safety and Jump-Access
Locktime Fixed (4b) Predictable range
Input Count VarInt Usually 1-2, occasionally 100+
ScriptData VarInt Extreme size variance

In the next section, we will discuss BIP154 & CompactSize History.

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