No history yet

Block Header Structure

The 80-Byte Heart of Bitcoin

The core of Bitcoin's Proof-of-Work is not the entire block, but a compact, 80-byte data structure: the block header. This is the exact piece of data that miners repeatedly hash in search of a valid solution. Its fixed size and predictable structure are essential for efficient mining, as it allows specialized hardware to perform trillions of hashes per second without needing to process the entire list of transactions for each attempt.

The entire mining process boils down to finding a nonce that, when combined with the other five fields and hashed, produces a result below a specific target.

Byte Order Matters

Before breaking down the header's fields, we have to address the most common stumbling block for developers: endianness. Computers can store multi-byte numbers in two ways. Big-endian stores the most significant byte first (like we read numbers), while stores the least significant byte first. Bitcoin's protocol specifies little-endian byte order for most header fields. When you pull block data from an explorer, hashes are usually displayed in a human-readable big-endian format. But for hashing and serialization, you must work with the raw, little-endian byte arrays. Mismatching the byte order is the number one cause of hash verification failures in custom implementations.

A Field-by-Field Breakdown

The 80-byte header is a concatenation of six distinct fields, each with a specific size and purpose. When serialized for hashing, they are placed one after another in a precise sequence.

FieldSize (Bytes)Data TypeEndianness
Version432-bit Unsigned IntegerLittle-Endian
Previous Block Hash32Hash (256-bit Integer)Little-Endian
Merkle Root32Hash (256-bit Integer)Little-Endian
Timestamp432-bit Unsigned IntegerLittle-Endian
nBits (Difficulty)432-bit Unsigned IntegerLittle-Endian
Nonce432-bit Unsigned IntegerLittle-Endian

Version (4 bytes): This field originally specified the block validation rules. Today, it's primarily used by miners to signal their readiness for proposed software upgrades, a system known as "version bits" or BIP 9. It's a standard 4-byte integer, encoded in little-endian format.

Previous Block Hash (32 bytes): This is the hash of the preceding block's header. It's the component that explicitly links blocks together, forming the chain. Like the other fields, it's a 32-byte little-endian value inside the header structure, even though block explorers display it as a big-endian hex string for readability.

Merkle Root (32 bytes): This is the cryptographic fingerprint of all transactions included in the block. It's the root hash of a Merkle tree built from the individual transaction IDs. This design is incredibly efficient. It allows miners to commit to an entire set of transactions with just a single 32-byte hash. They can then modify the nonce and re-hash the 80-byte header without ever touching the transaction data itself. This separation of header and transactions is fundamental to how lightweight clients can verify payments without downloading the entire blockchain.

Lesson image

Timestamp (4 bytes): A Unix epoch timestamp representing when the miner started hashing the block. It's a 4-byte little-endian integer. There are rules governing its validity; for instance, it must be greater than the median timestamp of the previous 11 blocks and cannot be more than two hours in the future.

nBits (4 bytes): This field encodes the Proof-of-Work difficulty target for the block in a compact format. The target is the 256-bit number that a valid block hash must be less than or equal to. Instead of storing the full 32-byte target, nBits represents it using a mantissa and an exponent, similar to scientific notation for floating-point numbers.

Nonce (4 bytes): Short for "number used once," this is the 4-byte field that miners iterate through during the mining process. They change the nonce, re-serialize the 80-byte header, and perform a double-SHA256 hash. If the resulting hash is below the target specified by nBits, they have found a valid block and broadcast it to the network. If not, they increment the nonce and try again.

To get a clearer picture of serialization, here's how you'd construct the 80-byte header in pseudocode before hashing:

header_hex = (
    version_little_endian +
    prev_block_hash_little_endian +
    merkle_root_little_endian +
    timestamp_little_endian +
    nbits_little_endian +
    nonce_little_endian
)

// Convert hex string to raw bytes
header_bytes = hex_to_bytes(header_hex)

// Hash the 80-byte structure
block_hash = sha256(sha256(header_bytes))

This 80-byte structure contains everything needed to verify the integrity of the blockchain: a link to the past, a commitment to the present transactions, and the proof of work that secured it.