<p>Difficulty is only recalculated/updated once every 2016 blocks. 
The node itself should only calculate the difficulty once every 2016 blocks.</p>

CC BY-SA 4.0
2018-07-26T13:06:05.630Z
2018-07-26T13:06:05.630Z
Samir Muradov
<p>When generating a new block, how is the nbits field in block header calculated? Is nbits calculated for every new block like:</p>

<pre><code>nbits=nbits of last block * (timstamp of lastblock-timestamp of (lastblocknum-2016))/20160 
</code></pre>

<p>Or, nbits is only updated every 2016 blocks like:</p>

<pre><code>if(currentblocknum%2016==0)
    nbits=nbits of last block * (timstamp of lastblock-timestamp of (lastblocknum-2016))/20160 
else
    nbits=nbits of lastblock
</code></pre>

<p>And when a node receives a new block, it will calculate the correct nbits itself for the new block (instead of using the nbits in the received block) before verifying the hash result, right?</p>

<p>I have not read the source code of bitcoin, and am confused by the introduction of nbits in some books. </p>

<difficulty>
How is nbits calculated?
user75243
# How is nbits calculated?

(Asked by: username_0 on 2018-01-25)

When generating a new block, how is the nbits field in block header calculated? Is nbits calculated for every new block like:

```
nbits=nbits of last block * (timstamp of lastblock-timestamp of (lastblocknum-2016))/20160 

```

Or, nbits is only updated every 2016 blocks like:

```
if(currentblocknum%2016==0)
    nbits=nbits of last block * (timstamp of lastblock-timestamp of (lastblocknum-2016))/20160 
else
    nbits=nbits of lastblock

```

And when a node receives a new block, it will calculate the correct nbits itself for the new block (instead of using the nbits in the received block) before verifying the hash result, right?

I have not read the source code of bitcoin, and am confused by the introduction of nbits in some books.

**Tags:** difficulty


---

## 1 answers

### Answer by username_1 on 2018-07-26. Score: 1

Difficulty is only recalculated/updated once every 2016 blocks.
The node itself should only calculate the difficulty once every 2016 blocks.


---

