In this article we will explore the commonly heard question “How is the bitcoin mining difficulty calculated?”

The mining difficulty depends on the difficulty target, meaning the difficulty at which the computing power of the bitcoin network is able to solve the proof-of-work algorithm on average in 10 minutes. It is automatically adjusted every 2,016 blocks, based on the time spent on mining the previous 2,016 blocks.

Mining nodes are essential for securing the bitcoin network. They secure the bitcoin network by providing processing power to the network, in exchange for a chance at winning the coinbase reward and the transaction fees of a block, when solving the proof-of-work algorithm.

Since the inception of bitcoin, the computing power of the bitcoin network has been growing exponentially. Yet, the average rate at which new blocks of bitcoin transactions are mined (i.e. added to the bitcoin blockchain) remains steady at a 10 minute interval. This is because the bitcoin mining difficulty is automatically adjusted (either increased or reduced) by the nodes of the bitcoin network, in accordance with an increase or reduction of the network’s aggregate computing power.

In order to better understand the above answer, we will begin by briefly explaining how bitcoin mining works. Then we will provide a more detailed answer to the above question. Finally, we will explore the possible reasons for why the difficulty target is set to ensure an average 10 minute block interval.

How bitcoin mining works

Mining nodes record valid transactions, which they group together in a container called a ‘block’, on the bitcoin blockchain.

Miners compete with each other to be the first to solve the cryptographic hash algorithm (i.e. SHA256), also known as ‘proof-of-work’, for a block of transactions. Each miner constructs its own blocks of transactions, independently from each other, for which the miner tries to solve the proof-of-work algorithm.

Solving the proof-of-work algorithm for a block of transactions requires the mining node to find a cryptographic hash of the block header which is numerically lower than the difficulty target, an adjustable 256-bit number (a bit is either 0 or 1) (see infra, section What is the difficulty target?).

A cryptographic hash is the output of a cryptographic hash function, a mathematical algorithm that takes data of arbitrary size (input) and produces a fixed size result (output). The cryptographic SHA256 algorithm used in bitcoin produces a deterministic output of 256 bits.

Cryptographic hash functions are one-way functions, meaning that it is infeasible to calculate the input of a hash function solely on the basis of a given output. The only viable method for finding an input that matches a known output, is to randomly try all possible inputs for the cryptographic hash function, until the desired output has been found.

For the purpose of bitcoin mining, each mining node begins by constructing a block of transactions and then proceeds to hash the block header of its assembled block (input), using the SHA256 algorithm. If the resulting hash (output) exceeds the difficulty target, the mining node will make an incremental change to part of the block header (i.e. the nonce) and re-apply the SHA256 algorithm, resulting in a different hash (output). This process is repeated (i.e. trial and error method) until a hash (output) is found by a miner that is numerically lower than the difficulty target.

The miner who is the first to find a hash that is numerically lower than the difficulty target, has the right to record its block of transactions on the bitcoin blockchain and is awarded the coinbase reward and the transaction fees of the transactions that are included in the block.

Once a solution to the proof-of-work algorithm is found for a block of transactions, the race is reset and a new competition starts amongst all the mining nodes for the next block of transactions.

What is the difficulty target?

The difficulty target is an adjustable 256-bit number (a bit is either 0 or 1). This 256-bit number, which is represented in a particular hexadecimal 32-bit format called ‘bits‘, is part of the data that is included in the block header of every block of transactions.

The difficulty target is what determines how difficult it is for miners to find a valid block header hash, and hence, how difficult it is for miners to earn the right to add a block to the blockchain and be awarded the coinbase reward and the transaction fees.

As explained above, mining nodes compete to find a block header hash (output), that is numerically lower than the difficulty target – roughly speaking, a hash that begins with at least the same number of zeros or more – by applying the SHA256 algorithm to their block header. The mining difficulty (i.e. the difficulty to find a number that is lower than the difficulty target) is periodically adjusted in the bitcoin network, by either lowering or increasing the 256-bit target number.

