What Is the Merkle Tree of Bitcoin?

In order to fully understand what a merkle tree is, you first have to understand what a cryptographic hash function is. Cryptographic hashes produce a fixed-size and unique hash value from variable-size transaction input. The SHA-256 computational algorithm is an example of a cryptographic hash.

The purpose of the merkle root is to be a sort of signature of all the transactions contained within a single block. If we have this block which contains eight transactions which Keifer Kif labels Ta – Th (this is also represented as Ha – Hp below). Ta – Th represent all the transactions on the block. We have these eight transaction and first step of forming the merkle tree is to perform a hash on each of the transactions. So each transaction goes through a hash function to get the transaction hash or the transaction ID, which is useful in itself for identifying a transaction. We don’t stop there. We got a lot more hashing to do. We take our transaction IDs or the transaction hashes that have been created and then we put them into pais and perform a hash on that pair of hashes. Once the hashes have paired up they get paired up again and hash them again. This keeps happening until all of the transactions meet at a single hash. This single hash is called the merkle root (it’s the root of the entire merkle tree).

What then happens is that the merkle root is put into the block header which is the part of the bitcoin block that gets hashed in the process of mining. By having the merkle root in the block header, this makes the transactions tamper proof so if you were to go to an old transaction and try to change the value of it, that change would be reflected in the hash of that transaction ( the transaction ID) and that change would cascade up the merkle tree to the merkle root, changing the value of the merkle root and thus invalidating the block. Everyone will be able to see that your transaction is not valid because it’s not on a valid block because you’ve tampered with it somehow.