A Merkle tree, or binary hash tree, involves taking large amounts data and making it more manageable to process. In the case of blockchain technology , merkle trees are used to organize regular transactions such as: “Alice sent Bob 5 Bitcoins”, in a way that utilizes fewer resources.

“T A ” represents a normal transaction, like the one described above. These transactions are hashed individually to give their corresponding hash value. For example, “T D ” is put through a hash function to give its corresponding hash value of “H D “. In the case of Bitcoin, the hash function it uses is the SHA-256 hash function. If you are unsure of what a hash function is, then I suggest that you read my previous article on what the SHA-256 function is, and how it relates to Bitcoin.

After each transaction has been individually hashed to produce its corresponding hash value, the new hash values are combined with an adjacent partner to be hashed once again. For example, the hash values “H C ” and “H D ” are combined and hashed to produce the hash “H CD “. In the above example, there are 8 transactions with their own corresponding hash values. However, if there had been an odd number of hash values, such as 7, then the 7th hash is simply paired with itself and hashed to produce a new hash value. That is, “H H ” and “H H ” would be combined to give “H HH “.

This process is repeated until the last hash value is obtained. This value is known as the merkle root. In the above example, the merkle root is labelled “H ABCDEFGH “. The merkle root is 32 bytes in size and is then taken to be placed inside the block header; it represents a summary of all transaction data.

Advantages of a merkle tree structure include:

Easy to check if transactions have been tampered with

Uses fewer resources

Easy to verify if a specific transaction has been added to the block

Tamper proof: One benefit of organising transactions in a merkle tree structure is, it becomes straightforward to verify that no transaction in a block has been tampered with. If for example the transaction: “T H ” were to be changed “T XYZ ”, the corresponding hash value would be different. Therefore, when the resulting hash is combined with its adjacent hash partner, the ensuring hash would be different. This leads to a completely different merkle root, and therefore, it can concluded that if the merkle root were ever to change, one or more transactions must have been tampered with.

Uses fewer resources: Organizing transactions in a merkle tree structure uses fewer resources than hashing transactions in one bundle and inserting that into the block header. Even though technically a cryptocurrency such as Bitcoin would still be able to function if all transactions were to be organized in this way, it would still use up too many resources. This method of handling transactions may result in fewer nodes on the Bitcoin network due to the higher costs of handling extra resources. Therefore, leading to a less decentralized Bitcoin network.