<p>You are very close. As Mesh already laid out, miners are hashing the following data:</p>

<ul>
<li>nVersion (e.g. 02000000)</li>
<li>HashPrevBlock (this hash gets reversed, and then every two bytes are flipped)</li>
<li>HashMerkleRoot (this hash gets reversed, and then every two bytes are flipped)</li>
<li>nTime (must be converted to hex e.g 358b0553)</li>
<li>nBits (target difficulty e.g 535f0119)</li>
<li>nNonce (the random data)</li>
</ul>

<p>This info can be found in the <a href="https://bitcoin.org/en/developer-reference" rel="nofollow noreferrer">Bitcoin Developer Reference</a>, or the <a href="https://lopp.net/pdf/Bitcoin_Developer_Reference.pdf" rel="nofollow noreferrer">PDF</a>.</p>

<p>Now, to your third question, yes you can! I actually just built a little program in C# to do this yesterday! There is a little trickery to it, because you cant just plug the data straight into a hashing calculator and verify it. First, you append all of the fields together into a single string (after the hash reversing and flipping is done for the previous block hash, and merkle root). Then, you convert that string to binary data. At this point, you run the double SHA256 hash to verify that you get a valid hash of the block.</p>

<p>A helpful resource for you to check out it is <a href="http://www.righto.com/2014/09/mining-bitcoin-with-pencil-and-paper.html" rel="nofollow noreferrer">Mining Bitcoin with pencil and paper</a> as well as <a href="https://en.bitcoin.it/wiki/Block_hashing_algorithm" rel="nofollow noreferrer">Bitcoin Wiki</a>. Both resources have code samples that show this process in action.</p>

CC BY-SA 3.0
2018-01-05T03:19:53.223Z
2018-01-05T03:19:53.223Z
Tanner.R
<p>From the <a href="https://bitcoin.org/en/developer-reference#block-headers" rel="nofollow noreferrer">Bitcoin.org Developer Documentation</a>, a block header consists of a:</p>

<ul>
<li>Version</li>
<li>Previous block header hash</li>
<li>merkle root</li>
<li>timestamp</li>
<li>nBits field</li>
<li>nonce</li>
</ul>

<p>In that order. So as you say, the only component missing from your list is the version and the nBits field. The version is self explanatory, but the nBits field is not. What the nBits field does is encode the current target for the difficulty algorithm:</p>

<blockquote>
  <p>to have at least 18 leading zeros.</p>
</blockquote>

<p>Not always 18 zeroes. The number of leading zeros changes based on how quickly blocks have been found recently, in order to keep the block time at roughly 10 minutes average despite varying hashpower on the network. As more miners join, the hashrate increases, so the difficulty does too (i.e. more zeroes are required). Another way to think about the 0's, is that the output of the SHA256, as a number, must be less than some target number. That target is encoded in the nBits field. And yes, anyone can verify that the block header hashes to a number below the target, that is how other clients verify blocks are valid, because SHA256 always produces the same output from the same input - it is deterministic, a property of all useful hash functions.</p>

CC BY-SA 3.0
2018-01-05T02:14:06.950Z
2018-01-05T02:14:06.950Z
meshcollider
<p>Can someone please explain in detail the components of the final hash that determines the winner of the block?</p>

<p>My understanding is that the miners are taking </p>

<ol>
<li>The Merkle Root, </li>
<li>The time stamp,  </li>
<li>The prior block's hash,  </li>
<li>Some other components??, along with  </li>
<li>A nonce that the miner's have to guess in order for the hash of all these components, using Sha256, to have at least 18 leading zeros.</li>
</ol>

<p>My questions are:</p>

<ol>
<li><p>Am I right in my understanding so far?</p></li>
<li><p>Can someone explain what the other components are and what order they are input into the hash function?</p></li>
<li><p>Using the data available on blockchain.info about each block, can I recreate the winning hash by inputing the same data into a Sha256 calculator?</p></li>
</ol>

<p>Thanks.</p>

<mining-theory><hash><sha256><merkle-tree><nonce>
Understanding the Hash Function
Adam Smith
# Understanding the Hash Function

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

Can someone please explain in detail the components of the final hash that determines the winner of the block?

My understanding is that the miners are taking

1. The Merkle Root,
2. The time stamp,
3. The prior block's hash,
4. Some other components??, along with
5. A nonce that the miner's have to guess in order for the hash of all these components, using Sha256, to have at least 18 leading zeros.

My questions are:

1. Am I right in my understanding so far?
2. Can someone explain what the other components are and what order they are input into the hash function?
3. Using the data available on blockchain.info about each block, can I recreate the winning hash by inputing the same data into a Sha256 calculator?

Thanks.

**Tags:** mining-theory, hash, sha256, merkle-tree, nonce


---

## 2 answers

### Answer by username_1 on 2018-01-05. Score: 2 | Accepted answer

You are very close. As Mesh already laid out, miners are hashing the following data:

* nVersion (e.g. 02000000)
* HashPrevBlock (this hash gets reversed, and then every two bytes are flipped)
* HashMerkleRoot (this hash gets reversed, and then every two bytes are flipped)
* nTime (must be converted to hex e.g 358b0553)
* nBits (target difficulty e.g 535f0119)
* nNonce (the random data)

This info can be found in the [Bitcoin Developer Reference](https://bitcoin.org/en/developer-reference), or the [PDF](https://lopp.net/pdf/Bitcoin_Developer_Reference.pdf).

Now, to your third question, yes you can! I actually just built a little program in C# to do this yesterday! There is a little trickery to it, because you cant just plug the data straight into a hashing calculator and verify it. First, you append all of the fields together into a single string (after the hash reversing and flipping is done for the previous block hash, and merkle root). Then, you convert that string to binary data. At this point, you run the double SHA256 hash to verify that you get a valid hash of the block.

A helpful resource for you to check out it is [Mining Bitcoin with pencil and paper](http://www.righto.com/2014/09/mining-bitcoin-with-pencil-and-paper.html) as well as [Bitcoin Wiki](https://en.bitcoin.it/wiki/Block_hashing_algorithm). Both resources have code samples that show this process in action.


---

### Answer by username_2 on 2018-01-05. Score: 3

From the [Bitcoin.org Developer Documentation](https://bitcoin.org/en/developer-reference#block-headers), a block header consists of a:

* Version
* Previous block header hash
* merkle root
* timestamp
* nBits field
* nonce

In that order. So as you say, the only component missing from your list is the version and the nBits field. The version is self explanatory, but the nBits field is not. What the nBits field does is encode the current target for the difficulty algorithm:

> to have at least 18 leading zeros.

Not always 18 zeroes. The number of leading zeros changes based on how quickly blocks have been found recently, in order to keep the block time at roughly 10 minutes average despite varying hashpower on the network. As more miners join, the hashrate increases, so the difficulty does too (i.e. more zeroes are required). Another way to think about the 0's, is that the output of the SHA256, as a number, must be less than some target number. That target is encoded in the nBits field. And yes, anyone can verify that the block header hashes to a number below the target, that is how other clients verify blocks are valid, because SHA256 always produces the same output from the same input - it is deterministic, a property of all useful hash functions.


---

