I understand that the Bitcoin mining problem is to find a string s (hash of previous block + Merkle Tree Hash + nonce) such that sha256(s) has n leading zeros, where n determines the mining difficulty.

According to Blockchain.Info, The Current Difficulty is 63,93,02,37,17,201.

The output of sha256() is a 16 bit hex value.

Question 1 The above image indicates that if N=4, there are 4 zeroes in the 16bit hex value. So if N=16 is the entire string is expected to have only zeroes? Please explain difficulty using this example. So if N=6393023717201 How do I expect 63,93,02,37,17,201 number of zeroes in 16bit length string? Please explain the significance of this huge number of zeroes in this context.

Question 2 Why is difficulty decreases at some point in time?

Bitcoin mining problem is to find a string s (hash of previous block + Merkle Tree Hash + nonce) such that sha256(s) has n leading zeros, where n determines the mining difficulty.

First a clarification. string s (block header) will include hash of previous block header, merkle root, nonce, target bits, timestamp and nonce.

So if N=6393023717201, how do I expect 63,93,02,37,17,201 number of zeroes in 16bit length string?

That is not how difficulty is represented. We start with the genesis block that has a difficulty of 1. At that difficulty we needed to find the block hash that was less than 0x00000000ffff0000000000000000000000000000000000000000000000000000. The current target hash is finding block header less than 0x0000000000000000002c071d0000000000000000000000000000000000000000. So your difficulty number is genesis block header hash target/current block header hash target. That's how you get 6393023717201.863.

Refer here for more info as to how block header hash target is determined using target bits that are in the block header.

Why difficulty decreases at some point in time?

In bitcoin the difficulty keeps the average block time at 10 minutes. If miners start using sophisticated instruments (eg. ASIC chips) that find the solution to the block header faster than 10 minutes, then every 2016 block the difficulty is adjusted so that the time needed to mine blocks increases. If miners start lowering their investments in sophisticated instruments so that average block mining time over 2016 blocks is more than 10 minutes, then the difficulty is lowered so that block mining time is faster. All of this is done so that we converge to 10 minutes as the average block mining time.

• Why this "difficulty" is needed in the first place? Does it limit Bitcoin's transaction throughput and in effect makes it difficult to scale up/out? Can this limitation prevent Bitcoin to serve as main-stream currency where there's need for large volume of transactions being possible? – Mariusz Apr 30 at 11:49

The Answer to your second question: Bitcoin network adjusts its difficulty every 2016 blocks (about 2 weeks). The difficulty adjustment is such that, if the average time to mine a block is greater than 10 minutes, then the difficulty will decrease. If the average time for mining a block is less than 10 minutes, then the difficulty will increase.

Expected Time to mine last 2016 blocks = 2016 * 10 = 20160 Actual Time = Actual time it took

New Difficulty = (20160/Actual Time) * Old Difficulty

Now if the average mining time for last 2016 blocks is less than 10 mins, then;

(20160/Actual Time) > 1; and hence new difficulty will be greater than old value.

Similarly if the average mining time for last 2016 blocks is greater than 10 mins, then;

(20160/Actual Time) < 1; and hence new difficulty will be lower than old value.

• Sir, Do you have any idea about Question 1? – Akhil Nadh PC Apr 8 '19 at 7:12