By lowering the 256-bit target number, the number of possible block header hashes that can be found by miners which are numerically lower than the difficulty target decreases. This effectively makes it more difficult for miners to find a valid block header hash, because this means that on average the number of block header hashes miners will need to perform in order to find a valid hash will increase.

To illustrate this, you can think of the following analogy: If you ask someone to pick a random card from a standard deck of 52 cards, the chances of that person picking a card that is lower than a King (i.e. 44 possible cards, with the Ace being the highest card in the deck) is greater than the chances of that same person picking a card that is lower than five (i.e. only 12 possible cards). On average that person will pick a random card that is lower than five only 23% of the time and will therefore need to pick on average five (rounded) different cards before picking a right card.

The same goes for miners trying to find a valid block header hash, meaning a block header hash that is lower than the difficulty target. The lower the difficulty target, the more permutations a miner will have to perform on average (through incremental changes to the nonce in the block header) before being able to find a valid block header hash.

It is worth mentioning in this regard that the sheer increase in computing power of the bitcoin network over the past years has been such that the original number of possible permutations offered by the 4-byte nonce in the block header has proven to be insufficient. Even after having tried all possible nonce values, miners can still be unable to find a valid block header hash. Updating the timestamp, which is also part of the block header, to account for the time that has elapsed, offers some additional possible permutations, but is also insufficient. To tackle this issue, miners also use an additional nonce in the coinbase transaction. A change of the nonce in the coinbase transaction affects the merkle root which is part of the block header, which in turn affects the outcome of a block header hash. Hence, mining nodes have now a vast amount of additional possible permutations at their disposal to cycle through.

Changing the extra nonce in the coinbase transaction (bottom left square), changes the merkle root which is part of the block header, resulting in a different block header hash.

Are mining nodes trying to solve the same puzzle?

You may be wondering, if mining nodes are trying to mine blocks containing the same transactions, all by making incremental changes to the block header nonce, aren’t they all competing to find the same deterministic block header hashes? And if that would be the case, wouldn’t the fastest miner always win?

The answer is no. Mining nodes will in principle never be mining identical blocks. Therefore, each mining node will always find a different deterministic block header hash.

The reason why mining nodes will in principle never be mining identical blocks is two-fold:

(1) First, as mentioned above, each miner constructs its own block of transactions, independently from the other competing miners. This means that it is unlikely that miners will have constructed identical blocks. Rather, it is more likely that each miner will have assembled a slightly different set of transactions and will have sorted the transactions in a slightly different order.

(2) Second, the first transaction every miner includes in a block is the coinbase transaction. The coinbase transactions contains (1) the coinbase reward and (2) the transaction fees of all transaction included in the block. The output of the coinbase transaction is payable to the miner’s own bitcoin address, which of course is different for every miner. The coinbase transaction will therefore be different for every miner, which in turn affects the merkle root which is included in the block header. It follows that the block header hash of a block will in principle always differ from that of another block.

How is the change in difficulty target calculated?

The difficulty target for the bitcoin network is set to ensure that new blocks of bitcoin transactions are being mined (i.e. added to the bitcoin blockchain) at an average pace of 1 block every 10 minutes.

The difficulty target is re-evaluated and automatically adjusted (as the case may be) by every full node of the network, every 2,016 blocks.

The adjustment of the difficulty target is done by comparing, on the one hand, the amount of time it took to mine 2,016 blocks, and, on the other hand, the time it should take to mine 2,016 blocks based on the desired 10 minute interval, i.e. 20,160 minutes (10 minutes x 2,016 blocks).

The amount of time spent on mining the previous 2,016 blocks is determined on the basis of the timestamps that are included by the miners in the block header of every block of transactions. The Unix Epoch timestamp used in every block header, represents the approximate time of creation of a mined block, expressed in the number of seconds that have elapsed since the date Jan 01, 1970, midnight (UTC).

If the amount of time it took to mine 2,016 blocks is greater than the desired 20,160 minutes, the mining difficulty is decreased, which means the difficulty target will be set higher. If the amount of time it took to mine 2,016 blocks is less than the desired 20,160 minutes, the mining difficulty is increased, which means the difficulty target will be lowered. It also follows that the adjustment of the difficulty target is independent from the transaction volume or value that is being processed by the bitcoin network.

