When you hear 'bitcoin mining' you imagine that coins are being mined from the ground. Bitcoins have no physical form, so why do we say that we 'mine' them?
It's because, in a way, it's similar to gold digging - bitcoins exist in the protocol's design just as the gold exists underground, but they haven't been unearthed yet. The bitcoin protocol predicts that at some point there will be 21 million bitcoins. What 'miners' do is extracting them, several at a time. They do this as a reward for creating blocks of verified transactions and including them in the blockchain.
For now, let's talk about nodes. A node is a powerful computer that runs the bitcoin software and helps to keep bitcoins active by participating in the transfer of information. Anyone can run a node by downloading a free bitcoin software and leaving the port open. Unfortunately, the disadvantage is that it consumes energy and storage space - the network at the time of writing takes about 145 GB. Nodes distribute bitcoin transactions over the network. One node will send information to several other nodes that it knows, which will pass information to nodes they know, etc. In this way, the information will quickly pass through the entire network.Some of these nodes are mining nodes, usually referred to as 'miners'. These divide transactions into blocks and add them to the blockchain. How do they do it? By solving a complicated mathematical puzzle, which is part of the bitcoin program, and including the answer in the block. The puzzle that requires a solution consists in finding a number that, in combination with the data in the block and transmitted by the hash function, gives the result within a definite range. It is much harder than it seems to be.For trivia lovers, this number is called 'nonce', which is an abbreviation of 'number used once'. In the case of bitcoins, the nonce is an integer between 0 and 4,294,967,296.
Solving a puzzle
How do they find this particular number? By guessing it randomly. The hashing function makes it impossible to predict what the result will be. So miners guess the mystery number and use the hash function to combine that number and the data in the block. The resulting hash must begin with a fixed number of zeros. It is not possible to check which number worked because two consecutive integers will give very varying results. Furthermore, there may be several nonces that give the desired result, or there may be not even one - in this case, the miners are still trying, but with a different block configuration.The first miner who has obtained the hash result in the desired range announces a victory for the rest of the network. All other miners immediately stop working on this block and start trying to find the secret number of the next one. As a reward, the winning miner gets a part of new bitcoins.
Although it is not as easy to earn as it seems, there are many mining nodes competing for this prize, and it's just a matter of luck and computing power: the more guessing you can do, the more luck you have. In addition, the costs associated with a mining node are significant, not only because of the need to have powerful hardware - if you have a faster processor than competitors you have a better chance of finding the right number before they do - but also because of the large amount of electricity consumed by these processors.Furthermore, the number of bitcoins awarded for solving a puzzle will be reduced. Currently, it amounts to 12.5, but this number is halved every four years (the next reduction is expected to occur in 2020 or 2021). The bitcoin's value in comparison to the cost of electricity and hardware may increase over the next few years to partially compensate for this reduction, but it is not certain that it will happen.
Difficulties in Bitcoin mining
The difficulty of calculations (the number of zeros required at the beginning of the hash sequence) is often adjusted, so the processing of the block takes about 10 minutes on average.Why 10 minutes? This is the time that the creators of bitcoin consider necessary for a steady and decreasing flow of new coins, up to a maximum of 21 million (expected in 2140).If you have come this far, then congratulations! There is still much to explain about the system, but at least now you have an idea about the general outline, genial programming and the concept. It's the first time we have a system that allows for convenient digital transfers in a decentralized way, free of authorities and resistant to manipulation. The effects can be huge.