Mining aka hashing (Proof of Work consensus algorithm)

The mathematical problem every miner is facing when trying to add a block to the blockchain is to find a hash output (aka signature) for the data in its block, that starts with a certain amount of consecutive zero’s. That sounds complicated, right? But it isn’t really that hard. Let me try to explain this to you in a simple way.

Before we proceed, it is important to know what a hash function is. A hash function is simply put a mathematical problem that is very hard to solve, but where the answer is very easy to verify.

A hash function takes an input string of numbers and letters (literally any string of random letters, numbers and/or symbols), and turns it into a new 32 digit string existing out of random letters and numbers. This 32 digit string is the hash output. If any number or letter in the input string is changed, the hash output will also change randomly. However, the same string of input will always give the same string of output.

Now consider the data inside a block to be the hash input (a string of data). When this input is hashed, it gives a hash output (32 digit string). A rule of the Bitcoin blockchain is that a block can only be added to the blockchain if its signature, the hash output, starts with a certain amount of zeros. However, the output string generated by an input string is always random for each different input string, so what if the data string of the block does not lead to a signature (hash output) that starts with so many consecutive zeros? Well, this is why miners repeatedly change a part of the data inside their block called the nonce. Every time a miner changes the nonce, it slightly changes the composition of the block’s data. And when the composition of the block’s data changes (it’s input), it’s signature (it’s output) also changes. So every time the nonce of a block is changed, the block gets a new random signature.

Miners repeat this process of changing the nonce indefinitely until they randomly hit an output string that meets the signature requirements (the zeros). Below illustrates this in an example. This example uses seven zeros, but the amount of zeros really depends on the block difficulty of a blockchain. Block difficulty is a little more complicated though, so I suggest you save that for later.