Nonce: What It Means and How It's Used in Blockchain

What Is the Nonce?

Nonce, a portmanteau of "number used only once," is a random number that bitcoin miners try to find in order to mine a new block in the Bitcoin blockchain and receive a block reward for their efforts. The number is a critical element to the Bitcoin blockchain running smoothly.

The practice of mining blocks helps record and verify transactions on the Bitcoin ledger and mint new bitcoins to grow the circulating supply. Bitcoin transactions are verified in batches rather than individually, giving rise to the block structure. The block height is the number of all blocks up to a given block.

The nonce ensures each block has a unique hash, a cryptographic fingerprint that serves as an identifier for the block and underpins the expansion of the blockchain. By adjusting the nonce, miners can modify hash values that in turn potentially solve mathematical problems for mining new blocks.

Key Takeaways

  • Bitcoin miners engage in a relentless trial-and-error process to find the correct nonce for the production of a new block, repeatedly hashing the block header with different nonce values until a hash appears that satisfies a mathematical puzzle and the network's requirements.
  • Each nonce is used only once for a particular block, ensuring each block has a unique identifier to prevent transaction malleability.
  • Finding valid nonces and hashing consumes significant computational power, contributing to the network's security and resistance to malicious attacks and double-spending.

Understanding the Nonce

A Bitcoin nonce is a 32-bit (or 4-byte) random number that miners attempt to figure out through computational brute force so they can generate a valid and unique hash to produce a new block in the Bitcoin blockchain. The nonce is one of the key elements in the Proof-of-Work (PoW) algorithm and consensus mechanism that validates and secures the Bitcoin network.

In Bitcoin mining, miners compete to solve a complex mathematical puzzle by repeatedly hashing a block header, a grouping of data in each block containing the nonce and other essential information about the previous block, the timestamp, transactions included in the new block, and the Merkle root, the hash of all hashes of all transactions in the block.

Hashing refers to the process of applying a cryptographic hash function to the block header. The cryptographic hash function is a mathematical operation that takes the block header data and transforms it into a unique hash value, a fixed-length hexadecimal and encrypted string of characters. The block header data is the input and the hash value is the output of the function.

This hash value serves as a cryptographic fingerprint of the block, ensuring that the block's contents remain unaltered. Miners constantly race to generate hash values that meet the Bitcoin network's mining difficulty requirements, which are programmed to increase at scheduled intervals so the blockchain remains tamper-proof and reliable.

The nonce is the only variable in the block header that miners can modify. By changing the nonce, miners can change the hash of the block and calculate different possible solutions to the mathematical puzzle needed to spin up a new block. The first miner to find a valid hash under the network's mining difficulty requirements is awarded the block reward and the right to add the new block to the blockchain.

To find a valid nonce, miners must repeatedly increment the nonce value and recalculate the hash until the resulting hash value meets the network's target difficulty. In numerical analysis and computational algorithms, incremental computation refers to a method for approximating functions or solving equations using small, consistent steps. 

If the hash value exceeds the network's difficulty-adjusted target hash, the miner tries again with another randomly generated nonce. If the resulting hash value is equal to or less than the target hash, the miner has created a solution and receives the block as a reward. The block is closed, and a new block opens that includes the previous block's hash.

The target difficulty is a measure of how difficult it is to find a valid nonce. It is adjusted periodically to maintain a consistent block generation rate.

The Nonce in Bitcoin Mining

Here is a step-by-step explanation of how the nonce is used in Bitcoin mining:

  1. Miners gather transaction data and create a new block header.
  2. They initialize the nonce to a random value and start hashing the block header along with the nonce.
  3. They repeatedly increment the nonce and rehash the block header until they find a hash that meets the network's difficulty requirements.
  4. The first miner to find a valid hash broadcasts the block to the network.
  5. Other miners verify the block's validity and add it to their local copies of the blockchain.

Significance of the Nonce

The nonce maintains the integrity and security of the Bitcoin blockchain. It prevents attackers from tampering with or forging blocks, as any alteration to the block data, including the nonce, would result in a different hash value, rendering the block invalid.

It is highly unlikely that a miner will guess the nonce on the first try. Miners in a PoW system generally have to test a large number of nonce options before getting it right.

The greater the difficulty—a measure of how hard it is to create a hash less than the target—the longer it is likely to take to generate a solution. And because the difficulty increases, the process of finding a valid nonce is more computationally intensive and requires significant electricity and computing power over time, introducing material constraints.

This is intentional, as it helps to secure the Bitcoin network by making it computationally infeasible to manipulate the blockchain with coordinated attacks and transaction errors such as 51% attacks and double-spending.

By requiring miners to find a valid nonce and making it difficult to predict or manipulate the nonce, the PoW algorithm ensures only blocks with a valid history can be added to the blockchain and malicious actors are prevented from changing or duplicating transactions, guaranteeing the immutability of the blockchain.

