How Does Bitcoin Mining Work?7 min read
To put it simply, Bitcoin mining is the process that is required to create new Bitcoin. Mining Bitcoin isn’t exactly like mining for gold, while it is a lot less physical it is also much more complex. To better understand how Bitcoin mining works, we will address the following key points:
- What is Bitcoin mining?
- How does Bitcoin mining work
- Bitcoin Halving
- Bitcoin Mining difficulty
- The supply of Bitcoin
Where do bitcoins come from? With other forms of currencies, a central authority decides how money is printed and distributed. Bitcoin doesn’t have a central authority. Mining is how new bitcoins are added, and transactions are validated in the Bitcoin network. A blockchain is a continuously growing list of records, called blocks which are cryptographically linked and secured to form a chain of records. Mining is the underlying method by which new blocks are created and linked together. Miners compete to build new blocks by solving a cryptographic puzzle, by which they are rewarded with newly minted bitcoins.
How Bitcoin mining works
In the Bitcoin network, blocks are added on average every 10 minutes; however, transactions can occur all the time. When users in the network transact bitcoin, the transactions are not instantly confirmed. The transaction needs to be included in a newly mined block and then accepted by all the nodes. Until the transactions are added to a mined block and verified, they wait in a memory pool.
Miners will then take unconfirmed transactions from the memory pool and add it to a temporary block called the candidate block which will either be validated or discarded. Since there is a limited number of transactions a miner can add to their candidate block, they are incentivized to choose the transactions with the highest fee to byte ratio. After adding the transactions, each transaction that the miner adds to the candidate block will be hashed to get a transaction id. Then, each transaction hash is put in pairs and hashed again to produce another transaction id. This process is repeated until a final hash value is produced called the Merkle root. The Merkle root is a single hash representing all previous hashes of that tree of hashes. This is done to make sure that the data received is unaltered and allows transactions to be verified quickly.
The root hash is then added to the block header along with the hash of the previous block, nonce (number used only once), and some other data. After the candidate block is formed, miners need to solve a cryptographic puzzle that involves finding a particular hash under a specific range called the target. This target is set by the Bitcoin algorithm, which is adjusted every 2016 blocks (every 2 weeks approximately). To find the hash of the next block, miners use the nonce (number used only once); which is the only piece of data in the entire block that can be changed. The “nonce” is a 32-bit (4-byte) field whose value is adjusted by miners. Miners vary the nonce and iterate it, through a hashing algorithm, searching for a hash under the target.
Nonce -> Sha-256 Hash Function -> Hash
Any hash above this set target is rejected, and the hash is not used to create a new block. However, if a miner finds a hash under the set target, the hash will be used to build the block. The nonce that finds the hash is called the golden nonce. Solving this cryptographic puzzle is a costly and energy-intensive process as there is no way to predict the golden nonce and it can be only done by guessing and iterating through the nonce. After the miner finds the new block and the network accepts the block, the miner is rewarded with freshly mined bitcoin as a reward. The newly created bitcoin will be the first transaction in the newly created block called the coinbase transaction.
As mining new blocks require a lot of computational power and electricity, miners are rewarded with a block reward. The block reward is how new freshly minted bitcoins are injected into the Bitcoin network. Bitcoins’ monetary system is designed to reduce the block reward by half every 210,000 blocks mined (roughly 4 years). This event when the reward for mining bitcoin transactions is cut in half is called the halving. Currently, the block reward for mining a new block is 6.25 BTC, after the next halving, this reward will be reduced by half. Unlike other currencies and altcoins, no central authority controls the Bitcoin monetary supply. This also gives Bitcoin its fixed monetary supply of 21 million coins. Every bitcoin halving bitcoin becomes even more valuable and scarce, thus even with the reduced block reward miners are still incentivized to mine.
Bitcoin Mining Pool
As for difficulty increases, it becomes more difficult for individual miners to find the golden nonce. Additionally, it may even take months or years to generate one block. Miners don’t just mine for themselves but instead enter mining pools. Miners combine their hashing power in the mining pool so that the miners do not do double work. The mining pool distributes the cryptographic puzzle among the miners. When a miner finds the golden nonce, the mining pool wins the reward, and the reward is split proportionately to the hashing power that the miners introduced to the mining pool. Mining pools do not discriminate, and anyone can join these mining pools
Bitcoin Mining Difficulty
Bitcoin mining difficulty is a measure of how difficult it is to find the golden nonce that finds a hash below a given target. The difficulty adjusts about every two weeks (2016 blocks) so that no matter how much mining takes place worldwide, a new block continues to be created every 10 minutes on average. If the aggregate hashing power changes, the mining difficulty will change according to it. The difficulty is not adjusted by any central authority. The nodes set the difficulty and the algorithm is coded into the Bitcoin protocol. The target regulates the speed at which new blocks are created on the blockchain. This is important as it allows time for the newly mined block to propagate through the network and be accepted by the other nodes in the network. It also reduced the waste of energy as it gives enough time for the new block to propagate, reducing the chance of competing chains forming.
As more people start to mine bitcoin, the difficulty rate also increases as mining hash power rises. This is because bitcoins are mined faster as the network’s aggregate power increases, so the algorithm has to adjust to keep the consistency of releasing a new block every 10 mins.
Bitcoin mining is the backbone of the Bitcoin network that builds and secures the Bitcoin network. Bitcoin miners are responsible for adding validated transactions to the blockchain. To add new blocks of transactions, miners solve a complex problem. When the miner successfully solves the problem, they can add their block to Bitcoin’s blockchain, and as compensation, they receive newly minted bitcoins and transaction fees. Every 210,000 blocks mined, the Bitcoin reward is halved, giving Bitcoin its fixed monetary supply of 21 million coins. To ensure that a new block is created on average every 10 minutes, the Bitcoin protocol adjusts the difficulty level of the problem every 2016 blocks.