<p>This is <em>not a duplicate</em> of previous, similar questions I've read on StackExchange, since none of those questions, nor the answers, go into the difficulty theory, as espoused on the Bitcoin Wiki.</p>

<p>Basically, I'm trying to calculate the number of attempts a miner needs to find a hash less than the target difficulty, through using some of the technical docs' on the Bitcoin Wiki. Hence, my answer is based on examples on that Wiki, but some of the explanations there are somewhat ambiguous. For example, I'm uncertain if the writer means <em>difficulty1Target</em> (they use difficulty_1_target), or difficulty 1. Therefore, I would be grateful if someone much more knowledgeable than I could run through my reasoning and also check my answer at the end.</p>

<blockquote>
  <p>The difficulty is calculated thus:</p>
  
  <p><em>difficulty = difficulty1Target / currentTarget</em></p>
  
  <p>Where <em>target</em> is a 256-bit (32-byte) number and <em>difficulty1Target</em>
  represents a hash where the leading 32 bits are zero and the rest are
  one. That is known as <em>pool difficulty</em> or <em>pdiff</em>. Floating point
  targets with limited precision allow clients to approximate
  difficulty. Such approximations are known as <em>bdiff</em>.</p>
  
  <p>Each block stores a packed representation of the hexadecimal target.
  Supposing a target of 0x1b0404cb, the hexadecimal target is:</p>
  
  <p><em>0x0404cb * 2^(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000</em></p>
  
  <p>Where 0x0404cb is a signed value. The largest legal value for that
  field is 0x7fffff and the smallest value is 0x008000.</p>
  
  <p>The highest possible target, <em>difficulty1Target</em>, is defined as
  0x1d00ffff. That gives a hexadecimal difficulty target of:</p>
  
  <p><em>0x00ffff * 2^(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000</em></p>
  
  <p>Pooled mining often uses non-truncated targets, giving a
  <em>difficulty1Target</em> of:</p>
  
  <p><em>0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF</em></p>
  
  <p>Hence, the <em>bdiff</em> difficulty at 0x1b0404cb is given by:</p>
  
  <p><em>0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x00000000000404CB000000000000000000000000000000000000000000000000
  = 16307.420938523983</em></p>
  
  <p>And the <em>pdiff</em> difficulty is:</p>
  
  <p><em>0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF / 0x00000000000404CB000000000000000000000000000000000000000000000000
  = 16307.669773817162</em></p>
  
  <p>The following formula shifts the target difficulty so that it is
  offset against the <em>difficulty1Target</em>:</p>
  
  <p><em>0xffff * 2^208</em></p>
  
  <p>And to offset for difficulty D, we have:</p>
  
  <p><em>(0xffff * 2^208)/D</em></p>
  
  <p>Since a calculated hash to test against the target will be a random
  number between 0 and 2**256-1 (SHA-256 is a 256-bit value), for any
  given difficulty D, the algorithm for estimating the average number of
  calculations needed before finding a solution, is as follows:</p>
  
  <p><em>D * 2^256 / (0xffff * 2^208), or just D * 2^48 / 0xffff</em> [@BitcoinWiki_Difficulty_2018].</p>
  
  <p>Hence, the estimated number of calculations needed to find a hash
  given the  <em>bdiff</em> difficulty at 0x1b0404cb is:</p>
  
  <p><em>16307.420938523983 * 2^48 / 0xffff = 7.0040908e+13</em></p>
</blockquote>

<p>Many thanks!</p>

CC BY-SA 4.0
2018-10-03T22:21:24.967Z
Possible duplicate of [How many hashes create one Bitcoin?](https://bitcoin.stackexchange.com/questions/12013/how-many-hashes-create-one-bitcoin)
Mason Ticehurst
CC BY-SA 4.0
2018-10-04T13:13:04.640Z
That question, nor the answers, go into the theory regarding difficulty targets, so this is _not a duplicate_. Having said that, I like, very much, one of the answers that use the published hash rate. Nice!
glowkeeper
<bitcoin-core><mining-theory><block><hash><difficulty>
Estimated number of hashes
glowkeeper
# Estimated number of hashes

(Asked by: username_0 on 2018-10-03)

This is *not a duplicate* of previous, similar questions I've read on StackExchange, since none of those questions, nor the answers, go into the difficulty theory, as espoused on the Bitcoin Wiki.

Basically, I'm trying to calculate the number of attempts a miner needs to find a hash less than the target difficulty, through using some of the technical docs' on the Bitcoin Wiki. Hence, my answer is based on examples on that Wiki, but some of the explanations there are somewhat ambiguous. For example, I'm uncertain if the writer means *difficulty1Target* (they use difficulty\_1\_target), or difficulty 1. Therefore, I would be grateful if someone much more knowledgeable than I could run through my reasoning and also check my answer at the end.

> The difficulty is calculated thus:
>
> *difficulty = difficulty1Target / currentTarget*
>
> Where *target* is a 256-bit (32-byte) number and *difficulty1Target*
> represents a hash where the leading 32 bits are zero and the rest are
> one. That is known as *pool difficulty* or *pdiff*. Floating point
> targets with limited precision allow clients to approximate
> difficulty. Such approximations are known as *bdiff*.
>
> Each block stores a packed representation of the hexadecimal target.
> Supposing a target of 0x1b0404cb, the hexadecimal target is:
>
> *0x0404cb \* 2^(8\*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000*
>
> Where 0x0404cb is a signed value. The largest legal value for that
> field is 0x7fffff and the smallest value is 0x008000.
>
> The highest possible target, *difficulty1Target*, is defined as
> 0x1d00ffff. That gives a hexadecimal difficulty target of:
>
> *0x00ffff \* 2^(8\*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000*
>
> Pooled mining often uses non-truncated targets, giving a
> *difficulty1Target* of:
>
> *0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF*
>
> Hence, the *bdiff* difficulty at 0x1b0404cb is given by:
>
> *0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x00000000000404CB000000000000000000000000000000000000000000000000
> = 16307.420938523983*
>
> And the *pdiff* difficulty is:
>
> *0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF / 0x00000000000404CB000000000000000000000000000000000000000000000000
> = 16307.669773817162*
>
> The following formula shifts the target difficulty so that it is
> offset against the *difficulty1Target*:
>
> *0xffff \* 2^208*
>
> And to offset for difficulty D, we have:
>
> *(0xffff \* 2^208)/D*
>
> Since a calculated hash to test against the target will be a random
> number between 0 and 2\*\*256-1 (SHA-256 is a 256-bit value), for any
> given difficulty D, the algorithm for estimating the average number of
> calculations needed before finding a solution, is as follows:
>
> *D \* 2^256 / (0xffff \* 2^208), or just D \* 2^48 / 0xffff* [@BitcoinWiki\_Difficulty\_2018].
>
> Hence, the estimated number of calculations needed to find a hash
> given the *bdiff* difficulty at 0x1b0404cb is:
>
> *16307.420938523983 \* 2^48 / 0xffff = 7.0040908e+13*

Many thanks!

**Tags:** bitcoin-core, mining-theory, block, hash, difficulty

> **Comments:**
> **username_1**: Possible duplicate of [How many hashes create one Bitcoin?](https://bitcoin.stackexchange.com/questions/12013/how-many-hashes-create-one-bitcoin)  
> **username_0**: That question, nor the answers, go into the theory regarding difficulty targets, so this is _not a duplicate_. Having said that, I like, very much, one of the answers that use the published hash rate. Nice!  

---

## 0 answers

