<p>See <a href="https://en.bitcoin.it/wiki/Difficulty#How_is_difficulty_calculated.3F_What_is_the_difference_between_bdiff_and_pdiff.3F" rel="nofollow">https://en.bitcoin.it/wiki/Difficulty#How_is_difficulty_calculated.3F_What_is_the_difference_between_bdiff_and_pdiff.3F</a></p>

<p>For example, block <code>#347444</code>:</p>

<pre><code>0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 
0x000000000000000014a5256523f37dd374dcb1e0840a85ab4d0cea60bad043d8
= 53256935148.82868
</code></pre>

<p>For fun, we can calculate the difficulty the smallest block hash ever mined (as of block <code>#347444</code>) could have satisfied.</p>

<p>First lets get the list from my Bitcoin Abe database:</p>

<pre><code>MariaDB [abe]&gt; SELECT hex(block_hash), block_height FROM block ORDER BY block_hash ASC LIMIT 10;
+------------------------------------------------------------------+--------------+
| hex(block_hash)                                                  | block_height |
+------------------------------------------------------------------+--------------+
| 000000000000000000002D414BB8F9175BA6C6563721E1BA2C1373C2BD94F29F |       334261 |
| 000000000000000000005A5E143087632FBF0EEA743AD99646D9FC67D40F7441 |       336175 |
| 000000000000000000006836C4009AB00485CD1DE4D5958CA7839184D0B80067 |       331908 |
| 000000000000000000007E1166D92ACF81D4E2D95934FCDEC1276B09A7DB9390 |       326055 |
| 000000000000000000007EEF13EE1F2FCF1B469BD862FCC93B48EC49548ECF6D |       343775 |
| 000000000000000000008AC86BA28085BE84AF2EBD6FC6935A004E57FB60C083 |       340483 |
| 00000000000000000000B7DE9E5C19E52BE073156924B7CF235EFB27AE8A202A |       313338 |
| 00000000000000000000EC03E3183BACC8B18437180F63F6A563267A186225BC |       331987 |
| 0000000000000000000119ADB3DA72742B1EBA98F9DC26F73858E91652B42287 |       334151 |
| 0000000000000000000119F88871F8A3C3B7BE053C98B31E9C4676DF30243CFE |       333904 |
+------------------------------------------------------------------+--------------+
10 rows in set (0.06 sec)
</code></pre>

<p>Then we pass that to Python (I ran a modified version of the query above to print a format Python understands):</p>

<pre><code>&gt;&gt;&gt; # 334261
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x000000000000000000002D414BB8F9175BA6C6563721E1BA2C1373C2BD94F29F
1592230611213387.2
&gt;&gt;&gt; # 336175
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x000000000000000000005A5E143087632FBF0EEA743AD99646D9FC67D40F7441
797371821285215.2
&gt;&gt;&gt; # 331908
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x000000000000000000006836C4009AB00485CD1DE4D5958CA7839184D0B80067
691428638477639.5
&gt;&gt;&gt; # 326055
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x000000000000000000007E1166D92ACF81D4E2D95934FCDEC1276B09A7DB9390
571568585825999.9
&gt;&gt;&gt; # 343775
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x000000000000000000007EEF13EE1F2FCF1B469BD862FCC93B48EC49548ECF6D
567669438511087.9
&gt;&gt;&gt; # 340483
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x000000000000000000008AC86BA28085BE84AF2EBD6FC6935A004E57FB60C083
519203003284590.0
&gt;&gt;&gt; # 313338
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x00000000000000000000B7DE9E5C19E52BE073156924B7CF235EFB27AE8A202A
391889105139868.25
&gt;&gt;&gt; # 331987
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x00000000000000000000EC03E3183BACC8B18437180F63F6A563267A186225BC
305304486446787.75
&gt;&gt;&gt; # 334151
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x0000000000000000000119ADB3DA72742B1EBA98F9DC26F73858E91652B42287
255811103719832.1
&gt;&gt;&gt; # 333904
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x0000000000000000000119F88871F8A3C3B7BE053C98B31E9C4676DF30243CFE
255545915930877.94
</code></pre>

<p>Therefore the highest difficulty target ever attained as of block <code>#347444</code> is <code>1,592,230,611,213,387.2</code> for block <code>#334261</code></p>

<p>NB: Use Python 3 to get decimals, Python 2.x truncates the fractional digits.</p>

CC BY-SA 3.0
2015-03-13T15:08:37.860Z
Of course, as @NickODell pointed out in another answer, the hashed block data includes its difficulty, so this is all theoretical, the block still satisfies only the difficulty it was mined for and that cannot be changed.
Thomas Guyot-Sionnest
CC BY-SA 3.0
2015-03-13T15:04:48.750Z
2015-03-13T15:04:48.750Z
Thomas Guyot-Sionnest
<p>A hash only meets one difficulty, because when mining, you set a field called <code>nBits</code>, which describes the difficulty you were mining for. You cannot change this field without changing the hash and starting over.</p>

<pre><code>bnTarget.SetCompact(nBits, &amp;fNegative, &amp;fOverflow);
[...]
if (UintToArith256(hash) &gt; bnTarget)
</code></pre>

<p><a href="https://github.com/bitcoin/bitcoin/blob/e564e63ef04e55b1e446f8440d51c611bc41cec6/src/pow.cpp#L84" rel="nofollow">(source)</a></p>

CC BY-SA 3.0
2015-03-13T14:34:28.280Z
2015-03-13T14:34:28.280Z
Nick ODell
<p>What is an algorithm to determine what maximum difficulty already found hash meets?</p>

<hash><difficulty>
Difficulty for hash (reversed function of "does hash met difficulty/target")
velurex
# Difficulty for hash (reversed function of "does hash met difficulty/target")

(Asked by: username_0 on 2015-03-13)

What is an algorithm to determine what maximum difficulty already found hash meets?

**Tags:** hash, difficulty


---

## 2 answers

### Answer by username_1 on 2015-03-13. Score: 2 | Accepted answer

See <https://en.bitcoin.it/wiki/Difficulty#How_is_difficulty_calculated.3F_What_is_the_difference_between_bdiff_and_pdiff.3F>

For example, block `#347444`:

```
0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 
0x000000000000000014a5256523f37dd374dcb1e0840a85ab4d0cea60bad043d8
= 53256935148.82868

```

For fun, we can calculate the difficulty the smallest block hash ever mined (as of block `#347444`) could have satisfied.

First lets get the list from my Bitcoin Abe database:

```
MariaDB [abe]> SELECT hex(block_hash), block_height FROM block ORDER BY block_hash ASC LIMIT 10;
+------------------------------------------------------------------+--------------+
| hex(block_hash)                                                  | block_height |
+------------------------------------------------------------------+--------------+
| 000000000000000000002D414BB8F9175BA6C6563721E1BA2C1373C2BD94F29F |       334261 |
| 000000000000000000005A5E143087632FBF0EEA743AD99646D9FC67D40F7441 |       336175 |
| 000000000000000000006836C4009AB00485CD1DE4D5958CA7839184D0B80067 |       331908 |
| 000000000000000000007E1166D92ACF81D4E2D95934FCDEC1276B09A7DB9390 |       326055 |
| 000000000000000000007EEF13EE1F2FCF1B469BD862FCC93B48EC49548ECF6D |       343775 |
| 000000000000000000008AC86BA28085BE84AF2EBD6FC6935A004E57FB60C083 |       340483 |
| 00000000000000000000B7DE9E5C19E52BE073156924B7CF235EFB27AE8A202A |       313338 |
| 00000000000000000000EC03E3183BACC8B18437180F63F6A563267A186225BC |       331987 |
| 0000000000000000000119ADB3DA72742B1EBA98F9DC26F73858E91652B42287 |       334151 |
| 0000000000000000000119F88871F8A3C3B7BE053C98B31E9C4676DF30243CFE |       333904 |
+------------------------------------------------------------------+--------------+
10 rows in set (0.06 sec)

```

Then we pass that to Python (I ran a modified version of the query above to print a format Python understands):

```
>>> # 334261
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x000000000000000000002D414BB8F9175BA6C6563721E1BA2C1373C2BD94F29F
1592230611213387.2
>>> # 336175
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x000000000000000000005A5E143087632FBF0EEA743AD99646D9FC67D40F7441
797371821285215.2
>>> # 331908
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x000000000000000000006836C4009AB00485CD1DE4D5958CA7839184D0B80067
691428638477639.5
>>> # 326055
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x000000000000000000007E1166D92ACF81D4E2D95934FCDEC1276B09A7DB9390
571568585825999.9
>>> # 343775
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x000000000000000000007EEF13EE1F2FCF1B469BD862FCC93B48EC49548ECF6D
567669438511087.9
>>> # 340483
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x000000000000000000008AC86BA28085BE84AF2EBD6FC6935A004E57FB60C083
519203003284590.0
>>> # 313338
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x00000000000000000000B7DE9E5C19E52BE073156924B7CF235EFB27AE8A202A
391889105139868.25
>>> # 331987
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x00000000000000000000EC03E3183BACC8B18437180F63F6A563267A186225BC
305304486446787.75
>>> # 334151
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x0000000000000000000119ADB3DA72742B1EBA98F9DC26F73858E91652B42287
255811103719832.1
>>> # 333904
... 0x00000000FFFF0000000000000000000000000000000000000000000000000000 / 0x0000000000000000000119F88871F8A3C3B7BE053C98B31E9C4676DF30243CFE
255545915930877.94

```

Therefore the highest difficulty target ever attained as of block `#347444` is `1,592,230,611,213,387.2` for block `#334261`

NB: Use Python 3 to get decimals, Python 2.x truncates the fractional digits.

> **Comments:**
> **username_1**: Of course, as @username_2 pointed out in another answer, the hashed block data includes its difficulty, so this is all theoretical, the block still satisfies only the difficulty it was mined for and that cannot be changed.  

---

### Answer by username_2 on 2015-03-13. Score: 1

A hash only meets one difficulty, because when mining, you set a field called `nBits`, which describes the difficulty you were mining for. You cannot change this field without changing the hash and starting over.

```
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
[...]
if (UintToArith256(hash) > bnTarget)

```

[(source)](https://github.com/bitcoin/bitcoin/blob/e564e63ef04e55b1e446f8440d51c611bc41cec6/src/pow.cpp#L84)


---

