BitcoinMachine
TECHNICAL_DOC // BLOCK / BLOCK-SERIALIZATION
BLOCK
SERIAL-
IZATION
A Bitcoin block is transmitted and stored as a flat binary stream following a precise byte-level format. Every field is encoded in little-endian, with variable-length fields preceded by a CompactSize integer. Understanding this format is essential for parsing raw blocks, building indexers, and implementing protocol-level tools.
COMPLETE BLOCK FORMAT
┌─ Block Header 80 bytes (always fixed) │ Version 4 bytes (LE uint32) │ Previous Block Hash 32 bytes (LE, inner byte order) │ Merkle Root 32 bytes (LE, inner byte order) │ Time 4 bytes (LE uint32 Unix timestamp) │ Bits 4 bytes (LE uint32 compact target) │ Nonce 4 bytes (LE uint32) ├─ Transaction Count 1–9 bytes (CompactSize varint) └─ Transactions[] variable [SegWit tx: includes marker 0x00, flag 0x01, witness]
OffsetFieldSizeDescription
0–3010000004 bytesVersion (LE) — currently 1, 2, or signalling bits
4–3500000...000032 bytesPrevious block hash (LE display order)
36–673BA3ED...5E4A32 bytesMerkle root of all transactions
68–7129AB5F494 bytesTimestamp (LE Unix epoch seconds)
72–75FFFF001D4 bytesBits — compact encoding of the target
76–791DAC2B7C4 bytesNonce — incremented by miner
transaction/">SegWit Transaction Marker & Flag
BIP 144
SegWit introduced two extra bytes in the transaction format. Non-SegWit nodes see blocks without witness-data/">witness data (stripped); SegWit nodes receive the full form including witness.
Legacy transaction format: [version][inputs][outputs][locktime] SegWit transaction format (BIP 144): [version][marker=0x00][flag=0x01][inputs][outputs][witness][locktime] The marker byte 0x00 is what signals SegWit to old nodes. Old nodes interpret it as "0 inputs" → valid empty tx (anyone-can-spend) SegWit nodes read flag 0x01 → continue to parse witness fields WTXID: hash of full serialization including witness TxID: hash of serialization WITHOUT marker, flag, and witness (ensures TxID is not malleable by witness changes)
BIP 152 — Compact Blocks
BANDWIDTH OPTIMIZATION
Full nodes that have already seen transactions in the mempool don't need the full block data. Compact Block Relay sends only short TxID references; missing transactions are requested separately.
cmpctblock message: Header: 80 bytes (full block header) Nonce: 8 bytes (for short ID generation) Prefilled txns: critical transactions sent in full (usually coinbase) Short IDs: 6 bytes each (truncated SipHash of WTXID) High-bandwidth mode: nodes pre-announce what they're working on Low-bandwidth mode: wait for block, then request missing txs Result: reduces block relay from ~1 MB to ~10–50 KB for well-connected nodes
Compact blocks dramatically reduce the variance in block propagation time, shrinking the orphan rate and allowing larger effective block capacity.
TERMINOLOGY_INDEX
CompactSize
Variable-length integer encoding used for counts (inputs, outputs, script length) in Bitcoin's wire format.
Little-Endian
Byte order where the least significant byte comes first. All multi-byte integers in Bitcoin use LE on the wire.
WTXID
Witness TxID. The double-SHA256 of the full SegWit transaction including witness data.
BIP 144
The BIP defining the new serialization format for SegWit transactions, adding marker, flag, and witness fields.
BIP 152
Compact Block Relay. A protocol optimization transmitting blocks using short transaction IDs to reduce bandwidth.
blk.dat
Raw block data files stored on disk by Bitcoin Core, each containing up to 128 MB of serialized blocks.
BLOCKS / SERIALIZATION
Block Serialization
A Bitcoin block has two parts: an 80-byte header and a transaction list. The header commits to the previous block, the Merkle root of all transactions, a timestamp, the difficulty target (bits), and the proof-of-work nonce. The block hash — SHA256d of the 80-byte header — must be below the target.
SECTIONFIELDBYTESENCODINGNOTES
HEADER
(80 bytes)
version4LE int32block version; bit-flags for fork/">soft fork signalling
prev_block32LE bytesSHA256d hash of previous block header
merkle_root32LE bytesMerkle root of all txids in block
time4LE uint32Unix timestamp (±2 hours of network time)
bits4LE uint32Compact target encoding
nonce4LE uint32Miner-chosen PoW value
TX LIST tx_countvarint1–9 Bnumber of transactions (coinbase first)
transactionsvariablerawlegacy or SegWit serialized
PARSE 80-BYTE BLOCK HEADERclick fields to inspect
PARSE FULL BLOCK HEXheader + transactions
DECODE COMPACT BITS FIELD → 256-BIT TARGET