<p>To calculate the PoW hash, all the data of the header of the block is concatenated. The nonce is also concatenated within that data.
Then, that concatenated data is put through the <code>SHA256</code> algorithm and the result is compared to the current target. The resulting hash needs to be smaller than the target to be valid.</p>
<p>So, it's not about how many zeros it has, but if it's smaller than the target.
Seeing it in terms of zeros could help to understand it, but that is miss leading. There could be 1 hash that has exactly the same number of zeros as the target and still not be valid, because it may not be smaller than the target.</p>
<p>For example, let's assume that the target is:</p>
<p><code>00000000000000000004f34860a8c59d52c4472ec3798c16f394a699f5e6d8b6</code>
And our <code>SHA256</code> hash is:</p>
<p><code>00000000000000000005f34860a8c59d52c4472ec3798c16f394a699f5e6d8b6</code>
It would not be a valid PoW hash because it's not smaller than the target. They both have the same amount of zeros, but our hash is greater than the target.</p>
<p>Both together:
<code>00000000000000000004f34860a8c59d52c4472ec3798c16f394a699f5e6d8b6 00000000000000000005f34860a8c59d52c4472ec3798c16f394a699f5e6d8b6</code>
If we keep changing a bit the data, by increasing the nonce by 1 and then concatenating it again with the data of the block header, and pass it through the <code>SHA256</code> alright again and again, eventually we will get a hash that is smaller than the target.</p>
<p>For example:</p>
<p>Target:</p>
<p><code>00000000000000000004f34860a8c59d52c4472ec3798c16f394a699f5e6d8b6</code></p>
<p>Our hash:</p>
<p><code>00000000000000000003f34860a8c59d52c4472ec3798c16f394a699f5e6d8b6</code>
As you can see, our hash now is smaller than the target and is a valid PoW hash for our block.</p>
<p>The hash of the block header data could even be way smaller than the target, and it's valid. It can have more zeros, but finding a hash like this is less probable in average:</p>
<p><code>00000000000000000000000000a8c59d52c4472ec3798c16f394a699f5e6d8b6</code></p>
<p>To visualize it better, you can go to this site that has a simple blockchain implementation to visualize how a blockchain works: <a href="https://andersbrownworth.com/blockchain/blockchain" rel="nofollow noreferrer">https://andersbrownworth.com/blockchain/blockchain</a></p>
<p>I've concatenated the data of the block <code>5</code> and passed it through a <code>SHA256</code> function:</p>
<p>Concatenated data:</p>
<p><code>529742data0000ae8bbc96cf89c68be6e10a865cc47c6c48a9ebec3c6cad729646cefaef83</code></p>
<p><a href="https://andersbrownworth.com/blockchain/hash" rel="nofollow noreferrer">SHA256</a> hash of that data:</p>
<p><code>0000d73c6ecf38aa53a8fbace738ff59540fd5e519e6d9aa496f61ce70110a09</code>
If we compare the <code>hash</code> of block <code>5</code> with this one, it's the same.</p>

CC BY-SA 4.0
2022-09-09T14:15:29.950Z
2022-09-09T14:15:29.950Z
Jeremy Then
<p>If I undestend the your question,</p>

<p>This is an example of the proof-of-work <a href="https://github.com/bitcoinbook/bitcoinbook/blob/develop/code/proof-of-work-example.py" rel="nofollow noreferrer">algorithm</a>.</p>

<p>The nonce is a component of the block, the strucure of the block contain the value, inside the <a href="https://www.blockchain.com/it/btc/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" rel="nofollow noreferrer">blockchain.com</a> you can find the value inside the propiety "nonce"</p>

<p>I hope I answered your question</p>

CC BY-SA 4.0
2019-08-25T14:53:26.107Z
2019-08-25T14:53:26.107Z
vincenzopalazzo
<p>When bitcoin miners mine, they have to solve a difficult and extremely repetitive math problem using the SHA256 algorithm. The miners are trying (basically playing lottery and almost always working in large groups) to get a hash with (currently) at least ~18.81 zeroes. (I put a decimal/float number because the value is inconsistent.) But, I want to put the hash into a hash function and get that super hard-to-compute number for a story I have where a superhero calculates this number. How do I get this string (nonce) that calculates to this zeroed hash and where do I find this on a block explorer, such as blockchain.com, or on bitcoin-cli?</p>

