This is part-2 of the series “What is Blockchain and How it Works?”. To get the context and understanding of what exactly is blockchain technology, please first read **part-1**.

In our last article we discussed and understood the significance and applications of blockchain technology. Now, it’s time to get our hands dirty and dig deeper to truly understand the working of blockchain technology. So, here we go.

To understand the working of blockchain, we first need to disintegrate it into smaller components and get ourselves acquainted with these concepts.

## Hash

In simple terms, hash is a simple function that gives a fixed-length unique output (called hash) for any given input. And, the catch is – it’s practically impossible to deduce the input from the output or hash. Basically, a hash function makes sure that you can’t reverse engineer the input from the output.

A few common examples of hash functions are SHA256, SHA512, SWIFT, MD6, etc. Bitcoin uses the SHA256 hash function, so let’s talk about this one. So, SHA256 hash function gives a unique output of length 256 bits for any given input.

In the picture above, you can see a hash output 7727871a4…28e93e for the data input of a quote by Leonardo da Vinci. Now, if you change any single character of data, the hash output changes in a completely unpredictable way. Whereas, if you run the exact same input bit by bit, you’ll always get the same hash as you see in the picture.

Now that we’ve understood a simple hash function, let’s get to the Nonce.

## Nonce

You must have heard numerous times about how Bitcoin miners solve a mathematical puzzle to mine Bitcoins. So, what’s that magical mathematical puzzle is all about?

Well, that’s where the hash function comes in the picture. We just learned that a SHA256 hash function gives a 64-character hexadecimal (256 bits) unique output for any given input, right? Now, what if I ask you to add another input to the function that will give an output hash with zeroes at the first four places?

So, how do you find that second input? Well, as we mentioned earlier that all the outcomes of a hash function are unpredictable and unpatterned. Therefore, the only way to find a second input that will give the required output is to bruteforce. Or in simpler terms, keep trying multiple inputs until we find the given output.

Well, that second input is called nonce. And that, my friend, is the mathematical puzzle miners are solving in order to get the required output. To find that nonce, (so called solving the mathematical puzzle) miners need machines with high processing power so that they could solve it before anyone else could.

Now, what if I ask you to find a nonce that gives a hash output with zeroes at first ten places? Well, the probability of finding the nonce just got really low and you need way more processing power to find that nonce. Basically, it’s just got more difficult, right? Well, that’s what is called the difficulty rate.

In the Bitcoin network, as the combined processing power of the network increases, the Bitcoin core software automatically increases the difficulty rate. Thus making sure, new blocks are mined uniformly at the speed of 10 minutes per block.

## Chain of Blocks – Blockchain

In the nonce explanation, we looked at a single block with block number, nonce, and a given data. Now, let’s put such blocks together in a chronological order. So how do we put the blocks in a chronological order?

Well, we add another input in the block – the hash of the previous block. Thus enabling us to not only locate the blocks but also verify whether the data in that block has been tempered or not. It’s worth noting here that when a hash is calculated for a block, it includes all the contents of the block such as block number, nonce, data, and hash of previous block.

For example, in the picture above, changing the data in the block #1 will require us to find a new nonce for the given difficulty (zeroes in the first four places) and subsequently changing the output hash.

And as you can see, this block#1 output hash is used as an input in the next block. Thus changing the data in the block#1 invalidates all the subsequent blocks in the chain.

So, if a malicious miner wants to alter data in any block, the malicious miner would need to mine all the subsequent blocks, that too faster than the rest of miners to catch up. The only way a blockchain can be tempered is – by acquiring more than 50% of the network’s total processing power. It is also called the 51% attack and so far no miner or group of miners have been successful with 51% on Bitcoin blockchain.

So, that’s all for today. In the next blog post in this series, we’ll understand the working of tokens and coinbase on Bitcoin blockchain. Meanwhile, if you’d like to play with a demo blockchain, check out Anders Brownworth’s website.