<p>difficulty = hashrate / (2^32-2^16) / 600 )
= hashrate / 7158170
~ hashrate / (2^32 / 600)</p>
<p>as 2^32-2^16=0xFFFF0000 in hex, a magic constant in the code.</p>

CC BY-SA 4.0
2021-05-09T22:31:32.803Z
Hey there @Adam Back. How'd you wander upon this question?
Kinnard Hockenhull
CC BY-SA 4.0
2021-05-06T22:28:15.933Z
2021-05-06T22:28:15.933Z
Adam Back
<p>Short answer:</p>

<pre><code>  difficulty = hashrate / (2^256 / max_target / intended_time_per_block)
             = hashrate / (2^256 / (2^208*65535) / 600)
             = hashrate / (2^48 / 65535 / 600)
             = hashrate / 7158388.055
</code></pre>

<p>(where hashrate is expressed in hashes/s)</p>

<p>Longer answer: there is no direct relation between the actual network hashrate and the difficulty, because the actual hashrate cannot be observed. What happens is that every 2016 blocks, the average hashrate during that period is measured, and the difficulty is adjusted based on that.</p>

CC BY-SA 3.0
2012-11-30T20:03:05.707Z
Can you elaborate on what max_target and intended time per block is?  Are they constant?  Located in the client?  Are they calculated?
makerofthings7
CC BY-SA 3.0
2012-11-30T20:17:44.940Z
max_target is 2^208*65535 (an application-defined constant, which sets the target hash corresponding to the lowest possible difficulty, 1), and intended_time_per_block is 600 (10 minutes, also a constant).
Pieter Wuille
CC BY-SA 3.0
2012-11-30T20:28:59.570Z
http://en.bitcoin.it/wiki/Difficulty#What_is_the_maximum_difficulty.3F
Stephen Gornick
CC BY-SA 3.0
2012-12-02T16:40:44.707Z
Where does the 2^256 come from? Where did you find this info in the client? Thanks so much!!!
Kinnard Hockenhull
CC BY-SA 3.0
2012-12-05T11:19:40.667Z
@KinnardHockenhull: Hashes are 256-bit integers. The target is max_target/difficulty, so (2^256*difficulty/max_target) hashes are needed on average to find a block. So the difficulty will be the value that makes the average time for the network to find a block equal to the intended time.
Meni Rosenfeld
CC BY-SA 3.0
2012-12-11T23:42:29.837Z
Unlikely that this is localized in any one part of the source code?
Kinnard Hockenhull
CC BY-SA 3.0
2012-11-30T19:53:41.803Z
2012-11-30T19:53:41.803Z
Pieter Wuille
<p>What is the algebraic relationship between Total Network Hash-Rate and Difficulty?</p>

<difficulty><hash>
Relationship between Hash-Rate and Difficulty
Kinnard Hockenhull
# Relationship between Hash-Rate and Difficulty

(Asked by: username_0 on 2012-11-30)

What is the algebraic relationship between Total Network Hash-Rate and Difficulty?

**Tags:** difficulty, hash


---

## 2 answers

### Answer by username_2 on 2012-11-30. Score: 23 | Accepted answer

Short answer:
  difficulty = hashrate / (2^256 / max_target / intended_time_per_block)
             = hashrate / (2^256 / (2^208*65535) / 600)
             = hashrate / (2^48 / 65535 / 600)
             = hashrate / 7158388.055

(where hashrate is expressed in hashes/s)
Longer answer: there is no direct relation between the actual network hashrate and the difficulty, because the actual hashrate cannot be observed. What happens is that every 2016 blocks, the average hashrate during that period is measured, and the difficulty is adjusted based on that.

> **Comments:**
> **username_3**: Can you elaborate on what max_target and intended time per block is?  Are they constant?  Located in the client?  Are they calculated?  
> **username_2**: max_target is 2^208*65535 (an application-defined constant, which sets the target hash corresponding to the lowest possible difficulty, 1), and intended_time_per_block is 600 (10 minutes, also a constant).  
> **username_4**: http://en.bitcoin.it/wiki/Difficulty#What_is_the_maximum_difficulty.3F  
> **username_0**: Where does the 2^256 come from? Where did you find this info in the client? Thanks so much!!!  
> **username_5**: @KinnardHockenhull: Hashes are 256-bit integers. The target is max_target/difficulty, so (2^256*difficulty/max_target) hashes are needed on average to find a block. So the difficulty will be the value that makes the average time for the network to find a block equal to the intended time.  
> **username_0**: Unlikely that this is localized in any one part of the source code?  

---

### Answer by username_1 on 2021-05-06. Score: 1

difficulty = hashrate / (2^32-2^16) / 600 )
= hashrate / 7158170
~ hashrate / (2^32 / 600)

as 2^32-2^16=0xFFFF0000 in hex, a magic constant in the code.

> **Comments:**
> **username_0**: Hey there @username_1. How'd you wander upon this question?  

---

