<p>For your First question please check out <a href="https://en.bitcoinwiki.org/wiki/Difficulty_in_Mining#Bitcoin_mining_difficulty" rel="nofollow noreferrer">Bitcoin Mining Difficulty</a></p>

<p>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.</p>

<p><code>Expected Time to mine last 2016 blocks = 2016 * 10 = 20160</code>
<code>Actual Time = Actual time it took</code></p>

<p><code>New Difficulty = (20160/Actual Time) * Old Difficulty</code></p>

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

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

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

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

CC BY-SA 4.0
2019-04-08T07:12:17.997Z
Sir, Do you have any idea about Question 1?
Akhil Nadh PC
CC BY-SA 4.0
2019-04-08T05:28:40.380Z
2019-04-08T13:36:28.187Z
2019-04-08T13:36:28.187Z
Asad Hayat
<blockquote>
  <p>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.</p>
</blockquote>

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

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

<p>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 <code>0x00000000ffff0000000000000000000000000000000000000000000000000000</code>. The current target hash is finding block header less than <code>0x0000000000000000002c071d0000000000000000000000000000000000000000</code>. So your difficulty number is <code>genesis block header hash target/current block header hash target</code>. That's how you get 6393023717201.863.</p>

<p>Refer <a href="https://bitcoin.stackexchange.com/questions/44579/how-is-a-block-header-hash-compared-to-the-target-bits">here</a> for more info as to how block header hash target is determined using target bits that are in the block header.</p>

<blockquote>
  <p>Why difficulty decreases at some point in time?</p>
</blockquote>

<p>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. </p>

CC BY-SA 4.0
2021-04-30T11:49:32.160Z
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
CC BY-SA 4.0
2021-06-21T17:10:26.977Z
@Mariusz the goal of Bitcoin blockchain is to represent an unequivocal truth of the transactions. This difficulty prevents double spend attacks and ensures all people converge to the same truth. Large blocks and lower block time will result in sync challenges especially in a P2P system. If you want high volume transactions, you can use Lightning Network or sidechains.
Ugam Kamat
CC BY-SA 4.0
2021-06-22T08:52:29.657Z
Thanks. This is how I understand it at the moment also. It seems to me that it's not scalable by design, or at least in environment where parties using it cannot trust each other.

At the moment I tend to think that bitcoin can be only used as additional means of exchanging value and cannot become mainstream.
Mariusz
CC BY-SA 4.0
2024-06-05T20:41:37.520Z
Difficulty is needed to control the block generation, without this parameter, the network will be flooded with blocks and it will become unusable.
charles
CC BY-SA 4.0
2019-04-08T09:33:35.173Z
2019-04-08T09:33:35.173Z
Ugam Kamat
<p>I understand that the Bitcoin mining problem is to find a <strong>string s</strong> (hash of previous block + Merkle Tree Hash + nonce) such that <strong>sha256(s)</strong> has <strong>n</strong> leading zeros, where <strong>n</strong> determines the mining difficulty.</p>
<p><a href="https://i.sstatic.net/bSp6c.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bSp6c.png" alt="Minng Difficulty" /></a></p>
<p>According to <a href="https://www.blockchain.com/en/charts/difficulty" rel="nofollow noreferrer">Blockchain.Info</a>, The Current Difficulty is 63,93,02,37,17,201.</p>
<p><a href="https://i.sstatic.net/VsFi8.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/VsFi8.png" alt="enter image description here" /></a></p>
<p>The output of <strong>sha256()</strong> is a 16 bit hex value.</p>
<p><strong>Question 1</strong>
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.</p>
<p><strong>Question 2</strong>
Why is difficulty decreases at some point in time?</p>

<bitcoin-core><difficulty>
Mining Difficulty and Leading Zeros
Akhil Nadh PC
# Mining Difficulty and Leading Zeros

(Asked by: username_0 on 2019-04-08)

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.

[![Minng Difficulty](https://i.sstatic.net/bSp6c.png)](https://i.sstatic.net/bSp6c.png)

According to [Blockchain.Info](https://www.blockchain.com/en/charts/difficulty), The Current Difficulty is 63,93,02,37,17,201.

[![enter image description here](https://i.sstatic.net/VsFi8.png)](https://i.sstatic.net/VsFi8.png)

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?

**Tags:** bitcoin-core, difficulty


---

## 2 answers

### Answer by username_2 on 2019-04-08. Score: 7 | Accepted answer

> 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](https://bitcoin.stackexchange.com/questions/44579/how-is-a-block-header-hash-compared-to-the-target-bits) 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.

> **Comments:**
> **username_3**: 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?  
> **username_2**: @username_3 the goal of Bitcoin blockchain is to represent an unequivocal truth of the transactions. This difficulty prevents double spend attacks and ensures all people converge to the same truth. Large blocks and lower block time will result in sync challenges especially in a P2P system. If you want high volume transactions, you can use Lightning Network or sidechains.  
> **username_3**: Thanks. This is how I understand it at the moment also. It seems to me that it's not scalable by design, or at least in environment where parties using it cannot trust each other.  At the moment I tend to think that bitcoin can be only used as additional means of exchanging value and cannot become mainstream.  
> **username_4**: Difficulty is needed to control the block generation, without this parameter, the network will be flooded with blocks and it will become unusable.  

---

### Answer by username_1 on 2019-04-08. Score: 3

For your First question please check out [Bitcoin Mining Difficulty](https://en.bitcoinwiki.org/wiki/Difficulty_in_Mining#Bitcoin_mining_difficulty)

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.

> **Comments:**
> **username_0**: Sir, Do you have any idea about Question 1?  

---

