What is a Blockchain Nonce?

Jake Howering
3 min readSep 28, 2018

When using the Proof of Work (PW) consensus algorithm, blockchain nodes will race to solve a complex problem and submit to peer nodes to verify the results. The PW problem is supposed to be difficult to solve but easy for others to verify. That riddle is solved by the use of a “nonce.”

In cryptography, a nonce is an arbitrary value that can be only used once. Ok, cool. But, what does this have to do with blockchain ?

In blockchain, the block contents are input to a SHA-256 crypto engine to create a unique hash value. Any change in the block contents will create a completely different hash value — additionally, the exact same block contents will create the exact same hash value each and every time.

Blockchain miners race to be the nodes that solve the complex problem so that they get to add the block to the chain because they will get a reward, which is currently 12.5 bitcoin. The nonce is the random variable added as input to the SHA-256 crypto engine to create the unique hash value.

The miners don’t know the nonce value, but do have the block contents, so they then run through their computation to solve the problem.

For instance, let’s say the requirement is to find a hash value that begins with 4 zeroes. So, they will take the block contents, pick a nonce, and input them into the SHA-256 crypto engine. If the hash value is the “correct” hash value, awesome — they have solved it!. Otherwise, they pick a new nonce, input the same block contents and run it through the SHA-256 cypto engine again.

Let’s say the to solve the complex problem the hash value result from the SHA-256 cytpto-engine must start with 4 leading zeroes. We know the block contents and we repeatedly pick nonce values to input into the SHA-256 cypto engine until we solve the problem (get 4 leading zeroes in the hash value). As an example, the code below is incrementing the nonce by 1 until it finds a hash string that starts with 4 0’s. When the 4 0’s are found via the hash, the nonce value is found and the problem solved. This loop iteration may take thousands or hundreds of thousands of iterations to find the correct nonce.

Once the miner has found the nonce that solves the problem, the miner provides it to peer nodes. Since the peer nodes have been given the nonce, then verifying the problem is easy. They simply run the block contents and the nonce through the SHA-256 crypto-engine and verify that the hash result correctly solves the problem of 4 leading 0’s.

There are many more detailed discussions on Proof of Work and the nonce that can be found here or here.

--

--