> For the complete documentation index, see [llms.txt](https://hub.bsvblockchain.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hub.bsvblockchain.org/wiki/blocks-and-the-blockchain/blockchain/difficulty.md).

# Difficulty

**See also: Target**

1. What is difficulty? Difficulty is a measure of how difficult it is to find a hash below a given target. Difficulty answers the question: "how many times more difficult is it to mine a block now, compared with how difficult it was to mine the Genesis Block?". It has a close relationship with target but is not the same thing. Rather it has an inverse relationship where a higher difficulty implies a lower target value. The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target. Mining pools also have a pool-specific share difficulty setting a lower limit for shares.
2. How often does the network difficulty change? See target.
3. What is the formula for difficulty? difficulty = difficulty\_1\_target / current\_target *target is a 256 bit big number* *difficulty\_1\_target is the target used in the Genesis Block and represents a difficulty of 1.* difficulty\_1\_target can be different for various ways to measure difficulty. Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as "pool difficulty" or "pdiff"). The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (known as "bdiff").
4. How is difficulty stored in blocks? Each block stores a packed representation in its block header (called Bits) for its actual \[] \[]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:

```bash
0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000
```

Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.

1. How is difficulty calculated? What is the difference between bdiff and pdiff? The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of

```bash
0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
```

It should be noted that pooled mining often uses non-truncated targets, which puts "pool difficulty 1" at

```bash
0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
```

So the difficulty at 0x1b0404cb is therefore:

```bash
0x00000000FFFF0000000000000000000000000000000000000000000000000000 /
0x00000000000404CB000000000000000000000000000000000000000000000000
= 16307.420938523983 (bdiff)
```

And:

```bash
0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /
0x00000000000404CB000000000000000000000000000000000000000000000000
= 16307.669773817162 (pdiff)
```

Here's a fast way to calculate Bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:

```bash
#include
#include
inline float fast_log(float val)
{
int * const exp_ptr = reinterpret_cast (&val);
int x = *exp_ptr;
const int log_2 = ((x >> 23) & 255) - 128;
x &= ~(255 > 24)));
}
int main()
{
std::cout
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:
import decimal, math
l = math.log
e = math.e
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)
```

1. What is the current difficulty? [Current difficulty](https://whatsonchain.com/)
2. What is the maximum difficulty? There is no minimum target. The maximum difficulty is roughly: maximum\_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224). The actual maximum difficulty is when current\_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately, it never will, so we're ok.) In the case of Bitcoin (BSV) and Bitcoin Cash (BCH), the network's difficulty can rise by a maximum of 100% of the current difficulty in a single adjustment. In the original implementation, still used by Bitcoin Core (BTC), the difficulty can rise by a maximum of 400% of the current difficulty in a single adjustment.
3. Can the network difficulty decrease? Yes it can. See discussion in \[]. In the case of Bitcoin (BSV) and Bitcoin Cash (BCH), the network's difficulty can adjust downwards by up to 50% of the current difficulty in a single adjustment. In the original implementation, still used by Bitcoin Core (BTC), the network's difficulty can adjust downwards by up to 75% of the current difficulty in a single adjustment.
4. What is the minimum difficulty? The minimum difficulty, when the target is at the maximum allowed value, is 1. This is the difficulty of the Genesis block.
5. What network hash rate results in a given difficulty? The difficulty is adjusted every 2016 blocks based on the time it took to find the previous 2016 blocks. At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find. If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced. If they took less than two weeks, the difficulty is increased. The change in difficulty, is in proportion to the amount of time over or under two weeks, the previous 2016 blocks took to find. To find a block, the hash must be less than the target. The hash is effectively a random number between 0 and 2**256-1. The offset for difficulty 1 is 0xffff \* 2**208 and for difficulty D is (0xffff \* 2**208)/D The expected number of hashes we need to calculate to find a block with difficulty D is therefore D \* 2**256 / (0xffff \* 2**208) or just D \* 2**48 / 0xffff The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D \* 2**48 / 0xffff) hashes in 600 seconds. That means the hash rate of the network was D \* 2**48 / 0xffff / 600 over the previous 2016 blocks. This can be further simplified to D \* 2**32 / 600 without much loss of accuracy. At difficulty 1, that is around 7 Mhashes per second. At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found, the average network hash rate was 22012.4941572 \* 2**32 / 600 = around 157 Ghashes per second.
6. Related Links

* See also: Target

1. Attribution This content is based on content sourced from <https://en.bitcoin.it/wiki/Difficulty> under [Creative Commons Attribution 3.0](https://creativecommons.org/licenses/by/3.0/). Although it may have been extensively revised and updated, we acknowledge the original authors.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hub.bsvblockchain.org/wiki/blocks-and-the-blockchain/blockchain/difficulty.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