CC BY-SA 4.0
2019-08-25T13:39:48.783Z
Sorry, I'm not secure to undestend the your question, you want have a method for calculate the nonce and you want find the nonce on the explorer, right?
vincenzopalazzo
CC BY-SA 4.0
2019-08-25T13:45:16.670Z
Yeah. That’s what I wanted to do. The nonce has already been computed.
Number File
CC BY-SA 4.0
2019-08-25T15:15:20.397Z
Bitcoin PoW uses _double_ SHA256, sometimes written SHA256d. See https://en.bitcoin.it/wiki/Block_hashing_algorithm for the format of the block header an example. Note this data is binary (aka bits) and 'string' is usually used in computing for characters, so if you are using a program or API designed to hash 'strings' it may not work for bitcoin, although some languages like C++ and python2 do support arbitrary binary strings.
dave_thompson_085
CC BY-SA 4.0
2019-08-25T16:24:12.103Z
That’s true, I did some research and found that you can get the info as the block heading/header
Number File
<sha256>
Where is the string that generates the hash with 18-20 zeroes?
Number File
# Where is the string that generates the hash with 18-20 zeroes?

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

When bitcoin miners mine, they have to solve a difficult and extremely repetitive math problem using the SHA256 algorithm. The miners are trying (basically playing lottery and almost always working in large groups) to get a hash with (currently) at least ~18.81 zeroes. (I put a decimal/float username_0 because the value is inconsistent.) But, I want to put the hash into a hash function and get that super hard-to-compute username_0 for a story I have where a superhero calculates this username_0. How do I get this string (nonce) that calculates to this zeroed hash and where do I find this on a block explorer, such as blockchain.com, or on bitcoin-cli?

**Tags:** sha256

> **Comments:**
> **username_1**: Sorry, I'm not secure to undestend the your question, you want have a method for calculate the nonce and you want find the nonce on the explorer, right?  
> **username_0**: Yeah. That’s what I wanted to do. The nonce has already been computed.  
> **username_2**: Bitcoin PoW uses _double_ SHA256, sometimes written SHA256d. See https://en.bitcoin.it/wiki/Block_hashing_algorithm for the format of the block header an example. Note this data is binary (aka bits) and 'string' is usually used in computing for characters, so if you are using a program or API designed to hash 'strings' it may not work for bitcoin, although some languages like C++ and python2 do support arbitrary binary strings.  
> **username_0**: That’s true, I did some research and found that you can get the info as the block heading/header  

---

## 2 answers

### Answer by username_3 on 2022-09-09. Score: 1

To calculate the PoW hash, all the data of the header of the block is concatenated. The nonce is also concatenated within that data.
username_3, that concatenated data is put through the `SHA256` algorithm and the result is compared to the current target. The resulting hash needs to be smaller than the target to be valid.

So, it's not about how many zeros it has, but if it's smaller than the target.
Seeing it in terms of zeros could help to understand it, but that is miss leading. There could be 1 hash that has exactly the same username_0 of zeros as the target and still not be valid, because it may not be smaller than the target.

For example, let's assume that the target is:

`00000000000000000004f34860a8c59d52c4472ec3798c16f394a699f5e6d8b6`
And our `SHA256` hash is:

`00000000000000000005f34860a8c59d52c4472ec3798c16f394a699f5e6d8b6`
It would not be a valid PoW hash because it's not smaller than the target. They both have the same amount of zeros, but our hash is greater than the target.

Both together:
`00000000000000000004f34860a8c59d52c4472ec3798c16f394a699f5e6d8b6 00000000000000000005f34860a8c59d52c4472ec3798c16f394a699f5e6d8b6`
If we keep changing a bit the data, by increasing the nonce by 1 and username_3 concatenating it again with the data of the block header, and pass it through the `SHA256` alright again and again, eventually we will get a hash that is smaller than the target.

For example:

Target:

`00000000000000000004f34860a8c59d52c4472ec3798c16f394a699f5e6d8b6`

Our hash:

`00000000000000000003f34860a8c59d52c4472ec3798c16f394a699f5e6d8b6`
As you can see, our hash now is smaller than the target and is a valid PoW hash for our block.

The hash of the block header data could even be way smaller than the target, and it's valid. It can have more zeros, but finding a hash like this is less probable in average:

`00000000000000000000000000a8c59d52c4472ec3798c16f394a699f5e6d8b6`

To visualize it better, you can go to this site that has a simple blockchain implementation to visualize how a blockchain works: <https://andersbrownworth.com/blockchain/blockchain>

I've concatenated the data of the block `5` and passed it through a `SHA256` function:

Concatenated data:

`529742data0000ae8bbc96cf89c68be6e10a865cc47c6c48a9ebec3c6cad729646cefaef83`

[SHA256](https://andersbrownworth.com/blockchain/hash) hash of that data:

`0000d73c6ecf38aa53a8fbace738ff59540fd5e519e6d9aa496f61ce70110a09`
If we compare the `hash` of block `5` with this one, it's the same.


---

### Answer by username_1 on 2019-08-25. Score: 0

If I undestend the your question,

This is an example of the proof-of-work [algorithm](https://github.com/bitcoinbook/bitcoinbook/blob/develop/code/proof-of-work-example.py).

The nonce is a component of the block, the strucure of the block contain the value, inside the [blockchain.com](https://www.blockchain.com/it/btc/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f) you can find the value inside the propiety "nonce"

I hope I answered your question


---

