Intermediate Lesson 4 4 min read

The block on the inside: header, Merkle root, and nonce

Eighty bytes of header summarize thousands of transactions and answer the question that the miner is trying to solve.

A Bitcoin block carries a few thousand transactions and is close to two megabytes. What the miner is actually trying to solve is eighty bytes and could be written by hand on a line of paper. Everything else is represented in that line.

These eighty bytes are the header, and it has six fields. Four bytes for the version, indicating which rules the block follows. Thirty-two bytes with the hash of the previous header, which is what makes the chain a chain. Thirty-two bytes with the merkle root, which summarizes the transactions. Four bytes for the date and time. Four bytes with the difficulty target at that moment. And four bytes for the nonce, the number the miner varies.

The merkle root deserves attention because it is what allows thousands of transactions to fit into thirty-two bytes. The method is by Ralph Merkle, patented in 1979, and works by pairing: the hash of each transaction is calculated, the hashes are paired two by two and the hash of each pair is calculated, and this is repeated until only one remains. This last one is the root. Changing a single satoshi in any transaction changes its hash, changes the hash of the pair, and continues changing everything up to the root.

A thousand threads braided two by two end in a single cable, and pulling the cable tests them all.

From this structure comes a huge bonus. To prove that a transaction is inside a block, you don't need the block: just the path of hashes that goes from that leaf to the root. In a block with four thousand transactions, there are twelve hashes. This is why a mobile wallet can confirm a payment without downloading the entire blockchain.

Now, what the miner does. They assemble the block, calculate the root, fill in the header, and calculate the hash of the eighty bytes. If the result is smaller than the target, they win. If not, they change the nonce and try again. Each attempt is an independent bet, and there is no shortcut — it's the same one-way nature of the hash function, now used as a lottery.

But four bytes of nonce give just over four billion possibilities, and a modern machine exhausts this in a fraction of a second. When it runs out, the miner needs to change something else in the header to have a new draw. They adjust the date by a few seconds, and especially tweak the first transaction of the block, the one that pays the reward to themselves: any change there alters its hash, changes the merkle root, and provides four billion new attempts.

Once the attempts are exhausted, they rewrite the first line and restart the entire search.

This first transaction is special in other ways. It has no inputs because it creates coins out of nothing according to the emission rule and also collects all the fees from the block. And it has a free field where the miner can write whatever they want — it was there that Satoshi left the newspaper headline in the genesis block, and it's there that major miners sign the blocks they produce to this day.

What the miner cannot change is the hash of the previous block. It is given, ready-made, and ties the new block to the exact tip of the chain. Altering a transaction in an old block would change the root of that block, change the hash of its header, and the next block would point to a place that doesn't exist — along with all those that came after.

The new link is forged at the tip of what is already there. What is already there is not touched.

Notice the balance: finding the nonce costs an absurd amount of energy, and verifying the result costs a single calculation. Any node, on a common computer, redoes the hash of those eighty bytes in microseconds and knows if the work was done. It is this asymmetry — expensive to produce, cheap to verify — that supports the entire network.

What remains to be explained is the target, that four-byte field that decides how small the hash needs to be. It changes automatically every 2,016 blocks and is what keeps the network's clock ticking every ten minutes regardless of how many machines are running. In the next lesson, the difficulty.