On blockchain every transactions are hashed together in a tree pattern until it reaches a merkle root

On blockchain every transactions are hashed together in a tree pattern until it reaches a merkle root. Let us show you an example: Say we have four transactions. We can hash each transactions in a pair. For the sake of the example let’s just add the transaction numbers so we avoid repeating numbers. The first and the second transactions hashed together becomes three, in real life instead of three you would get hashes which are 64 digit set of numbers and letters. We do the same with the 3rd and the 4th transaction and get 3+4=7. Finally we hash the new hashes together and we get the merkle root. The whole tree pattern is called merkle tree, which is a data structure. If you change a single transaction in the Merkle tree you will get completely different merkle root. Say we change the first transaction to 6, the root will completely change and in this example the new merkle root is 15 as the image illustrates.

In real life hundreds and thousands of transactions occur in a second, which create a huge amount of data. The data is stored on the blockchain, which is a public distributed ledger. Distributed means the information is stored on computers and mobile phones scattered all around the world. Millions of users are updating the public ledger constantly. But downloading the whole database will require lot of computational power and storage. Here comes the merkle tree to save us. All transactions have their own hashes, these hashes are themselves hashed and give us the merkle root. The merkle root will change if a single data changes in any of the transactions or the order of transactions change. The miners race to produce a root hash by solving a mathematical problem. The first miner who successfully figures out the root hash gets ether as a reward. Every block has a unique root hash, which allows us to quickly verify whether a particular transaction is included in the block or not without having to download a large amount of data. Then the new block gets hashed with the previous block thus creating chains of blocks. Once a new block is created and added to the blockchain it stays there forever no one can change or tamper with it. Each new block added to the blockchain increases the security of the previous blocks. Ethereum blocks contain not only ether transactions but also a whole computer operations.