HomeCryptoBitcoinHow does the difficulty in Bitcoin work

How does the difficulty in Bitcoin work

The difficulty is part of the sophisticated mechanism that regulates the operation of the Bitcoin network.

Through the mining process, transactions are “secured” thanks to the computing power made available by the miners, who participate in a competition that has as its reward a certain number of bitcoins. This number is halved every four years as a result of the halving process.

What do the miners calculate?

Miners calculate cryptographic hashes in the head of the block. For each new hash, the mining software uses a random number called Nonce. In order for the extraction of a block to become a difficult “job”, the miner must find a hash that is lower than a determined number.

The difficulty is a number that regulates the time it takes for the miners to extract the next block, which will then be added to the blockchain. On average this time is ten minutes. As mentioned, the difficulty is “adjusted” every two weeks, in fact, this happens every 2016 blocks. After this interval, each node performs an operation that consists of multiplying the expected time by the 2016 blocks (2016 x 10 minutes) and divides the result with a number that is obtained by multiplying the actual time by the 2016 blocks. So, if for example, the actual time is 8 minutes, the result is:

2016 x 10 / 2016 x 8 = 1.25

Hence each node will use this number to set the new difficulty for the next 2016 blocks. Bearing in mind that the new difficulty will be obtained from the result of the multiplication between the current difficulty and the result of the previous operation (in our example 1.25)

New difficulty = difficulty x 1.25

Relationship between difficulty and target group

difficulty bitcoin work

The average block time is maintained through the variation of the difficulty. To understand how this happens we can use as an example the game of rolling the dice.

Let’s suppose we have two classic dice and establish as a rule, that the player wins (and therefore gets a reward) when the sum resulting from the roll of the dice, is less than or equal to a number previously established. If a very high number is chosen, for example 10, the probability of finding a number less than or equal to 10 will be very high. In this case, in order to lose, the player should total either 6 plus 5 or a double 6. However, if a much lower number is chosen, such as 4, the throws to be made to get a result equal to or less than this number will have to be many more. As this number, called target value, becomes small, the difficulty increases. Thus the difficulty shows a variation of the target value from its original value.

If the game was regulated by software and a fixed settlement time had to be set, the target would be adjusted to maintain an average payout time equal to that set by the system.

The difficulty in Bitcoin

The difficulty in Bitcoin works in a more or less similar way. Miners generate numbers with the hope that one of them is less than or equal to the target value. The numbers are very large and are hexadecimal. Each block stores a compressed representation of the target called Bits. The bits are actually an abbreviated version of the target, introduced to save space inside the block header.

The difficulty is “adjusted” every two weeks or so in order to keep the average extraction time unchanged as new nodes are added to the network.