# What are the units of “difficulty”?

In various places, e.g. here and here, there are plots of the "difficulty" of bitcoin mining over time. What exactly is the interpretation of these numbers - in what units are they measured?

My first thought was that the "difficulty" is the number of bits that should be zero in SHA256(block+nonce). But, in this case the difficulty should have been a number between 0 and 255, and these sites show much higher numbers.

My second thought was that SHA256(block+nonce) should be at most 2^256-difficulty. But, in this case it should be an integer, while this link shows that the current difficulty level is not an integer.

So, what exactly the number called "difficulty" represent?

• What you meant in "second thought" is probably Target – CoperNick Jun 4 '18 at 13:18

Difficulty is a multiple of the minimum amount of Proof of Work (PoW) any valid block can contain. In Bitcoin, the minimum difficulty (called difficulty 1) is defined in the code by this byte mask:

``````consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
``````

That is, a hash must start[*] with 8 hexadecimal zeros. That's 4 zero bytes, or 32 zero bits.

If you double that difficulty, that's difficulty 2. Double it again and it's difficulty 4, then 8, then 16. At difficulty 16, the hash must have at least 8 + 1 = 9 zeros. Double it again and it's 32, then 64, then 128, then 256. At difficulty 256, the hash must have a minimum of 8 + 2 zeros. Et cetra...

As I write this, the current difficulty is 4306949573981.513. We can see how many minimum zeros that corresponds to by taking its binary log, dividing by the 4 bits that are in in half a byte (one hexadecimal character) and adding the eight zeros from the minimum difficulty:

``````log2(4306949573981.513) / 4 + 8
= 18.49245089279219
``````

For comparison, here's the most recent block header hash (reformatted into byte pairs for readability). It has 18 zeros, as expected. (Note: if you do this experiment at home, note that the hashes are always allowed to have more zeros; they just can't have less.)

``````0000 0000 0000 0000 0023 bfeb 3a02 1b25 7577 9256 7762 275e b72a d88b 7d50 d7f7
``````

[*] Bitcoin is weird. We display hashes backwards from most other software, so the zeros that start a block header hash are actually at end if you use any non-Bitcoin software to do the hashing.

• So, 32+log2(difficulty) is the number of initial bits that should be zero? If so, shouldn't the difficulty level always be a power of two, as in your examples? – Erel Segal-Halevi Jun 4 '18 at 14:57
• Yes, that's the number of bits. However, in Bitcoin (unlike hashcash), difficulty can be fractional because the amount of PoW required (the "target") is specified using a byte mask rather than just the number of bits. For example, a byte mask of 00000000ffff...fffe would require on average just doing one more hash than the minimum difficulty. In practice, Bitcoin targets have limited precision, but they're plenty precise enough to provide for very fractional difficulty. – David A. Harding Jun 4 '18 at 15:07
• So, is the formula SHA256(block+nonce) < 2^224 / difficulty ? – Erel Segal-Halevi Jun 4 '18 at 17:29
• Difficulty is calculated from the target, which is itself derived from 32 bits in the header of every block. For formulas you can use to calculate it, see en.bitcoin.it/wiki/Difficulty and bitcoin.org/en/developer-reference#target-nbits – David A. Harding Jun 4 '18 at 17:37

Difficulty represents the expected number of hashes it takes to find a valid one. The probability of a hash being valid is inversely proportional to the difficulty. The constant of proportionality is (2^16-1)/(2^48); that is, the probability of a hash being valid is (2^16-1)/(difficulty*2^48)

It means how many times it is harder to mine than in the early days of Bitcoin. In early days it was used some kind of minimum difficulty.

AFAIK Bitcoin code do not operate on "difficulty". Instead of "difficulty" Bitcoin operates on Target which is more useful in source code.

Simple put difficulty is a scaling parameter it does not have units.

To understand what is actually is doing requires a little background:

A bitcoin hash is comprised of 64 hex characters. Or in other words, 16^64 unique encodings (1.15 * 10^77).

The minimum proof of work (PoW) for a Bitcoin is to find a hash which has 8 zero hex characters at the start of the hash:

``````0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
``````

Therefore if you were guessing and checking (which the SHA256 algorithm is designed to be a close equivalent to), then you would need to guess 16^8 times before you could expect to find the correct hash (or there is a 1/(16^8) chance of finding the correct hash each time you compute a hash), so if you were hashing at a rate of 4.29 GH/s, you would achieve this in 1 second.

Bitcoin's design is to have a Block Reward every 10 minutes. Therefore in order to ensure that the coin is mined at this rate, there will need to be an adjustment to the difficulty which is done by adding a zero to the target hash.

A difficulty of 1 is the minimum proof of work. If another zero is added the difficulty doubles to 2. It is, therefore, a judge of how many times longer it would take you to find a reward given the same hashing rate.

### Example

The minimum PoW would be expected to require 16^8 or 4294967296 hashes to solve.

As of 1/10/2020, the difficulty of Bitcoin is 13798783827516.4. It would be expected that we would need to go through 5.92653E+22 Hashes before we found a block reward.

If we had a global pool hash rate of 1.0728E+20 Hashes/second. Then we would find a block every 552.4 seconds or 9.2 minutes.

This is faster than the target of 10 minutes and the average would be taken to determine if it was luck or if indeed the mining pool is hashing at a faster rate and the difficulty would therefore increase.

Difficulty has units, and these are "Trials / Nonce". (Trials = Hashes)

It is the number of trials (or hashes computed) per nonce, on average, which will yield a success ( A "success" is defined as finding the variables to the hash function which will yield a result that meets or exceeds the difficulty threshold )

The Equation that governs this is:

HashRate (trials/second) = Difficulty (trials/nonce) * [Blocks_found/Blocks_expected] * [ Size_of_nonce_space (nonces) / target_block_time (seconds) ]

(Note: This equation is normally used to set the mining difficulty to match the hashrate on the network.
In our case, we assume that difficulty threshold is matched to the network's HashRate, so Blocks_found = Blocks_expected, and this term reduces to unity)

Currently (February 2020), in the case of bitcoin, to find a block:

Difficulty is 15.5 Tera (trials/nonce) * 1 * ( Nonce space is 2^32 nonces / 600 seconds) =

107.37 Exa (trials / second) is the Hashrate