---
title: "Merkle Tree — definition | Nuri Glossary"
description: "A hash tree that lets anyone verify inclusion with a handful of hashes."
lang: "en"
type: "glossary-term"
canonical: "https://nuri.com/glossary/merkle-tree"
---

# Merkle Tree

A hash tree that lets anyone verify inclusion with a handful of hashes.

## Basically

A Merkle tree combines transaction hashes in pairs until one hash remains for the whole Bitcoin block. You can use it to prove a transaction is in that block with only a small amount of data.

## Key Takeaways

- A Merkle tree is a binary hash tree that compresses all transactions in a Bitcoin block into a single 32-byte root hash stored in the block header. You can verify transaction inclusion without downloading the entire block.
- Merkle proofs let lightweight clients verify that a transaction belongs to a block using only O(log n) hashes. For a block with 4,000 transactions, a proof requires just 12 hashes instead of all 4,000.
- Merkle trees do more than commit to transactions. Taproot uses Merklized Abstract Syntax Trees (MAST) to commit to multiple spending conditions while revealing only the one actually used.

## What Is a Merkle Tree?

A Merkle tree, also called a hash tree, is a data structure where every leaf node contains the hash of a data block and every non-leaf node contains the hash of its two children. Ralph Merkle patented the concept in 1979, and the structure produces a single root hash that cryptographically commits to all the data in the tree. Changing any leaf changes the root hash, making the tree a tamper-evident summary of its contents.
Each Bitcoin block contains a Merkle tree built from its transactions. The tree's root, called the Merkle root, sits in the 80-byte block header alongside the previous block hash, timestamp and difficulty target. You can verify that a specific transaction is in a block without having every transaction because you only need a small "proof path" through the tree.
Merkle trees separate block verification from block size. They make lightweight verification possible even when blocks contain thousands of transactions. Without Merkle trees, every node would need to download and store every transaction to verify any single one.

## Constructing the Tree

Merkle tree construction follows a bottom-up process. Each transaction is first serialised and double-SHA256 hashed to produce a 32-byte transaction ID (txid), and these txids form the leaf layer. Adjacent pairs of hashes are then concatenated and hashed together to produce the next layer, repeating until a single root remains.
A block with four transactions (A, B, C, D) produces the tree below. The tree pairs their hashes until one root remains.
A five-transaction block requires the last hash (E) to be duplicated to form a pair: Hash(EE). This duplication keeps the tree complete and binary at every level.

## The Merkle Root in Block Headers

The 80-byte Bitcoin block header contains six fields: version, previous block hash, Merkle root, timestamp, difficulty target and nonce. The Merkle root is the only field that commits to the block's transaction content. Miners iterate over the nonce and other fields to find a valid proof-of-work, but changing any transaction changes the Merkle root and invalidates the block.
A full node can validate the 80-byte block header and then independently verify that any claimed transaction belongs to that block through a Merkle proof. The header chain alone, without full block data, is sufficient to establish the longest proof-of-work chain.

## Merkle Proofs

A Merkle proof, also called an inclusion proof or authentication path, demonstrates that a specific transaction is part of a block's Merkle tree. The proof consists of the sibling hashes at each level from the target leaf up to the root. You combine these with the target transaction's hash to recompute the root and compare it against the block header.
The proof for Tx C in the four-transaction tree above contains two hashes. These sibling hashes let you recompute the root.
Merkle proof size scales logarithmically, so n transactions require log₂(n) hashes of 32 bytes each. A block with 4,096 transactions needs only 12 hashes, or 384 bytes, to prove inclusion of any single transaction. This efficiency makes Simplified Payment Verification (SPV) practical for mobile wallets and embedded devices.

## SPV Clients and Lightweight Verification

Satoshi Nakamoto described Simplified Payment Verification in Section 8 of the Bitcoin whitepaper. SPV clients download only block headers of 80 bytes each instead of full blocks of up to 4 MB with SegWit. They request a Merkle proof from a full node when they need to verify a payment and check it against the header chain.
The entire Bitcoin header chain from genesis to block 900,000 is roughly 72 MB, small enough for a smartphone. Merkle proofs let these lightweight clients verify transactions without trusting a server, although they still trust that the longest chain represents the most proof-of-work. SPV offers a practical trade-off between full validation and resource constraints.

## Taproot and MAST

