Merkle Tree
A Merkle tree hashes pieces of data in pairs, layer by layer, until one root hash is left. Blockchains use it to prove a transaction is in a block without downloading the whole block.
A block can hold thousands of transactions, yet its header has room for just one hash that stands for all of them. That hash is the Merkle root, the top of a Merkle tree. Because any change to any transaction changes the root, a short chain of hashes is enough to prove that one transaction is in a block. The same trick lets light wallets check payments and lets exchanges show customers that their balance was counted in a proof of reserves.
- Category
- Cryptocurrency and Blockchain
- Reading time
- 6 min
- Also called
- Hash tree, Merkle root, Merkle proof
- Updated
A Merkle tree in plain words
A Merkle tree is built by hashing data in pairs, then hashing those results in pairs again, until a single hash remains.1 That last hash is the Merkle root, and in Bitcoin the data at the bottom are the transactions of one block.1
Each block header stores the Merkle root, so changing any transaction in the block would change the root and break the header.2 See Block.
The Bitcoin whitepaper used a Merkle tree so that old transactions could be pruned while the block's hash stayed valid, and so that light users could check payments with a short Merkle branch.3 The structure is named after Ralph Merkle, whose 1980 paper the whitepaper cites.3
How a Merkle root is built and used, step by step
Hash every transaction
Each transaction is hashed to give its ID, the txid. These are the leaves of the tree.2
Hash the leaves in pairs
Two neighbouring txids are joined and hashed together, giving one hash per pair.2
Handle an odd count
In Bitcoin, if a level has an odd number of hashes, the last one is paired with a copy of itself.2
Repeat until one hash is left
Each level halves the number of hashes until only the Merkle root remains.1
Put the root in the header
The block header stores the root, so it commits to every transaction in the block.1
Prove one item with a branch
To prove a transaction is included, supply the sibling hashes on its path to the root; anyone can rehash them and compare.4
Worked examples
Example 1 — Four transactions
Tree sizeA hypothetical block holds 4 transactions: A, B, C and D. How many hashes does the tree have, and how many does a proof for C need?
| Leaves (txids) | 4 |
| Pair hashes (AB, CD) | 4 ÷ 2 = 2 |
| Root (ABCD) | 2 ÷ 2 = 1 |
| Hashes in the tree | 4 + 2 + 1 = 7 |
| Proof for C | 2 hashes (D and AB) |
The verifier hashes C with D, then that result with AB, and checks it equals the root in the header.
Example 2 — An odd number of transactions
Odd countA hypothetical block holds 5 transactions. Bitcoin pairs a lone hash with a copy of itself.2
| Level 0 (txids) | 5 |
| Level 1 | (5 + 1) ÷ 2 = 3 |
| Level 2 | (3 + 1) ÷ 2 = 2 |
| Level 3 (root) | 2 ÷ 2 = 1 |
Duplicating the last hash keeps every level in pairs, so the tree always ends in a single root.
Example 3 — Headers for a light wallet
StorageThe whitepaper estimated that a header without transactions is about 80 bytes, with a block every 10 minutes.3
| Blocks per hour | 6 |
| Bytes per day | 80 × 6 × 24 = 11,520 |
| Bytes per year | 11,520 × 365 = 4,204,800 |
| About | 4.2 MB a year |
A light wallet keeps only these headers and asks for Merkle branches, which is why it can run on a phone.3
Merkle proof vs. downloading the block
| Aspect | Merkle proof | Full block download |
|---|---|---|
| Data needed | Headers plus a short branch of hashes | Every transaction in the block |
| What it proves | The transaction is in the block | The whole block is valid |
| Who uses it | Light wallets, proof-of-reserves checks | Full nodes |
| Main weakness | Trusts that the longest chain is honest | Needs more storage and bandwidth |
Where Merkle trees are used
Block headers
Bitcoin headers carry a Merkle root that covers every transaction in the block.1
Light wallets
Simplified payment verification checks a transaction with headers and a Merkle branch.1 See Crypto Wallet.
Ethereum state
Ethereum headers hold state, transactions and receipts roots built from a Merkle Patricia trie.4 See Ethereum (ETH).
Proof of reserves
Exchanges put customer balances into a Merkle tree so each customer can check their own entry.5 See Proof of Reserves.
Advantages and disadvantages
Advantages
- One short hash commits to a whole set of data.
- A proof grows only by one hash each time the data set doubles.
- Any change to the data changes the root, so tampering shows.
- Lets light clients check payments without storing full blocks.
Disadvantages
- A proof shows inclusion, not that the data itself is valid.
- Light clients still trust the chain with the most work.
- Proof of reserves built on it covers balances, not hidden debts.
- Implementation details, like odd-count rules, differ between chains.
Going deeper
Read as far as you need. Each level builds on the one before it.
A fingerprint of fingerprints
Beginner
Simplified payment verification
Intermediate
The whitepaper describes how a user can verify a payment without a full node: keep the headers of the longest proof-of-work chain and get the Merkle branch that links the transaction to its block.3
This check is reliable only while honest nodes control the network; an attacker with more hash power could fool a light client for as long as the attack lasts.3 See 51% Attack.
Patricia tries and proof of reserves
Advanced
Ethereum stores key-value data such as account balances in a Merkle Patricia trie, whose root changes whenever any value changes, so a known root lets anyone verify a claimed value with the hashes along its path.4
In Kraken's proof of reserves, an independent accountant builds a Merkle tree of anonymised client balances, and each client recomputes their own leaf and follows the sibling hashes up to the published root.5
Kraken also lists the limits: the check cannot prove exclusive control of keys or rule out borrowed funds and hidden encumbrances.5
Common mistakes
Thinking a proof validates the transaction
A Merkle branch shows the transaction is in a block; it does not re-check every rule like a full node does.3
Confusing the root with the block hash
The root covers the transactions; the block hash is the hash of the whole header, which includes the root.
Reading proof of reserves as solvency
Inclusion in the tree says your balance was counted, not that all liabilities are covered.5
Assuming all chains build trees alike
Bitcoin pairs transactions in a binary tree, while Ethereum uses a Merkle Patricia trie for its state.4
Check your understanding
Test yourself before moving on. Each answer comes with an explanation.
Key points to remember
- A Merkle tree hashes data in pairs until one root hash is left.
- Each Bitcoin block header stores the Merkle root of its transactions.
- A short branch of sibling hashes proves one item is in the set.
- Light wallets use headers and Merkle branches instead of full blocks.
- Proof-of-reserves checks use Merkle trees, but they do not prove solvency.
Frequently asked questions
What is a Merkle root?
Why does a light wallet need Merkle proofs?
Who invented the Merkle tree?
Further learning
- Block
Where the Merkle root sits in a block header.
- Proof of Reserves
How exchanges use Merkle trees to show balances.
- Sidechain
Sidechain pegs rely on SPV proofs built on Merkle branches.
Sources
This article is written in our own words. The sources below support the specific facts, rules and figures marked with a number in the text. Links open the original publisher’s page.
- Bitcoin Project (developer.bitcoin.org). Glossary (opens in a new tab) Checked .
- Bitcoin Project (developer.bitcoin.org). Block Chain developer guide (opens in a new tab) Checked .
- Satoshi Nakamoto. Bitcoin: A Peer-to-Peer Electronic Cash System (opens in a new tab) Checked .
- ethereum.org. Merkle Patricia Trie (opens in a new tab) Checked .
- Kraken. Proof of Reserves (opens in a new tab) Checked .
Educational content, not financial advice. Examples use hypothetical prices and simplified costs; actual fees, margin rules and regulations vary by broker, market and country. We are not affiliated with any publisher linked above. Last reviewed . Report an error or request a source credit.