Open In App

Why Do We Need Both Nonce and Mixhash Values in a Block?

Last Updated : 16 Sep, 2022
Like Article

In the field of blockchain, blocks serve as the building blocks of its structure. Blocks convey the transactions of all the previous blocks in the blockchain. A block contains the hash of its parent block, thus it is connected to the rest of the blockchain. Any tampering with the data of a particular block will invalidate the data of all subsequent blocks as the hash of the resulting blocks will be affected, and all nodes would notice this. This process is essential to a blockchain as it prevents fraud and ensures security. In this article, these two important aspects of a block, the mixhash, and nonce, and the role that these play in making a blockchain secure will be discussed.

What is MixHash?

A mixhash is an encrypted form of data in the block. Whatever data is present in the block is encrypted with a hashing algorithm (ex. sha256) to create its mixhash. The properties of a hash are:

  1. Unique: The hash generated by a particular input is always unique. You cannot have two different hashes that originated from the same string.
  2. Irreversible: A hash cannot be un-hashed to reveal the original string. 
  3. Fixed length: A particular hashing algorithm will always generate a hash of a pre-defined length. The length of the generated hash is independent of the length of the input string.

One can think of a mixhash as a fingerprint of the data in a block. A mixhash is present in every block of the blockchain and it is computed with the data of the block which includes the index, content, hash of the previous block, and the nonce.

What is Nonce?

Nonce stands for the Number used only once. It is a random whole number that is decided depending on the difficulty of the hash algorithm. 

  • It is a value that is included in the block content, which is then hashed in order for the mixhash to conform to limitations set by the miners of the blockchain. 
  • The nonce is an integral part of the blockchain since it represents the Proof of Work
  • In other words, miners parse through millions of nonce values to ultimately find the golden nonce that will suit the blockchain. 
  • This is how they earn their block reward for mining.

Essentially what this means is that the nonce value is used to adjust the overall mixhash of the block to a standard that is set by the blockchain. In order to do this, i.e. in order to find the golden nonce, miners must use their computational power to go through millions of candidate nonces. This is what is meant by the term mining.

Structure of the Block

The block is an integral part of the blockchain. Some of the fields that are in the block are:

Structure of Block


  1. Index.
  2. Nonce.
  3. Content.
  4. Previous Node’s Hash.
  5. Current Node’s Hash.

The content field usually consists of transaction details. This is in line with blockchain being used as an immutable distributed ledger.

The blockchain is made by appending new blocks at the end of existing blocks. Each new block contains its own hash as well as the hash of the previous block.

Structure of Blockchain


As can be seen in the diagram, each subsequent block contains the hash of the previous block. While computing the hash of the current block, the previous block’s hash is also used. The nonce value of each block is unique. In our example, the nonce value is adjusted to ensure that the first four digits of the hash are always zero. The nonces that are able to generate this kind of hashes are valid nonces and a block that has this kind of hash is a minted block. However, the criteria for a valid hash may be different than this. 

Why Do We Need Both Nonce and Mixhash Values in a Block?

Let us assume that we have a blockchain of four blocks and all the blocks are valid. This would mean that each block contains a valid hash and the hash of the previous block.

Blockchain Structure


1. Let us change some data in the last block. Suppose, the index of the last block is changed from #4 to #5 (in reality, some data field i.e. a transaction has been tampered with). 

2. This will mean that the hash of the current block will change and the nonce that was being used will no longer be valid. In this case, the first 4 digits of the hash will no longer be 0.

Data in the block is tampered


3. It can be seen that as a result of the nonce being incorrect, the mixhash can be made invalid hence making the block invalid. 

4. In this case, however, only data from the last block has been tampered with. 

What happens if the data of the second block has also been tampered with?


1. Tampering with the second block will cause its hash to change, this will set a chain reaction where the hash of all subsequent blocks will be changed.

2. Hence all the subsequent blocks will be invalidated. In this manner, a blockchain resists mutation. 

One might ask, well if we can mine each block independently and validate their hashes, have we not resolved this problem and hacked into the blockchain? 

This is where the distributed nature of the blockchain comes into play. There exist various peers of the same blockchain. These are identical in nature. This means that even if one re-mines the block of a mutated blockchain, it could always be verified that this is a mutated blockchain by comparing it with one of its peers. Hence a democracy comes into play where the authenticity of a peer is judged by comparing it with other peers. This is possible because the nonces are unique and even if a block is re-mined, it will not have the same hash as the original block.


 In combination, these two values nonce and mixhash help to determine the authenticity and immutability of the blockchain. 

  1. Mixhash is a hash of the index, nonce, content, and previous node’s hash. This is unique, non-reversible, and of fixed length. It serves to encrypt the data of a particular block.
  2. Nonce stands for the Number used only once. It is a unique whole number that shall be used only once in the blockchain. The purpose of this number is to make the hash of the current cell conform to a certain standard as is set by the blockchain. The mining of the nonce represents the Proof of Work that miners display in order to get the block reward.

Used in tandem, these values are instrumental in providing the resistance to the mutation that the concept of blockchain is known for. 

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads