Merkle Branch (Merkle Path)
A Merkle branch is the set of sibling hashes needed to prove a transaction's inclusion in a block's Merkle tree.
Key Takeaways
- A Merkle branch is the minimal set of sibling hashes a verifier needs to reconstruct the path from a leaf (such as a transaction hash) up to the Merkle root of a block.
- Proof size grows logarithmically: a block containing 4,000 transactions requires only about 12 hashes (384 bytes) to prove any single transaction's inclusion, rather than transmitting all 4,000 transaction IDs.
- Merkle branches are used by SPV clients to verify payments without downloading full blocks, and by mining pools in the Stratum protocol to let miners compute new block headers independently.
What Is a Merkle Branch?
A Merkle branch (also called a Merkle path or authentication path) is the ordered list of sibling hashes that, combined with a target leaf hash, allows a verifier to recompute every intermediate node up to the root of a Merkle tree. If the computed root matches the root committed in a block header, the verifier knows the leaf transaction is genuinely included in that block.
Satoshi Nakamoto described this mechanism in Section 8 of the Bitcoin whitepaper under "Simplified Payment Verification." The core insight is that a verifier does not need every transaction in a block to confirm one specific transaction: it only needs the small set of hashes along the path from the transaction up to the root. This makes lightweight verification practical even on resource-constrained devices like mobile phones.
How It Works
Bitcoin organizes all transactions in a block into a binary Merkle tree. Each leaf is the double-SHA-256 hash of a serialized transaction (its txid). Pairs of leaves are concatenated and hashed again to form parent nodes, and this process repeats until a single 32-byte Merkle root remains. That root is stored in the block header.
To build a Merkle branch for a specific transaction, a full node identifies the leaf position in the tree and collects the sibling hash at each level. The branch contains only the nodes the verifier cannot compute on its own: one sibling per level of the tree.
- Start with the target transaction hash (the leaf)
- At level 0, record whether the leaf is a left or right child, and include its sibling hash
- Hash the pair (in the correct left-right order) using double SHA-256 to produce the parent
- Move up one level and repeat: record the parent's sibling, hash together, ascend
- Continue until reaching the root; compare the computed root against the block header's Merkle root
If the two roots match, the transaction is provably included in the block. If any hash in the branch is altered or missing, the computed root will differ, and verification fails.
Logarithmic Efficiency
Because the tree is binary, its depth is ceil(log2(N)) where N is the number of transactions. A branch contains exactly one sibling hash per level, so the proof size scales logarithmically with the transaction count:
| Transactions in block | Tree depth | Sibling hashes needed | Proof size (bytes) |
|---|---|---|---|
| 16 | 4 | 4 | 128 |
| 256 | 8 | 8 | 256 |
| 1,000 | 10 | 10 | 320 |
| 4,000 | 12 | 12 | 384 |
| 65,536 | 16 | 16 | 512 |
Even in the most extreme case of a completely full block, the proof remains under a kilobyte. This is what makes lightweight transaction verification feasible without downloading the entire block.
Handling Odd Transaction Counts
When a level of the tree has an odd number of nodes, Bitcoin duplicates the last node so it can pair with itself. This padding ensures the tree is always a complete binary structure. The duplication is deterministic: any verifier rebuilding the tree from the same set of transactions will produce the same root.
Verification in Code
A simplified verification algorithm takes a transaction hash, a Merkle branch (array of sibling hashes), and position flags indicating left or right at each level:
function verifyMerkleBranch(txHash, branch, index) {
let current = txHash;
for (let i = 0; i < branch.length; i++) {
if (index & 1) {
// current node is a right child
current = doubleSHA256(branch[i] + current);
} else {
// current node is a left child
current = doubleSHA256(current + branch[i]);
}
index >>= 1;
}
return current; // compare against block header's merkle root
}The index value encodes the leaf's position in the tree as a bitmask. Each bit determines whether the current hash is a left child (bit = 0) or right child (bit = 1) at that level.
Use Cases
SPV Clients and Lightweight Wallets
Simplified Payment Verification (SPV) clients rely on Merkle branches to confirm transactions without storing the full blockchain. An SPV wallet downloads only block headers (80 bytes each) and requests Merkle branches for transactions relevant to its addresses. The original mechanism for this was BIP-37 Bloom filters, where the client sends a Bloom filter to a full node, and the node responds with merkleblock messages containing the block header and a partial Merkle tree with the matching transactions and their sibling hashes.
Modern light clients have largely moved to BIP-157/158 compact block filters, which improve privacy by letting the client download filters and test them locally. When a filter signals a potential match, the client fetches the full block and verifies the transaction against its Merkle root. The underlying Merkle branch verification remains the same in both approaches. For a deeper look at how light clients use these mechanisms, see the research article on Bitcoin light clients and SPV.
Mining Pool Coordination (Stratum Protocol)
In the Stratum mining protocol, pools send Merkle branches to miners as part of the mining.notify message. The pool splits the coinbase transaction into two parts and provides a Merkle branch containing the sibling hashes of all other transactions in the candidate block.
Each miner inserts its own extranonce values into the coinbase, hashes the reconstructed coinbase transaction, and then folds that hash up the Merkle branch to compute a fresh Merkle root. This root goes into the block header, which the miner then hashes to search for a valid proof of work. The key benefit: miners can produce billions of unique block header candidates without any additional network communication with the pool.
Stratum V2 extends this model by allowing miners to construct their own block templates, further decentralizing transaction selection. For more on how this impacts mining, see the research article on Stratum V2 mining decentralization.
Compact Block Relay
Compact block relay (BIP-152) reduces block propagation bandwidth by sending abbreviated transaction identifiers instead of full transactions. When a receiving node is missing a transaction, it can request just that transaction and verify its position using the Merkle root in the block header. The Merkle branch structure makes this selective reconstruction possible.
Cross-Chain and Layer 2 Verification
Merkle branches are also used in protocols that need to prove Bitcoin transaction inclusion to external systems. Cross-chain bridges, sidechains, and some layer 2 protocols accept Merkle branches as compact proofs that a deposit or peg-in transaction exists on the Bitcoin blockchain, without requiring the verifying chain to process every Bitcoin transaction.
Merkle Branches vs. Merkle Proofs
The terms "Merkle branch" and "Merkle proof" are often used interchangeably, but there is a subtle distinction. A Merkle branch refers specifically to the ordered list of sibling hashes. A Merkle proof is the complete verification package: the branch, plus the target leaf hash, plus position information, plus the expected root to compare against. In practice, most implementations bundle these together, so the terms overlap in everyday usage.
Risks and Considerations
Inclusion Only, Not Exclusion
A standard Merkle branch can prove that a transaction is included in a block, but it cannot prove that a transaction is absent. Proving non-inclusion requires different data structures, such as sorted Merkle trees or sparse Merkle trees. This limitation matters for protocols that need to verify that a conflicting transaction does not exist.
Trust in Block Headers
A Merkle branch alone does not guarantee security. The verifier must also trust that the block header containing the Merkle root belongs to the longest valid chain. SPV clients address this by downloading and validating the full header chain, checking that each header meets the current difficulty target. Without this chain validation, an attacker could present a valid Merkle branch under a fabricated block header.
Privacy Tradeoffs
Requesting specific Merkle branches from a full node reveals which transactions the client is interested in. The original BIP-37 approach attempted to mask this with Bloom filters, but research showed these filters leak significant information about the client's addresses. The newer compact block filter approach (BIP-157/158) addresses this by having the client download filters for every block and test them locally, eliminating the need to tell any peer which transactions it cares about.
Duplicate Transaction Vulnerability
Bitcoin's approach of duplicating the last node when a tree level has an odd count creates a theoretical vulnerability: an inner node could be crafted to look like a valid transaction hash, potentially fooling an SPV client. Bitcoin Core addressed this by rejecting blocks with duplicate transactions (since BIP-34 made coinbase transactions unique by including block height). Implementations verifying Merkle branches should be aware of this edge case.
This glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.