Merkle Tree in Blockchain

Merkle Tree in Blockchain

If you are reading this blog, it means you are aware about Blockchain and eager to know about Merkle tree concept. Merkle tree is one of the most important concept that you need to know and be aware about before you proceed further in Blockchain. Merkle tree concept is not for Bitcoin Blockchain rather it is applicable to all of the Blockchain platforms.


What is Merkle Tree ?

In this blog, we will explain you what is Merkle tree and how it is used in Blockchain. Merkle tree concept is not new, it is there from long time but it came to lime light with Blockchain technology. Let's deep dive and understand about it. Below diagram represent Merkle tree so let’s try to understand it step by step.

Merkle Tree in Blockchain

Merkle Tree in Blockchain

Here T stands for Transaction and H stands for Hash of input. There can be n number of transaction at given time. For this example, we have taken 4 transactions for this first scenario.

Hash Algorithm

In Merkle tree, transactions are hashed to get their corresponding hash value. Different hash algorithm used in different blockchain platform, like in Bitcoin SHA-256 is used to generate hash and in Ethereum Keccak-256. Hash output is nothing, it is long string for any input that is not human readable.


“hello” string hash is 2CF24DBA5FB0A30E26E83B2AC5B9E29E1B161E5C1FA7425E73043362938B9824 when you use SHA-256

Hash for “hello” string is 1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8 when you use Keeck-256.

When you hash Transaction-A, you get Hash for that transaction and same for other transaction as well. As you see in the diagram, we get total 4 hashes for 4 transactions. Now these hashes are combine in pair to create new hash e.g. If you combine Hash-A and Hash-B, you will get new Hash-AB. So, you get two hashes in next step which is Hash-AB and Hash-CD. Now these hashes are also combined in pair and new hash got generated until we get single hash. E.g. Hash-AB and Hash-CD combined to generate Hash-ABCD.

This Hash-ABCD is known as Merkle root.

Now there can be scenario when we have odd transactions instead of even transactions. That is explained in below diagram where we have only 3 transactions. As you see in below diagram for transaction- C we have Hash-C but we don’t have any other Hash available to be in pair with Hash-C so in that scenario, Hash-C is taken two times, combined and generate a new Hash that is Hash-CC.

Benefits of Merkle Tree

Now question come about benefits of Merkle tree and usage of Merkle tree in Blockchain. Answer to that question is below.

  • Data Integrity: Merkle tree maintain data integrity as you can easily verify is someone has tempered the data as if anyone try to change anything in the Merkle tree, that change will generate new hash and in turn Merkle root will be different.
Merkle Tree Data Integrity
  • Need little memory / disk space and proofs are computationally easy and fast.
  • Easy transaction queries: When you use Merkle tree and need to check if one transaction is included or not then you need not to download the full blocks in Blockchain, you can easily traverse through the tree and check the transaction. Light client in Bitcoin and Ethereum works on that principals only where these clients only download block header not the full blocks in Blockchain.
Inquire Now
close slider