The change in difficulty can be described as follows:

New Mining Difficulty = Previous Mining Difficulty * (Time To Mine Last 2016 blocks / 20,160 minutes)

Evolution of hash rate (green) and the mining difficulty (red) mid – 2014 (source: bitcoinwisdom.com)

The adjustment of the mining difficulty at any re-target point cannot exceed a factor of 4. In the event a change in the hashing power of the bitcoin network is such that a correction is required exceeding a factor of 4 vis-à-vis the current mining difficulty, the maximum factor of 4 will be applied. Any further adjustments will take place at the next re-target point(s), as the case may be.

A side note worth mentioning in this regard, is that an apparent error was included in the original bitcoin core client implementation, causing the recalibration of the difficulty target every 2,016 blocks to be based on, not the time spent to mine the previous 2,016 blocks, but rather the previous 2,015 blocks.

Who adjusts the difficulty target?

The recalibration of the difficulty target happens in a decentralized way. This means that each full node will independently evaluate and adjust (as the case may be) the mining difficulty, in accordance with the above mentioned calculation method, and will only accept blocks that meet the difficulty that it has computed.

Why is the difficulty target set to ensure an average 10 minute block interval?

It is believed the average 10 minute block interval was deliberately chosen by Satoshi Nakamoto, the inventor of bitcoin, as a compromise between (1) the speed of the bitcoin network and (2) the stability of the bitcoin network.

(1) Speed of the bitcoin network

On the one hand, the average 10 minute block interval ensures that transactions that are being broadcast to the bitcoin network are confirmed (i.e. included in a mined and valid block) relatively quickly. Relatively short confirmation times are beneficial for bitcoin’s usability as a transaction mechanism.

(2) Stability of the bitcoin network

On the other hand, the average 10 minute block interval minimizes the possibility that two (or more) valid blocks are mined containing duplicate transactions.

Such situation can occur whenever two or more mining nodes successfully mine a valid block within a short timeframe, before either of them is made aware of each other’s newly mined block. The size of the bitcoin network is such that a short period of time may elapse before the broadcast of a newly mined block propagates throughout the entire bitcoin network. Hence, it is entirely possible that a new block is mined, even though another mined block containing the same transactions had already been broadcast to the bitcoin network, but has not yet been received by the miner of the most recent block.

In such event, two different versions of the bitcoin blockchain will temporarily exist amongst the nodes of the bitcoin network (often referred to as a ‘fork‘), until the nodes eventually re-converge to a single chain that is considered as the main bitcoin blockchain, containing the most number of blocks, and therefore displaying the most amount of proof-of-work.

By ensuring that on average a sufficient amount of time (i.e. 10 minutes) elapses between newly mined blocks, the risk of a fork materializing is mitigated, though not entirely excluded.

Conclusion

The mining difficulty depends on the difficulty target, meaning the difficulty at which the computing power of the bitcoin network is able to solve the proof-of-work algorithm on average in 10 minutes. It is automatically adjusted every 2,016 blocks, based on the time spent on mining the previous 2,016 blocks. It is believed the average block interval of 10 minutes was deliberately chosen, as a compromise between (1) speed of the bitcoin network and (2) stability of the bitcoin network.

Other related bitcoin mining questions

What kind of mining hardware do bitcoin miners use?

As explained at the beginning of this article, miners compete with each other to be the first to solve the cryptographic hash algorithm (i.e. SHA256), also known as ‘proof-of-work’, for a block of transactions. This essentially requires a miner to perform many computations, in the hopes to be the first to find a block header hash that is numerically lower than the difficulty target. Calculation speed is therefore of the essence. In this section we will take a look at the type of hardware that miners use to perform these vast amount of calculations.

The mining equipment being used has evolved over time, due to the increase in the processing power of the bitcoin network (also known as the hash rate), which has caused an increase in the bitcoin mining difficulty.

Evolution of the aggregate hash rate of the bitcoin network over time.

The following 3 types of mining hardware have generally been used over the years to mine bitcoin:

CPUs

GPUs

ASICs

Of these 3 types, ASICs dominate the bitcoin mining industry today.

