Bitcoin & Crypto Mining | How Does it Work?
Bitcoin and Crypto mining is the process in which you can obtain new digital tokens that are released. You can mine a block about every 10 minutes, the current return is 12.5 bitcoin per block. It currently takes significant computational power to mine bitcoin and that will only increase alongside the hashrate, which correlates with computational power needed to solve the mathematical formula to mine each new block.
Simply put, miners are another node that connect to the network. Generally they do everything a node does but with one specific task. Besides propagating transactions and blocks, miners create new blocks by adding transaction records to the public ledger of past transactions.
Block hash algorithm – Bitcoin and most Crypto currency mining uses proof-of-work function. Miners combine several inputs and hash it to produce the desired output (Block header hash). When we achieve the desired output, the network rewards us with newly generated Bitcoin and transaction fees. New bitcoin generation has similar characteristics to gold. However, rather than spending resources on gold mining, resources are CPU power, time, and electricity. Once all 21 million bitcoins are generated, miners will still have an incentive for transaction fees. Furthermore, the transaction fees are inflation free.
The desired output is a 256-bit number that all Bitcoin clients share. The network accepts blocks with a SHA256 hash block header and is lower than or equal to the current target. In short the hash output value needs to have a certain number of starting zeros. The lower the target (the more starting zeros required), the more difficult it is to generate a block.
As you can see it is not a set mathematical problem, as the input changes. Some down to every few seconds and the inclusion of Nonce (Random Number), to be able to generate the right output is more like winning the lottery. The more hash power you have, the more attempts you have per second – like buying many lottery tickets.
The difficulty in Bitcoin and Crypto Mining is the target. Ordinarily the network produces a new block every 10 minutes and the difficulty is adjusted every 2016 blocks. Usually it takes 2 weeks when each block is 10 minutes. After every 2016 blocks, the network compares the actual time taken against the 2 week benchmark, and adjusts the difficulty. When we mine blocks too quickly, the difficulty will go up and vice versa.
Block Creation Fees (newly generated Bitcoin per block):
The block creation fee changes at every 210,000 blocks. Before, Bitcoin mining started with 50 Bitcoin per block, then decreased to 25 Bitcoin per block. Currently – it is 12.5 per block. However, May 17th 2020 the amount of Bitcoin mined per block will halve to 6.25 (learn more about Bitcoin halving here). This will eventually decreased to zero at block 6,930,000 where all 21 Million Bitcoin will be generated and in circulation. Subsequently miners will only earn transaction fees on creating new blocks.
*Difficulty, Block creation fee and Data structures etc are governed by Bitcoin Protocol Rules.
If you add up the input and output on your transaction, you’ll notice there’s a difference. Namely the transaction fees the network pays miners for validation, doing the proof-of-work, and adding your transaction onto the blockchain. New blocks don’t have to include all of the outstanding transactions and miners can pick and choose what they include. The difference between all the inputs and all the outputs in the block is the transaction fees. In this case fees a miner earns on top of the newly generated Bitcoin for hard work and resources spent.
Therefore the higher the transaction fee, the more likely miner will include it (other words the higher the transfer). You can set the amount of fees you pay, some wallets decide for you. Lastly you pay transaction fees. It’s possible to pay nothing, however, it could take weeks, months, or possibly never be included in a block. I’m sure you’ve heard the saying “There’s no free lunch in this world”. Why would miners want to work for free on your transaction?
You can see the cost per transaction (in Bitcoin) in the Memepool here.
This link provides a good visual representation of the whole process from encryption, transaction, verification, mining, to block and bitcoin generation. (NOTE: this image is dated and number of bitcoin generated per block has dropped to 12.5)