The miner who successfully finds the valid nonce for a new block receives a block reward, which consists of newly minted Bitcoin and transaction fees. This reward incentivizes miners to participate in the network's security and contribute to the validation of transactions.

Transactions on a blockchain are aggregated into blocks from a memory pool based on the age of the transaction or the amount of fees paid. A memory pool, also known as a mempool, is a temporary data storage area that holds unconfirmed transactions before they are added to the blockchain. The mempool acts as a waiting room where transactions are queued up and prioritized based on their transaction fees.

Nonce and Difficulty

Block difficulty is kept at the same level across the entire Bitcoin network, meaning all miners have the same chance of figuring out the correct hash. The Bitcoin network is set up to process a specific number of blocks over a period of time and to occasionally adjust the difficulty for miners to validate the blocks.

The difficulty of finding a valid nonce is dynamically adjusted based on the overall hash rate of the network. If the network's hash rate increases, the difficulty increases, making it harder to find a valid nonce. This mechanism ensures that blocks are generated at a consistent rate, regardless of the number of miners participating.

If the number of blocks processed doesn't meet the difficulty target, the difficulty is reduced, determining how much time the process took over the limit. If the network meets it too quickly, the difficulty is increased. When the difficulty is higher, more nonces are generated because more attempts are required to solve the hash.

Bitcoin block 813,958, mined on Oct. 26, 2023 by AntPool, a cluster of miners known as a mining pool, had a nonce of 105,983,939. That day, AntPool had a bitcoin hashrate of 123 exa-hashes per second (or 123 quintillion hashes) and the entire Bitcoin network hashed at 428.22 exa-hashes per second (or 428.22 quintillion hashes). That means the AntPool mining pool alone generated quadrillions of numbers to find the correct nonce and winning hash, out of an exponentially many more number of trials for all mining pools combined.

Mining pools, rather than individuals, open most blocks because the mining difficulty is so high that a single miner is unlikely to have enough hashing power to keep up. This power is measured in the number of hashes per second. A home computer might have a hash rate of 100 mega-hashes per second (or 100 million hashes). In contrast, a mining farm full of ASIC miners, the most advanced mining technology on the market, might hash around 30 exa-hashes per second (or 30 quintillion hashes).

What Is a Blockchain?

A blockchain is a distributed ledger or database shared among nodes of a digital network, which can include computers, data centers, and mobile devices. As a database, a blockchain stores information electronically in a digital format. As a ledger, a blockchain maintains a secure record of transactions, as in cryptocurrency systems such as Bitcoin. A blockchain's innovation comes from the fidelity of a data record without the need for a trusted third-party.

What Is the Difference Between a Nonce and a Hash?

A nonce is a temporary value used in the process of generating a hash, while a hash is a permanent identifier for a block. A nonce is 32 bits long, while a hash is 256 bits long.  A nonce is used only once for a particular block, while a hash is unique to the block header and cannot be reversed to obtain the original data. Nonces are used to make it difficult to generate valid hashes, which helps to secure the Bitcoin blockchain.

How Much Do Miners Make From Block Rewards?

The block reward for miners who successfully find a valid nonce for a block in Bitcoin consists of two components: newly minted Bitcoin and transaction fees. The amount of newly minted Bitcoin in the block reward has been roughly 6.3 BTC since June 2021 and halves every 210,000 blocks, or approximately every four years, with the next due in April 2024. This halving mechanism is called the "Bitcoin halving" and is designed to gradually reduce the overall supply of Bitcoin and maintain its value. The amount of transaction fees in the block reward varies depending on the overall volume and fee rates of transactions. In recent years, transaction fees have become a significant portion of miners' income, often exceeding the value of the newly minted Bitcoin in the block reward. This is due to the increasing popularity and usage of Bitcoin, leading to a higher volume of transactions and higher transaction fees.

The Bottom Line

In Bitcoin mining, miners are constantly trying to find a nonce that will produce a hash that meets the network's difficulty requirements for spawning new blocks that validate recent transactions and issue fresh bitcoin. A hash is a unique identifier for each block in the Bitcoin blockchain and a fixed-length string of characters that is generated by applying a cryptographic hash function to a piece of data in a process known as hashing. The data that is hashed is the block header, a structured element containing information about the block. Once a valid nonce is found, it is discarded and never used again.

Article Sources
Investopedia requires writers to use primary sources to support their work. These include white papers, government data, original reporting, and interviews with industry experts. We also reference original research from other reputable publishers where appropriate. You can learn more about the standards we follow in producing accurate, unbiased content in our editorial policy.
  1. Blockchain.com. "Bitcoin Block 813,958."

  2. AntPool. "AntPool Mining Coin."

  3. U.S. Department of Energy. "DOE Explains...Exascale Computing."

  4. Bitcoin Visuals. "Block Reward Per Block Chart."

Take the Next Step to Invest
×
The offers that appear in this table are from partnerships from which Investopedia receives compensation. This compensation may impact how and where listings appear. Investopedia does not include all offers available in the marketplace.