In the beginning people made us of the general purpose CPU (central processing unit) of their PCs for mining bitcoin.

After some time people started using GPUs (graphics processing units) for bitcoin mining. One of the main reasons being that GPUs have the ability to perform multiple calculations at the same time. In addition, you can drive many GPUs from one single motherboard and CPU, which made it possible to build a powerful mining operation from one’s home.

Bitcoin mining rig consisting of multiple GPUs.

GPUs have however 3 main drawbacks, rendering them suboptimal for bitcoin mining:

part of the hardware that makes up a standard GPU is not useful for bitcoin mining;

they generally produce a lot of heat, making it challenging to keep them cool; and

they generally consume a lot of electricity.

Today, bitcoin mining is mostly done by application‐specific integrated circuits (ASICs).

ASICs are chips that have been purposely designed and manufactured for mining bitcoin. They have been optimised in terms of (1) increased hashing power, (2) lower heat generation and (3) lower power consumption.

At the present, the hash rate of the bitcoin network is such that ASIC mining is the only viable way for mining bitcoin profitably.

Is bitcoin mining still profitable?

Individuals

It has arguably become unprofitable for an individual to mine bitcoin on his/her own. The aggregate hash rate of the bitcoin network has simply become too great (47 million TH/s at the time of writing).

In this regard, bitcoin mining has evolved from being a hobby for interested individuals in the early days of bitcoin, to having become a professional capital intensive and extremely competitive endeavour.

Nowadays, bitcoin mining is done by gigantic mining centers, assembling thousands of ASICs in large warehouses. These mining centers are mostly built in strategic locations, taking multiple factors into consideration, such as the local climate (a cold climate reduces cooling costs), and the availability of abundant and cheap electricity, as well as high network speeds.

Bitcoin hashrate distribution dd. 15 March 2019

Mining pools

Individual miners are now able to collaborate to mine bitcoin. Thousands of participants pool their individual, relatively low amounts of hashing power, in order to form one giant and powerful mining pool.

The individual miners share in the mining rewards earned by the mining pool (minus fees for the pool operator), in proportion to the hashing power that they have contributed to the overall hash rate of the mining pool.

Mining pools have a couple of advantages over solo-mining:

The combined hashing power of the mining pool increases the likelihood of finding valid blocks. By joining a mining pool, individual miners are able to earn mining rewards on a regular basis, reducing income uncertainty. The individual miners are relieved of the burden of having to run a full node, which is typically run by the pool operator.

If you want to mine bitcoin profitably, the only viable option is to join a mining pool.

Bitcoin mining profit calculator

The below mining profit calculator allows you to estimate potential mining profits, taking into account a multitude of factors:

A number of elements need to be taken into consideration when using the above bitcoin mining calculator:

Not all fields are mandatory, but the more information you enter, the more accurate the results will be.

Results will be displayed in USD.

If you wish to take electricity costs into account when using the above calculator, please make sure to fill in both the power consumption (Watts) and the electricity cost (USD/kWh), since one won’t work without the other.

The difficulty factor and the USD/BTC exchange rate shown above are automatically updated once every hour. Price data is taken from Coindesk’s API. The difficulty number is derived from BitcoinWisdom’s API. Any value can also be adjusted manually, which can be useful for making particular simulations.

The calculation is based on the current mining difficulty. Please keep in mind that the mining difficulty can (and probably will) fluctuate as time goes by, affecting your mining profitability. As set out in the beginning of this article, the mining difficulty is automatically readjusted every 2,016 blocks. Based on historical data, the mining difficulty tends to increase over time (on average 0.4% increase per day). You can find the estimated next mining difficulty adjustment by clicking here.

The rise in mining difficulty over time is likely to make your current mining equipment obsolete at some future point in time. Therefore, when making any sort of long term mining profit calculations, the cost of replacing your mining equipment should also be taken into consideration.

Ivan on Tech Academy Has Already Helped Countless of People Around The World – Are You Next?

The Ivan On Tech Academy crypto and blockchain courses have already been rated with 5 stars by over 600+ people!

Read All The Facebook Reviews Here.