BitcoinMachine
TECHNICAL_DOC // GENERAL / BYTE-ORDER
BYTE
ORDER
Byte order describes the sequence in which bytes of a multi-byte value are stored or transmitted. Bitcoin uses two conventions simultaneously: little-endian in its wire protocol and on-disk format for integers, and big-endian (natural order) for display of hashes and txids. Confusing the two is a common source of bugs in Bitcoin implementations.
THE SAME VALUE, TWO REPRESENTATIONS
Value: 305,419,896 (decimal) = 0x12345678 (hex) Big-endian (most significant byte first): Memory: 12 34 56 78 Index: 0 1 2 3 ← used for: human display, network byte order Little-endian (least significant byte first): Memory: 78 56 34 12 Index: 0 1 2 3 ← used by: x86 CPUs, Bitcoin wire protocol integers
Little-Endian Fields in Bitcoin
WIRE FORMAT
Most integer fields in Bitcoin's serialization format are stored little-endian — the least significant byte comes first in the byte stream.
Block header (little-endian fields): version: 4 bytes LE e.g. 0x00000001 → stored as 01 00 00 00 time: 4 bytes LE Unix timestamp in LE bits: 4 bytes LE compact difficulty target nonce: 4 bytes LE miner's nonce Transaction (little-endian fields): version: 4 bytes LE locktime: 4 bytes LE value: 8 bytes LE satoshi amounts in outputs sequence: 4 bytes LE Hashes: internally treated as little-endian 256-bit integers (but displayed reversed — see below)
Hash Display — The Reversal Convention
DISPLAY CONVENTION
Bitcoin hashes (TxID, block-hash/">block hash) are internally stored and compared as little-endian 256-bit integers, but displayed to humans in big-endian (byte-reversed) order.
Raw hash bytes (as computed by SHA256d): e3 b0 c4 42 98 fc 1c 14 ... (32 bytes) Internal (wire/storage) representation: e3 b0 c4 42 ... Displayed to humans (block explorers): ... 42 c4 b0 e3 TxID in raw transaction: little-endian bytes TxID shown on explorer: big-endian (reversed) bytes When parsing a raw tx hex and comparing to a txid from a block explorer: REVERSE the 32 bytes first.
This reversal convention exists for historical reasons and is a persistent source of confusion. Bitcoin Core's RPC returns txids in the human-readable (reversed) form.
TERMINOLOGY_INDEX
Big-Endian
Most significant byte stored first. Used for human display of Bitcoin hashes. Also called "network byte order".
Little-Endian
Least significant byte stored first. Used for integers in Bitcoin's wire format. Native to x86/x64 CPUs.
Internal Byte Order
The byte order as it appears in serialized transactions and blocks — little-endian for integers, LE for hashes.
Display Byte Order
Hashes shown on block explorers and RPC are byte-reversed (big-endian) compared to raw serialization.