<p>In short: no, the nBits encoding is not unique (there may be multiple 32-bit values that correspond to the same 256-bit target), but the nBits value as required by the network consensus rules is unique.</p>

<p>The reason for that is that all calculations happen on the target, which is then converted (using a deterministic algorithm) into nBits format. That nBits value is then required to match the value in the block header.</p>

CC BY-SA 4.0
2019-04-19T23:11:03.413Z
Yeah, I guess I was hoping for some more technical details? What is the algorithm to make sure everyone is using the same rep of bits?
Stephen C
CC BY-SA 4.0
2019-04-19T23:15:21.760Z
@StephenCowley The point of consensus rules is that everyone uses the same ones; if they don't, they'd end up on their own chain. So by definition everyone who follows Bitcoin's consensus rules uses the same algorithm. In Bitcoin Core, that code is https://github.com/bitcoin/bitcoin/blob/v0.17.1/src/pow.cpp#L71 and https://github.com/bitcoin/bitcoin/blob/v0.17.1/src/arith_uint256.cpp#L226L247
Pieter Wuille
CC BY-SA 4.0
2019-04-18T21:35:26.853Z
2019-04-18T21:35:26.853Z
Pieter Wuille
<p>The <code>bits</code> field is the compact representation of the <code>target</code>.</p>

<p>Example:</p>

<pre><code>bits: 1d00ffff
target: 00ffff0000000000000000000000000000000000000000000000000000

bits: 1cfff00
target: ffff0000000000000000000000000000000000000000000000000000
</code></pre>

<p>But these two actually represent the same number.</p>

<p><code>int(target) -&gt;  26959535291011309493156476344723991336010898738574164086137773096960</code>
 for both of the above targets.</p>

<p>What (if anything) makes <code>bits</code> a <em>unique</em> representation of the <code>target</code>?</p>

<hr>

<p>Clarification:</p>

<p>In regular interactions with numbers, this kind of thing doesn't really matter, as a few leading zeros don't affect how we interpret the number. However, in Bitcoin, the <code>bits</code> field is used as part of the hash of the block. Therefore, a different <code>bits</code> representation would produce a different hash of the block.</p>

CC BY-SA 4.0
2019-04-18T15:28:40.910Z
@NateEldredge Thanks for pointing this out. I've added a clarification to the question.
Stephen C
CC BY-SA 4.0
2019-04-18T15:40:22.527Z
Some related fun, try and establish why the there is a sign bit in the target.
Claris
CC BY-SA 4.0
2019-04-18T15:45:02.543Z
@Anonymous _Is_ there a sign bit?
Stephen C
CC BY-SA 4.0
2019-04-18T16:05:20.373Z
There is a sign bit.
Claris
CC BY-SA 4.0
2019-04-19T05:16:19.877Z
See the answer over here for representation of sign bit. https://bitcoin.stackexchange.com/questions/48707/difficulty-target-representation-in-bitcoin-wiki
Ugam Kamat
<difficulty>
Is the bits field a unique representation of the target?
Stephen C
# Is the bits field a unique representation of the target?

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

The `bits` field is the compact representation of the `target`.

Example:

```
bits: 1d00ffff
target: 00ffff0000000000000000000000000000000000000000000000000000

bits: 1cfff00
target: ffff0000000000000000000000000000000000000000000000000000

```

But these two actually represent the same number.

`int(target) -> 26959535291011309493156476344723991336010898738574164086137773096960`
for both of the above targets.

What (if anything) makes `bits` a *unique* representation of the `target`?

---

Clarification:

In regular interactions with numbers, this kind of thing doesn't really matter, as a few leading zeros don't affect how we interpret the number. However, in Bitcoin, the `bits` field is used as part of the hash of the block. Therefore, a different `bits` representation would produce a different hash of the block.

**Tags:** difficulty

> **Comments:**
> **username_0**: @NateEldredge Thanks for pointing this out. I've added a clarification to the question.  
> **username_1**: Some related fun, try and establish why the there is a sign bit in the target.  
> **username_0**: @Anonymous _Is_ there a sign bit?  
> **username_1**: There is a sign bit.  
> **username_2**: See the answer over here for representation of sign bit. https://bitcoin.stackexchange.com/questions/48707/difficulty-target-representation-in-bitcoin-wiki  

---

## 1 answers

### Answer by username_3 on 2019-04-18. Score: 4 | Accepted answer

In short: no, the nBits encoding is not unique (there may be multiple 32-bit values that correspond to the same 256-bit target), but the nBits value as required by the network consensus rules is unique.

The reason for that is that all calculations happen on the target, which is then converted (using a deterministic algorithm) into nBits format. That nBits value is then required to match the value in the block header.

> **Comments:**
> **username_0**: Yeah, I guess I was hoping for some more technical details? What is the algorithm to make sure everyone is using the same rep of bits?  
> **username_3**: @StephenCowley The point of consensus rules is that everyone uses the same ones; if they don't, they'd end up on their own chain. So by definition everyone who follows Bitcoin's consensus rules uses the same algorithm. In Bitcoin Core, that code is https://github.com/bitcoin/bitcoin/blob/v0.17.1/src/pow.cpp#L71 and https://github.com/bitcoin/bitcoin/blob/v0.17.1/src/arith_uint256.cpp#L226L247  

---

