TECHNICAL_DOC // BLOCK / BLOCK-SERIALIZATION
BLOCK
SERIAL-
IZATION
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.
BLOCK_STRUCTURE — TOP_LEVEL
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]
BLOCK_HEADER_BYTE_MAP
| Offset | Field | Size | Description |
|---|---|---|---|
| 0–3 | 01000000 | 4 bytes | Version (LE) — currently 1, 2, or signalling bits |
| 4–35 | 00000...0000 | 32 bytes | Previous block hash (LE display order) |
| 36–67 | 3BA3ED...5E4A | 32 bytes | Merkle root of all transactions |
| 68–71 | 29AB5F49 | 4 bytes | Timestamp (LE Unix epoch seconds) |
| 72–75 | FFFF001D | 4 bytes | Bits — compact encoding of the target |
| 76–79 | 1DAC2B7C | 4 bytes | Nonce — incremented by miner |
SEGWIT_BLOCK_TRANSACTION_FORMAT
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)
COMPACT_BLOCK_RELAY
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.
INTERACTIVE — TRY IT YOURSELF
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.
BLOCK STRUCTURE REFERENCE
| SECTION | FIELD | BYTES | ENCODING | NOTES |
|---|---|---|---|---|
| HEADER (80 bytes) |
version | 4 | LE int32 | block version; bit-flags for fork/">soft fork signalling |
| prev_block | 32 | LE bytes | SHA256d hash of previous block header | |
| merkle_root | 32 | LE bytes | Merkle root of all txids in block | |
| time | 4 | LE uint32 | Unix timestamp (±2 hours of network time) | |
| bits | 4 | LE uint32 | Compact target encoding | |
| nonce | 4 | LE uint32 | Miner-chosen PoW value | |
| TX LIST | tx_count | varint | 1–9 B | number of transactions (coinbase first) |
| transactions | variable | raw | legacy or SegWit serialized |
HEADER DISSECTOR
PARSE 80-BYTE BLOCK HEADERclick fields to inspect
FULL BLOCK DISSECTOR
PARSE FULL BLOCK HEXheader + transactions
BITS → TARGET DECODER
DECODE COMPACT BITS FIELD → 256-BIT TARGET