A Merkle tree is a data structure that summarizes a large set of data with a single fixedsize fingerprint. You build it
A Merkle tree is a data structure that summarizes a large set of data with a single fixed-size fingerprint. You build it from the bottom up. First, hash each piece of data, such as a transaction, to get the "leaves." Next, pair up the leaves, concatenate each pair, and hash the result to get the next level up. Repeat this until one hash remains. That final hash is the Merkle root. Because a cryptographic hash function is deterministic and collision-resistant, the root depends on every leaf and on the order the leaves appear in.
Any change to the data shows up in the root. If you alter one transaction, its leaf hash changes. That changes its parent, then the parent's parent, and so on, all the way to the root. Someone who holds only the root can therefore tell whether a full dataset matches the one the root was computed from. You don't need to compare the data item by item. You compare one hash.
The main benefit is efficient proof of membership. Suppose you want to prove that a transaction is in a set of N items. You don't need to send the whole set. You send the transaction plus the "sibling" hash at each level on the path from its leaf to the root. That is about log₂(N) hashes, called a Merkle proof or Merkle branch. The verifier hashes the transaction, combines the result with each sibling hash in turn, and checks that the final value equals the known root. For a block with 4,000 transactions, that is about 12 hashes instead of 4,000 transactions.
Bitcoin puts a Merkle root of all of a block's transactions in each block header. The header is only 80 bytes, and it contains the version, the previous block hash, the Merkle root, a timestamp, the difficulty target, and a nonce. Miners do proof-of-work by hashing this header. Since the Merkle root commits to every transaction, the proof-of-work protects the whole transaction set while the header stays small and fixed in size. Changing any transaction after the fact would change the root, change the header hash, and invalidate the work.
This design is what makes lightweight clients possible. The paper that introduced Bitcoin describes Simplified Payment Verification (SPV). An SPV client downloads only block headers, not full blocks. To confirm that a payment was included in a block, it asks a full node for the transaction and its Merkle branch. It checks that the branch hashes up to the root in a header it already has. It also checks that the header is part of the most-work chain, and it can count the confirmations built on top of it. This lets phones and other low-resource devices verify payments without storing the full blockchain, which is hundreds of gigabytes.
There are a few details and caveats. If a level has an odd number of nodes, Bitcoin duplicates the last hash to complete the pair. This quirk allowed a known vulnerability (CVE-2012-2459), where different transaction lists could produce the same root. Bitcoin also applies SHA-256 twice at each step. The Merkle tree also keeps the block structure modular, because nodes can verify, prune, and relay transactions without handling everything at once. Later upgrades built on the same idea. Segregated Witness added a separate witness commitment, and Taproot uses Merkle trees to commit to the alternative spending scripts of an output. Taproot reveals only the script path that is actually used.