<p>The Bitcoin blockchain has a property called the "difficulty" or "target", which is expressed as a 32-byte number. For a new block to be valid (among many other things) it's hash (another 32-byte number) must be arithmetically less than the target. This target value is adjusted after every 2,016 block period by a deterministic algorithm performed by all full nodes on the network.</p>

<p>Imagine if I asked you to flip a coin and if you got 3 "heads" in a row you win. How many attempts would you need to win? Once you win, I change the difficulty: now you must get 4 "heads" in a row... that will be harder for you and require more "computation" (attempts).</p>

<p>In Bitcoin, the difficulty adjustment algorithm looks at the time stamp of the block at the start and end of the 2,016-block period. If that time is greater than two weeks, the new difficulty target becomes "easier". If the blocks are being mined too fast, the difficulty becomes "harder".</p>

<p>further reading: <a href="https://bitcoin.stackexchange.com/questions/20597/where-exactly-is-the-off-by-one-difficulty-bug">Where exactly is the &quot;off-by-one&quot; difficulty bug?</a></p>

CC BY-SA 4.0
2020-04-21T19:20:08.053Z
Thank you for the detailed answer, I have some questions though. Firstly, isn't bitcoin blockchain using SHA-256 hashing algorithm which produces 64-bit results? Secondly, what do you specifically mean by "arithmetically less" since hash is a combination of letters and numbers? Also, could you elaborate on the last paragraph more? @pinhead
Frenk Frenk
CC BY-SA 4.0
2020-04-21T19:52:48.040Z
SHA-256 digests are 256 bits (32 bytes) hence the name. While hashes are commonly displayed as hexadecimal digits (0-9, A-F) they aren't strings, they are a set of 32 bytes that can be interpreted or compared as numbers just like 1-byte numbers. Since the target is just a number, it can go up or down based on how fast the last 2,016 blocks were. The formula targets 1 block every 10 minutes.
pinhead
CC BY-SA 4.0
2020-04-21T20:34:22.353Z
Alright, now I understand it completely! Thank you! @pinhead
Frenk Frenk
CC BY-SA 4.0
2020-04-21T11:59:00.380Z
2020-04-21T11:59:00.380Z
pinhead
<p>The easiest way I can think of to explain this is to give you a die (dice) and say "If you roll less than a 6, i'll give you $100". It'll be pretty easy to get the money, right? The only way you can lose is if you roll a 6</p>

<p>Now if I change the game to be "roll less than a 2", it's harder (less likely) that you'll get it on your first go, because you have to roll a 1.</p>

<p>So lets say I am aiming for you to win $100 a minute, and you're fast enough to roll about 3 times a minute. You start rolling and I notice with the difficulty set at 5, you're winning a lot more often than once a minute, so I dial the difficulty number down (make it harder). Say we reach a point where with the difficulty set at "below 3" you are, on average, winning once a minute. Then you have a real streak of bad luck and it takes you 4 minutes to roll less than 3 - you just kept rolling 6's for the first 3 minutes. I figure I'll go easy on you, and I raise the difficulty number again because you're having a bad streak so I'll make it easier to win. Then you start doing really well, so i start reducing the number again.</p>

<p>On a regular basis, i'll look back over the average time it took you to win recent games and decide whether to adjust the difficulty or not, and tweak it up or down to try and keep you to winning once a minute. If you get faster at rolling, i'll make the game harder. If you get your buddy to roll with you, I'll make it harder still. If you put the die away for a day then roll a win it'll massively affect the average time for a win, and I'll probably adjust thing so it's easier.</p>

<hr>

<p>This uses a 6 sided dice; the numbers involved in bitcoin are much much higher - at the time of writing the difficulty is about 15,000,000,000,000 and hashes can be between 0 and 2^224 (about 270,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000) but the premise remains the same - it's a dice with 27000 vigintillion sides and you have to roll less than about 15 trillion. And you can buy devices that roll up to 16 trillion times a second. With your big rewards you can buy loads of these devices and fill a warehouse with them, increasing your odds of being the one to roll the win, if you can afford the power bill</p>

<p>The rolling of the dice is the generating of the hash code for the transactions the miner has decided to pack into a block. </p>

