A tree of hashes that lets two machines find exactly which data differs, fast.
A Merkle tree is a tree of hashes. Each leaf is the hash of one block of data, and each parent is the hash of its two children. The top hash is called the root, and it stands for all the data below it.
A hash turns any data into a short fixed-size fingerprint. The same data always gives the same hash, and even a tiny change gives a completely different one. Hashes are the base of a Merkle tree.
To build the tree, first split the data into blocks and hash each block. These are the leaves. Then join the leaves in pairs: hash the two child hashes together to make a parent. Keep going upward until one hash is left, the root. If a level has an odd number of nodes, systems usually repeat or promote the last one.
| Part | What it is | Role |
|---|---|---|
| Leaf | Hash of one data block | The lowest level. A changed block changes its leaf. |
| Internal node | Hash of the two child hashes put together | Summarises a whole branch with one value. |
| Root | The single hash at the top | Stands for all the data. Compared first. |
| Merkle proof | The sibling hashes along one path from a leaf to the root | Lets someone check one block without the rest of the data. |
| Variation | Idea | Trade-off |
|---|---|---|
| Binary Merkle tree | Each node has two children | Simple, with proofs about log2(n) hashes long. |
| Wider tree (more children per node) | Hash many children at once | Shallower tree, but longer proofs at each level. |
| Merkle DAG | Nodes can be shared between several parents (Git, IPFS) | Same data stored once, and links form a graph, not a strict tree. |
| Sparse Merkle tree | A huge fixed-size tree where most leaves are empty | Allows proof that a key is absent, at some extra cost. |
Each leaf hash is hash(block). Each parent is hash(left child + right child). Hashes here are a small 16-bit view of a 32-bit hash, so they are short enough to read. Real systems use long hashes such as SHA-256. Try changing 1 block, then 4 blocks, then none, and compare how many hashes are needed.
| Term | Meaning in easy words |
|---|---|
| Hash | A short fixed-size fingerprint of some data. The same data always gives the same hash |
| Leaf | A node holding the hash of one data block |
| Parent / internal node | A node holding the hash of its children's hashes |
| Root hash | The single hash at the top that stands for all the data |
| Merkle proof (audit path) | The sibling hashes needed to check one leaf against the root |
| Anti-entropy | A background process that finds and repairs differences between replicas |
| Collision | Two different inputs with the same hash. Strong hashes make this practically impossible |
| Tamper-evident | Any change to the data changes the root, so changes cannot go unseen |
| Content addressing | Naming data by the hash of its content |
| Merkle DAG | A Merkle structure where nodes can be shared by several parents (Git, IPFS) |
| Block / chunk | A piece of the data covered by one leaf |
| Choice | We gain | We lose |
|---|---|---|
| Small blocks | Pinpoint small differences, copy little | A bigger tree, more hashes to store and compute |
| Large blocks | A small tree | A tiny change forces a large block to be copied |
| Strong hash (SHA-256) | Safe against tampering | Slower than a simple hash |
| Fast simple hash | Very cheap to compute | Fine for sync, not safe against an attacker |
| Keep the tree up to date on every write | Always ready to compare | Extra work on each write |
| Build the tree only when needed | No cost on writes | A slow first comparison, because all data must be read |