TeachMeBitcoin

Merkle Tree Fundamentals

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

Merkle Tree Fundamentals

The Merkle Root is the third field in the 80-Byte Block Header. It is a single 32-byte hash that cryptographically summarizes every single transaction included in the block.

1. What is a Merkle Tree?

A Merkle Tree is a Binary Hash Tree. Instead of hashing all transactions together in one long string (which would be inefficient), Bitcoin hashes them in pairs. * Leaf Nodes: The hashes of the individual Transaction IDs (TXIDs). * Branch Nodes: The hash of the concatenation of two child hashes. * Root Node: The final hash at the top of the tree.

2. The Pairing Process

If a block has 4 transactions ($TX_A, TX_B, TX_C, TX_D$): 1. Calculate hashes: $H_A = Hash(TX_A)$, $H_B = Hash(TX_B)$, etc. 2. Pair them: $H_{AB} = Hash(H_A + H_B)$ and $H_{CD} = Hash(H_C + H_D)$. 3. Final Root: Merkle Root $= Hash(H_{AB} + H_{CD})$.

3. Cryptographic Binding

Because the Merkle Root is included in the block header, any change to a transaction—even a single satoshi or a signature bit—will change its leaf hash. This change will ripple up the tree, changing every branch hash and ultimately changing the Merkle Root. This would make the block header (and thus the block hash) invalid.

4. Efficiency for SPV

The real power of the Merkle Tree is not just security, but efficiency. It allows a user to prove that a transaction is part of a block without needing to download the entire multi-megabyte block.

Component Role
TXID The unique identifier of a transaction.
Leaf The base level of the tree ($Hash(TXID)$).
Branch Intermediate nodes representing pairs.
Merkle Root The 32-byte summary in the block header.
IMPORTANT

A Bitcoin block can contain thousands of transactions, but the Merkle Root is always exactly 32 bytes. This constant size is what keeps the block header small and easy to process for mobile wallets.

In the next section, we will look at the Merkle Path and how proofs work.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!