<p>In essence the miner packs a block with transactions, calculates the hash, it's greater than the difficulty, they change one number in the block header (rather than go to the effort of packing another block of transactions - a lot more computationally expensive to do but would have the desired effect of changing the hashcode, which is the overall goal) called the nonce. So we change the nonce, re-do the hash, is it less than the difficulty? No. Change the nonce,  redo the hash. Check the difficulty/change the nonce/hash/check/change/hash/check/change..</p>

<p>Eventually something happens:</p>

<ul>
<li>we find a hash less than the current difficulty - quick! announce it to the network and get the world to verify the work, accept it and we get the reward</li>
<li>someone else finds a block of transactions that has a hash less than the difficulty, they get the reward, all the transactions they packed are completed/paid - we need to start over with a new block of transactions </li>
<li>we run out of nonces (there are only 4 billion) because we're hashing so fast (transaction blocks have a timestamp that increments, which also changes the hashcode, but even then coupled with the 4 billion nonces means if we hash faster than >4ghash/second we'll run out of nonces before the time ticks up by a second, so we then go and modify one of the transactions slightly, or swap it out for another) - whatever is needed to bring about even a valid single byte change in the block will produce a different hashcode, so we make that change and carry on (probably back with the nonce changing method)</li>
</ul>

<hr>

<p>So who is the authority on what the difficulty should be? Same as anything else with bitcoin - everyone. The network decides on the difficulty, and because all (or most) of the network are good actors, you can't cheat, you can't write a program that claims a win with some hash, because everyone else proof checks the work and they don't accept it if you cheated the hashcode, or lied about getting lower than the difficulty. It's like everyone else in the casino watched you roll, and if you rolled a 6 but shouted "i rolled a 1!" they ignore you</p>

CC BY-SA 4.0
2020-04-22T08:54:41.743Z
Thank you for the detailed answer! I appreciate it! @Caius Jard
Frenk Frenk
CC BY-SA 4.0
2020-04-22T09:08:34.377Z
No probs! I made a couple of edits since you've read it, but likely stuff you knew already..
Caius Jard
CC BY-SA 4.0
2020-04-22T08:30:14.907Z
2020-04-22T09:05:05.637Z
2020-04-22T09:05:05.637Z
Caius Jard
<p>How does it become harder for miners to extract bitcoin as time passes (excluding increasing computer capabilities and the competition between miners accordingly)? Is related to the amount of bitcoins that could be extracted at that timestamp?</p>

<blockchain><mining-theory><mining-profitability><mining-reward><difficulty-retargetting>
How does the mathematical problem get harder for bitcoin mining over time?
Frenk Frenk
# How does the mathematical problem get harder for bitcoin mining over time?

(Asked by: username_0 on 2020-04-21)

How does it become harder for miners to extract bitcoin as time passes (excluding increasing computer capabilities and the competition between miners accordingly)? Is related to the amount of bitcoins that could be extracted at that timestamp?

**Tags:** blockchain, mining-theory, mining-profitability, mining-reward, difficulty-retargetting


---

## 2 answers

### Answer by username_1 on 2020-04-21. Score: 1

The Bitcoin blockchain has a property called the "difficulty" or "target", which is expressed as a 32-byte number. For a new block to be valid (among many other things) it's hash (another 32-byte number) must be arithmetically less than the target. This target value is adjusted after every 2,016 block period by a deterministic algorithm performed by all full nodes on the network.

Imagine if I asked you to flip a coin and if you got 3 "heads" in a row you win. How many attempts would you need to win? Once you win, I change the difficulty: now you must get 4 "heads" in a row... that will be harder for you and require more "computation" (attempts).

In Bitcoin, the difficulty adjustment algorithm looks at the time stamp of the block at the start and end of the 2,016-block period. If that time is greater than two weeks, the new difficulty target becomes "easier". If the blocks are being mined too fast, the difficulty becomes "harder".

