On this page
When you download a large file, clone a code repository or check a crypto payment, a computer must confirm that the data is exactly right. A Merkle tree lets it check one piece against a single short fingerprint, the root hash, and the maths is simple enough to do by hand.
What is a Merkle tree?
A Merkle tree (also called a hash tree) is a binary tree in which each leaf holds the hash of one data block and each parent holds the hash of its two children joined together. The idea is Ralph C. Merkle's: his US patent 4,309,569, "Method of providing digital signatures", was filed in 1979 and granted on 5 January 1982, and it describes an "authentication tree" (Google Patents).
A hash function turns any input into a short, fixed-length output; a cryptographic one makes finding two inputs with the same output infeasible in practice. The Certificate Transparency standard states the rule exactly: a leaf is SHA-256(0x00 ‖ data) and an internal node is SHA-256(0x01 ‖ left ‖ right), where ‖ means "joined end to end" (RFC 6962, section 2.1).
How do you build an 8-leaf Merkle tree?
Take eight data blocks, A to H; lowercase letters are their hashes. For clarity we leave out the 0x00 and 0x01 prefixes.
Leaves: a = hash(A), b = hash(B), and so on up to h = hash(H).
Level 1: ab = hash(a ‖ b), cd = hash(c ‖ d), ef = hash(e ‖ f), gh = hash(g ‖ h).
Level 2: abcd = hash(ab ‖ cd) and efgh = hash(ef ‖ gh).
Root: root = hash(abcd ‖ efgh).
That is 8 leaf hashes plus 4 + 2 + 1 = 7 internal hashes, 15 in all, in log₂ 8 = 3 levels above the leaves. If n is not a power of two, RFC 6962 splits the list at k, the largest power of two below n (RFC 6962). Only the root must come from someone you trust.
How can you prove one block belongs using only log₂ n hashes?
A friend holds only the trusted root. To show them block C is in the tree, send C, its position, and three hashes: d, ab and efgh. They compute:
c = hash(C)
cd = hash(c ‖ d)
abcd = hash(ab ‖ cd)
hash(abcd ‖ efgh), and accept C only if this equals the trusted root.
RFC 6962 calls this list the audit path, "the shortest list of additional nodes in the Merkle Tree required to compute the Merkle Tree Hash" (RFC 6962, section 2.1.1). Each step climbs one level, so the proof holds one sibling per level: log₂ n hashes when n is a power of two. Eight blocks need 3 hashes; 1,048,576 blocks need just 20. That is the logarithmic growth from Big O notation and growth rates.
Why does changing any block change the root?
Change one byte of C. Then c changes, so cd, abcd and the root change: the edit ripples up one path to the top. Keeping the old root would mean finding a different input with the same hash at some level, which a cryptographic hash is built to prevent.
The same path finds the damage. If one block differs, compare the two children of the root, follow the one that differs, and repeat; after log₂ n steps you reach the changed block.
Where are Merkle trees used in Git, BitTorrent and blockchains?
Bitcoin. The Bitcoin paper says transactions are "hashed in a Merkle Tree" with "only the root included in the block's hash"; a block header without transactions is about 80 bytes, so at one block every 10 minutes the headers grow by 4.2 MB a year (Bitcoin white paper, sections 7 and 8). A light client keeps only headers and asks for the Merkle branch: the proof you just built.
BitTorrent v2. Each file's "pieces root" is the root of a Merkle tree with a branching factor of 2, built from 16 KiB blocks and hashed with SHA2-256 (BEP 52). Peers exchange hashes to check pieces against it.
Git. Git names each file's content (a blob) by its SHA-1 hash, a tree object lists the SHA-1 hashes of its blobs and subtrees, and each commit points to the top-level tree (Pro Git, Git Objects). Git's trees are not binary, but edit one file and every folder hash above it changes.
How should you practise Merkle trees?
Draw the 8-leaf tree from memory and label all 15 hashes.
Write the proof for every leaf and check that each has exactly 3 hashes.
Build a 5-block tree with the RFC 6962 split (k = 4). Work out why E's proof is just abcd, while A needs b, cd and e.
Contrast this use of hashing with hash tables, collisions and load factor, and this tree with binary heaps and priority queues.
If a step felt shaky, the Fermi Concept Library covers every concept in physics, chemistry, biology, mathematics and computing, and the Fermi Problem Library has a step-by-step solver that explains the reasoning.



