How bitcoin works?

There seems to be a lot of misunderstanding among people about how bitcoin and how the underlying blockchain works, let us try to understand how it works in a layman terms.

how bitcoin works?

A real-world analogy for bitcoins

Suppose there were no banks and transactions had to be done without any central authority, we have a public transaction box (transaction pool) where anyone who wants to send money will write their address, receiver's address and amount on piece of paper and sign it, this sign is actually cryptographic signature and is foolproof, they put this paper in transaction box, this box contains "pending transactions".

to actually do these transactions, the process is time-consuming so there is a group of people (miners) who took this job, since it's time consuming they need an incentive to do this job, that's why they get a mining fees as a reward for this, since there is no central authority, to control the transactions, the process is designed such that doing the transaction takes upto 10 minutes no matter what, and only n number of transactions can be made at once, miners have the choice to pick these n transactions from the box, either they could pick randomly, or the sender can say, "please pick mine first, I will reward you", and they give some additional money for miner, once the miner picks n transactions, they perform this tedious task.

the one who finishes first runs towards the public ledger, everyone else who couldn't do it first get nothing, all efforts wasted. The winner puts his solution along with the list of transactions on a public board such that it's very easy to verify if it's legitimate, once it updates, all other miners take a note of this board, if it's legitimate and longer than the existing copy, they keep it, else, discard it. And that's how you have a public list of transactions which can't be tampered because In order to tamper, you would need to do the tedious task and by the time you do this task, new blocks will be added, and your malicious copy will always be smaller than the ones in circulation.

What is this tedious task that miners do?

You might be wondering what is this tedious task which miners do, how could it be such that it takes about 10 minutes no matter what? This is where you would need to understand how computer works, there are some tasks which can only be done in a certain way, Let us try to understand what hashing is before we proceed.

To understand a hashing, consider this analogy, Suppose you have a blender, you put some stuff in it and blend it completely, and you take out a spoon of the blended material, If we assume perfect blending, this spoonful of material represents our input material, and if we precisely specify the conditions of blending, we will always get same output for same input.

Thus, This Spoonful can be used to represent our input material, but the size of this output is always 1 spoon, and mostly less than the input, this implies that though this output represents our data completely, it's not enough to get original input back from it, as it's lost, what this spoonful can do is verify if another input is identical to this input if they have the same output.

It would be obvious that you can't get original data back from hash, as it does not contain original data, all you can do is check if some data is same as the original data. How bitcoin uses this property is that it requires miners to add some dummy data (nonce) which can be any number, and it should be such that the hash calculated after adding this dummy data will have certain number of zeroes in beginning. This certain number of zeroes is called difficulty and more zeroes imply more difficulty.

proof of work

The difficulty increases because there is no way to directly get a nonce whose hash contains certain number of zeroes, you have to keep checking a lot of nonce values till you get such a hash, and more zeroes make it more unlikely to find it, since computers are limited by how fast they can compute, it has been estimated that a computer won't be able to compute such a hash in less than 10 minutes.

This doesn't mean faster computers can't compute it in less time, but in future, when computers become a lot faster, we can just increase the difficulty in order to keep the rate same.