further reading: [Where exactly is the "off-by-one" difficulty bug?](https://bitcoin.stackexchange.com/questions/20597/where-exactly-is-the-off-by-one-difficulty-bug)

> **Comments:**
> **username_0**: Thank you for the detailed answer, I have some questions though. Firstly, isn't bitcoin blockchain using SHA-256 hashing algorithm which produces 64-bit results? Secondly, what do you specifically mean by "arithmetically less" since hash is a combination of letters and numbers? Also, could you elaborate on the last paragraph more? @username_1  
> **username_1**: SHA-256 digests are 256 bits (32 bytes) hence the name. While hashes are commonly displayed as hexadecimal digits (0-9, A-F) they aren't strings, they are a set of 32 bytes that can be interpreted or compared as numbers just like 1-byte numbers. Since the target is just a number, it can go up or down based on how fast the last 2,016 blocks were. The formula targets 1 block every 10 minutes.  
> **username_0**: Alright, now I understand it completely! Thank you! @username_1  

---

### Answer by username_2 on 2020-04-22. Score: 0

The easiest way I can think of to explain this is to give you a die (dice) and say "If you roll less than a 6, i'll give you $100". It'll be pretty easy to get the money, right? The only way you can lose is if you roll a 6

Now if I change the game to be "roll less than a 2", it's harder (less likely) that you'll get it on your first go, because you have to roll a 1.

So lets say I am aiming for you to win $100 a minute, and you're fast enough to roll about 3 times a minute. You start rolling and I notice with the difficulty set at 5, you're winning a lot more often than once a minute, so I dial the difficulty number down (make it harder). Say we reach a point where with the difficulty set at "below 3" you are, on average, winning once a minute. Then you have a real streak of bad luck and it takes you 4 minutes to roll less than 3 - you just kept rolling 6's for the first 3 minutes. I figure I'll go easy on you, and I raise the difficulty number again because you're having a bad streak so I'll make it easier to win. Then you start doing really well, so i start reducing the number again.

On a regular basis, i'll look back over the average time it took you to win recent games and decide whether to adjust the difficulty or not, and tweak it up or down to try and keep you to winning once a minute. If you get faster at rolling, i'll make the game harder. If you get your buddy to roll with you, I'll make it harder still. If you put the die away for a day then roll a win it'll massively affect the average time for a win, and I'll probably adjust thing so it's easier.

---

This uses a 6 sided dice; the numbers involved in bitcoin are much much higher - at the time of writing the difficulty is about 15,000,000,000,000 and hashes can be between 0 and 2^224 (about 270,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000) but the premise remains the same - it's a dice with 27000 vigintillion sides and you have to roll less than about 15 trillion. And you can buy devices that roll up to 16 trillion times a second. With your big rewards you can buy loads of these devices and fill a warehouse with them, increasing your odds of being the one to roll the win, if you can afford the power bill

The rolling of the dice is the generating of the hash code for the transactions the miner has decided to pack into a block.

In essence the miner packs a block with transactions, calculates the hash, it's greater than the difficulty, they change one number in the block header (rather than go to the effort of packing another block of transactions - a lot more computationally expensive to do but would have the desired effect of changing the hashcode, which is the overall goal) called the nonce. So we change the nonce, re-do the hash, is it less than the difficulty? No. Change the nonce, redo the hash. Check the difficulty/change the nonce/hash/check/change/hash/check/change..

Eventually something happens:

* we find a hash less than the current difficulty - quick! announce it to the network and get the world to verify the work, accept it and we get the reward
* someone else finds a block of transactions that has a hash less than the difficulty, they get the reward, all the transactions they packed are completed/paid - we need to start over with a new block of transactions
* we run out of nonces (there are only 4 billion) because we're hashing so fast (transaction blocks have a timestamp that increments, which also changes the hashcode, but even then coupled with the 4 billion nonces means if we hash faster than >4ghash/second we'll run out of nonces before the time ticks up by a second, so we then go and modify one of the transactions slightly, or swap it out for another) - whatever is needed to bring about even a valid single byte change in the block will produce a different hashcode, so we make that change and carry on (probably back with the nonce changing method)

---

So who is the authority on what the difficulty should be? Same as anything else with bitcoin - everyone. The network decides on the difficulty, and because all (or most) of the network are good actors, you can't cheat, you can't write a program that claims a win with some hash, because everyone else proof checks the work and they don't accept it if you cheated the hashcode, or lied about getting lower than the difficulty. It's like everyone else in the casino watched you roll, and if you rolled a 6 but shouted "i rolled a 1!" they ignore you

> **Comments:**
> **username_0**: Thank you for the detailed answer! I appreciate it! @username_2  
> **username_2**: No probs! I made a couple of edits since you've read it, but likely stuff you knew already..  

---