Taproot, activated in November 2021, uses a Merklized Abstract Syntax Tree (MAST) to commit to multiple Bitcoin Script spending conditions within a single output. Each possible spending path is a leaf in a Merkle tree. Spending reveals only the used path and its Merkle proof, while all other conditions remain hidden.
Taproot improves privacy and efficiency because a complex multisig arrangement with multiple fallback conditions looks identical on-chain to a simple single-signature spend when the key path is used. A script-path spender reveals only the relevant script and a compact Merkle proof, not the full set of conditions. The Taproot and Schnorr signatures explainer covers how Taproot uses Schnorr signatures alongside MAST in more detail.

## Commitment Schemes and Data Integrity

Merkle trees also serve as general-purpose commitment structures beyond transaction inclusion. OP_RETURN outputs can embed a Merkle root that commits to arbitrary off-chain data, compressing thousands of documents, records or state transitions into a single 32-byte on-chain footprint. Anyone with the original data and a proof path can later verify inclusion against the on-chain root.
Timestamping services, audit trails and layer-2 protocols use this pattern to anchor state to Bitcoin. The UTXO set itself is not stored as a Merkle tree in Bitcoin Core, but some alternative implementations commit to it through a hash-based structure for fast synchronisation. The UTXO model vs. account model comparison explains how Bitcoin's UTXO model operates.

## CVE-2012-2459: Duplicate Transaction Vulnerability

Bitcoin's original Merkle tree construction had a subtle vulnerability. Odd-length levels duplicate the last hash, so two different transaction lists can produce the same Merkle root. A block with transactions [A, B, C, D] and a crafted block with transactions [A, B, C, D, D, D], where the duplicates match the padding, could yield the same root hash.
An attacker could exploit this with an "invalid" block containing duplicate transactions that matched the Merkle root of a valid block. Nodes that cached block rejections by hash could then be tricked into permanently rejecting the valid block. Bitcoin Core 0.6.1 patched CVE-2012-2459 after private disclosure with a straightforward fix: after constructing the Merkle tree, nodes reject the block if any two transactions are identical.

## Second Preimage Attacks on Short Trees

A standard Merkle tree is vulnerable to second preimage attacks if internal nodes and leaf nodes are not domain-separated, because an attacker could present an internal node, the concatenation of two child hashes, as a leaf and potentially forge a proof for data not in the original tree. Bitcoin mitigates this naturally because transaction data has a very different structure from the 64-byte concatenated hash pairs used at internal levels, so valid Bitcoin transactions cannot be confused with internal nodes in practice. Generic Merkle tree implementations outside Bitcoin typically add a domain-separation prefix, 0x00 for leaves and 0x01 for internal nodes, to prevent this class of attack.

## SPV Security Limitations

Merkle proofs verify inclusion but not validity. An SPV client can confirm that a transaction exists in a block with sufficient proof-of-work, but it cannot verify that the transaction is actually valid, such as whether its inputs are unspent or its scripts evaluate correctly. A dishonest miner with significant hashpower could theoretically include invalid transactions in a block and provide valid Merkle proofs for them to SPV clients.
Lightweight verification carries an inherent trade-off. Full nodes validate every transaction and every script, while SPV clients trade this completeness for efficiency and rely on the economic assumption that miners will not sacrifice block rewards to attack SPV users. Fraud proofs and more advanced light-client protocols have been proposed to narrow this gap but are not yet deployed in Bitcoin.

## Computational and Storage Overhead

Merkle tree construction requires n - 1 hash operations for n leaves, one per internal node. A block with 4,000 transactions therefore means roughly 4,000 additional double-SHA256 computations during block assembly and verification. These costs are modest compared to overall validation, but the tree must be rebuilt from scratch if any transaction changes, which affects mining software that frequently updates the transaction set in candidate blocks.
Some proposals discussed in the Bitcoin development community would replace the Merkle tree with more efficient accumulator structures or switch to a different tree topology, but these would require a consensus-level change. The current Merkle tree construction remains a simple and well-understood component of the Bitcoin protocol despite its known quirks.
The glossary entry is for informational purposes only and does not constitute financial or investment advice. You should always do your own research before using any protocol or technology.
Part of the [Nuri glossary](https://nuri.com/glossary), which defines 1876 Bitcoin, Lightning, wallet, stablecoin and payment terms.
