TeachMeBitcoin

Little Endian vs. Big Endian

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

Little Endian vs. Big Endian

One of the most confusing aspects of Bitcoin data serialization is the way multi-byte numbers are stored in memory. This is known as Endianness. Bitcoin uses both "Big Endian" and "Little Endian" depending on what part of the protocol you are looking at.

1. What is Endianness?

Imagine you have the hex number 12 34 56 78. How should you write it in a file?

2. Why does Bitcoin use Little Endian?

Satoshi Nakamoto developed Bitcoin on x86 computers (Intel CPUs).

3. The "Block Hash" Flip

This is the most common pitfall for new developers.

Example: If a block hash starts with many zeros in an explorer: 00000000000000000005... In the raw data of the block file, those zeros are actually at the End: ...05000000000000000000

4. What is flipped?

5. Byte-Level vs. Bit-Level

Important: Endianness only applies to the Order of Bytes, not the order of bits inside a byte.

Data Type Endianness Human Order Raw Byte Order
Amount Little 100 64 00 00 00
TXID Little Starts with 00 Ends with 00
IP Address Big 1.2.3.4 01 02 03 04

In the next section, we will discuss Byte Serialization in Raw Transactions.

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