<p>Leading ones or trailing ones will work as well as leading zeroes or trailing zeroes, it looks like a random choice from four equivalent cases.</p>

<p>Starting index from middle point might limit that value of maximal hardness of the mining, unless using of some sophisticated bit shifts for overcoming the limit, which may be slightly awkward for supporting in future. Non-regular patterns, like mathematical constants, might add even more pain for some kinds of developers and will not be obvious at all when looking at bit string of hash sum.</p>

CC BY-SA 3.0
2017-08-09T05:59:23.563Z
2017-08-09T05:59:23.563Z
Eimrine
<p>The "leading zeros" are a simplification. The difficulty is encoded as a <em>target</em> which is essentially a 256 bit number. Since block hashes are produced by SHA-256, they're also a string of 256 bits. If a block candidate's hash interpreted as a number is numerically smaller than the target, the block candidate is a valid block.</p>

CC BY-SA 3.0
2017-08-09T20:10:38.820Z
Sensical! So if I know a target has `n` leading zeroes, that's shorthand for saying that the actual specific target lies somewhere between `[ 16^(63-n), 16^(64-n) )`, yeah?
Jacob Ford
CC BY-SA 3.0
2017-08-09T20:52:50.790Z
I'd have said `[ 2^(255-n)-1, 2^(256-n)-1 )`, but besides that yeah.
Murch
CC BY-SA 3.0
2017-08-09T06:30:32.187Z
2017-08-09T06:30:32.187Z
Murch
<p>I understand how generating a SHA-256 hash containing <em>any</em> specified sequence requires lots of guessing and checking. The longer the specified sequence, the more rarely that it will appear.</p>

<p>And I understand how inserting random nonces into a block until its hash happens to begin with a certain number of <code>0</code>s is a computationally expensive and ultimately random process, which demonstrates proof of work.</p>

<p>What I’m wondering is: why <strong>zeroes</strong>, and why <strong>leading</strong>?</p>

<p>Could mining work just as feasibly if the challenge were to produce a hash with, say, ends in a certain number of <code>F</code>s, or has the digits <code>314159265358979...</code> starting at index 32?</p>

<p>Or is there a technical reason why miners’ goal is to produce a hash which begins with <code>0</code>s, and not any other character at any other location in the hash?</p>

<mining-theory><hash><difficulty>
Why is difficulty measured in a hash’s leading zeroes?
Jacob Ford
# Why is difficulty measured in a hash’s leading zeroes?

(Asked by: username_0 on 2017-08-09)

I understand how generating a SHA-256 hash containing *any* specified sequence requires lots of guessing and checking. The longer the specified sequence, the more rarely that it will appear.

And I understand how inserting random nonces into a block until its hash happens to begin with a certain number of `0`s is a computationally expensive and ultimately random process, which demonstrates proof of work.

What I’m wondering is: why **zeroes**, and why **leading**?

Could mining work just as feasibly if the challenge were to produce a hash with, say, ends in a certain number of `F`s, or has the digits `314159265358979...` starting at index 32?

Or is there a technical reason why miners’ goal is to produce a hash which begins with `0`s, and not any other character at any other location in the hash?

**Tags:** mining-theory, hash, difficulty


---

## 2 answers

### Answer by username_2 on 2017-08-09. Score: 7 | Accepted answer

The "leading zeros" are a simplification. The difficulty is encoded as a *target* which is essentially a 256 bit number. Since block hashes are produced by SHA-256, they're also a string of 256 bits. If a block candidate's hash interpreted as a number is numerically smaller than the target, the block candidate is a valid block.

> **Comments:**
> **username_0**: Sensical! So if I know a target has `n` leading zeroes, that's shorthand for saying that the actual specific target lies somewhere between `[ 16^(63-n), 16^(64-n) )`, yeah?  
> **username_2**: I'd have said `[ 2^(255-n)-1, 2^(256-n)-1 )`, but besides that yeah.  

---

### Answer by username_1 on 2017-08-09. Score: 1

Leading ones or trailing ones will work as well as leading zeroes or trailing zeroes, it looks like a random choice from four equivalent cases.

Starting index from middle point might limit that value of maximal hardness of the mining, unless using of some sophisticated bit shifts for overcoming the limit, which may be slightly awkward for supporting in future. Non-regular patterns, like mathematical constants, might add even more pain for some kinds of developers and will not be obvious at all when looking at bit string of hash sum.


---

