<p>The problem is that you are hashing the header as a string, not as the bytes that the hex represents. If you hash it as bytes, you will get the expected hash. Both the header, and the first hash, must be treated as bytes, not a hex string.</p>

CC BY-SA 4.0
2022-02-10T17:12:48.347Z
2022-02-10T17:12:48.347Z
Ava Chow
<p>From my knowledge a header hash will be calculated like this:</p>
<ol>
<li>serialize all header fields, including &quot;the nonce&quot;</li>
<li>hash the serialized header once</li>
<li>hash the hashed serialized header again</li>
<li>check if the result is below the target</li>
<li>if no: choose a different nonce and start over</li>
</ol>
<p>I'm referring to this site that allows you to enter some header data and calculate the header hash:</p>
<blockquote>
<p><a href="https://learnmeabitcoin.com/tools/hashblockheader/?version=536870912&amp;hashPrevBlock=00000000000000000001eaef94e697cae4216042819d6e2c6ec1c959f8112b38&amp;hashMerkleRoot=eb9439ab4f13d3bd448b792d30a97e4632e567d5e6e40c2d5c9a72f27edbddbd&amp;time=1644443882&amp;bits=170a8bb4&amp;nonce=3156027&amp;submit=true" rel="nofollow noreferrer">https://learnmeabitcoin.com/tools/hashblockheader/?version=536870912&amp;hashPrevBlock=00000000000000000001eaef94e697cae4216042819d6e2c6ec1c959f8112b38&amp;hashMerkleRoot=eb9439ab4f13d3bd448b792d30a97e4632e567d5e6e40c2d5c9a72f27edbddbd&amp;time=1644443882&amp;bits=170a8bb4&amp;nonce=3156027&amp;submit=true</a></p>
</blockquote>
<p>The site already calculates the serialized header that I have to use for the hashing process:</p>
<pre><code>00000020382b11f859c9c16e2c6e9d81426021e4ca97e694efea01000000000000000000bddddb7ef2729a5c2d0ce4e6d567e532467ea9302d798b44bdd3134fab3994ebea380462b48b0a173b283000 
</code></pre>
<p>So running this serialized header through SHA256 for two times gives me this hash after the first iteration:</p>
<pre><code>969d0e7028705a4ca408430f5d2bcb05acbcd6c3350f43a838714a2ba5db94f0
</code></pre>
<p>And hashing this again would return:</p>
<pre><code>9fe2e96559673ba8e038452cc161e2da87636567d95ef7ae6be800770a5cbf9f
</code></pre>
<p>But this is not the actual hash for this block header. Apparently, because starting with a 9 seems not be very difficult. That is the correct header:</p>
<pre><code>000000000000000000055730c92292ebd5c5851e7d24ab3ba2efc1cea0b5fe81
</code></pre>
<p>So I'm wondering, what additional step I'm missing here?</p>
<p>Thank you</p>

<hash><block-header>
What actual steps are required to calculate a block's header hash?
n.r.
# What actual steps are required to calculate a block's header hash?

(Asked by: username_0 on 2022-02-10)

From my knowledge a header hash will be calculated like this:

serialize all header fields, including "the nonce"
hash the serialized header once
hash the hashed serialized header again
check if the result is below the target
if no: choose a different nonce and start over

I'm referring to this site that allows you to enter some header data and calculate the header hash:

https://learnmeabitcoin.com/tools/hashblockheader/?version=536870912&hashPrevBlock=00000000000000000001eaef94e697cae4216042819d6e2c6ec1c959f8112b38&hashMerkleRoot=eb9439ab4f13d3bd448b792d30a97e4632e567d5e6e40c2d5c9a72f27edbddbd&time=1644443882&bits=170a8bb4&nonce=3156027&submit=true

The site already calculates the serialized header that I have to use for the hashing process:
00000020382b11f859c9c16e2c6e9d81426021e4ca97e694efea01000000000000000000bddddb7ef2729a5c2d0ce4e6d567e532467ea9302d798b44bdd3134fab3994ebea380462b48b0a173b283000 

So running this serialized header through SHA256 for two times gives me this hash after the first iteration:
969d0e7028705a4ca408430f5d2bcb05acbcd6c3350f43a838714a2ba5db94f0

And hashing this again would return:
9fe2e96559673ba8e038452cc161e2da87636567d95ef7ae6be800770a5cbf9f

But this is not the actual hash for this block header. Apparently, because starting with a 9 seems not be very difficult. That is the correct header:
000000000000000000055730c92292ebd5c5851e7d24ab3ba2efc1cea0b5fe81

So I'm wondering, what additional step I'm missing here?
Thank you

**Tags:** hash, block-header


---

## 1 answers

### Answer by username_1 on 2022-02-10. Score: 5 | Accepted answer

The problem is that you are hashing the header as a string, not as the bytes that the hex represents. If you hash it as bytes, you will get the expected hash. Both the header, and the first hash, must be treated as bytes, not a hex string.


---

