Independent research · No paid placements · Not financial advice

Crypto Infrastructure RESEARCH · NOT SOLD
Guides

What Is a Nonce in Blockchain?

What is a nonce in blockchain? In Bitcoin it is the 4-byte header field miners change to hit the difficulty target; on Ethereum it is the account counter that orders transactions and blocks replays.

What Is a Nonce in Blockchain? – featured image, cryptoinfrastructure.io
TL;DR summary

A nonce (“number used once”) means two different things in blockchain. In Bitcoin mining it is a 4-byte field in the block header that miners change, over and over, until the block’s hash falls at or below the network’s difficulty target. On Ethereum and other account-based chains it is a counter attached to every account: your first transaction uses nonce 0, the next uses 1 and so on. That keeps your transactions in order and stops a signed transaction from being replayed. A third, separate meaning is the secret random value inside a digital signature, where reusing it can expose a private key.

You usually meet the word “nonce” in one of two places: a mining explainer that says miners are “guessing a number”, or a wallet screen showing a stuck transaction with a “custom nonce” field. They are not the same thing. Most explainers only cover the first. This guide explains what a nonce in blockchain is in both senses, works through a simple hashing example, shows how account nonces cause (and fix) stuck transactions plus covers the signature nonce that has cost people real funds when it went wrong.

What is a nonce in blockchain?

A nonce is short for “number used once”. In blockchain it has two main meanings:

  • Block nonce (proof of work): a value in a block header that miners vary to search for a block hash that meets the difficulty target. Bitcoin works this way.
  • Account nonce (transaction counter): a number tied to each account that counts its transactions, so every transaction has a unique, ordered slot. Ethereum works this way.

Both make something unique, but they solve different problems. The block nonce is how miners prove they did work. The account nonce is how the network keeps your transactions in sequence and refuses to run the same one twice.

Block nonce (Bitcoin mining)Account nonce (Ethereum)
Where it livesThe 80-byte block headerThe account’s state, and a field in every transaction
Size4 bytes (32 bits)An integer counter (EIP-7702 caps authorization nonces below 264, that is 2 to the power of 64)
Who sets itMining hardware, trying value after valueYour wallet, using the next number in sequence
What it doesChanges the header hash so miners can search for a valid blockOrders transactions and gives replay protection
Random?No. Miners iterate through valuesNo. It increases by one per transaction

Sources: Bitcoin developer reference (block headers) and ethereum.org accounts documentation.

One correction worth making early: some summaries list Solana alongside Ethereum as a chain that uses a sequential account nonce. Solana’s own developer guide describes a different design. Transactions carry a recent blockhash and are matched against the last 150 blocks, which both rejects duplicates and makes transactions expire (Solana: transaction confirmation and expiration). For transactions that need to be signed now and sent later, Solana offers optional “durable nonces”: a 32-byte value stored in a nonce account that is advanced each time it is used (Solana: durable nonces guide). There is no per-account counter that transactions must follow in order.

The block nonce: how it works in Bitcoin mining

Every Bitcoin block starts with an 80-byte header. According to the Bitcoin developer reference, it holds six fields:

FieldBytesWhat it is
Version4Which set of block validation rules to follow
Previous block header hash32Links this block to the one before it
Merkle root32A single hash committing to every transaction in the block
Time4Unix timestamp; must be greater than the median time of the previous 11 blocks
nBits4An encoded form of the target threshold
Nonce4The value miners change to vary the header hash
Steps for the nonce in blockchain mining: build the header, set the nonce, double SHA-256, check the target, extranonce
Finding a valid nonce takes many attempts, but verifying one takes a single hash.

The header is hashed with SHA-256 twice. The rule for a valid block is simple: the header hash, read as a 256-bit number, must be equal to or below the target encoded in nBits. “Leading zeros”, which most explainers mention, is a loose way of describing the same thing, since a very small number written in hex starts with zeros.

Because nobody can predict what a hash will be, the only way to find a valid one is to keep changing the input and hashing again. The nonce is the field designed for that. The Bitcoin developer guide on mining describes it plainly: the mining hardware “iterates through every possible value for the block header nonce and generates the corresponding hash.” So the block nonce is not a random number someone picks. It is a counter that hardware runs through as fast as it can.

A worked hashing example (hypothetical)

Here is a toy version you can reproduce with any SHA-256 tool. It is not a real Bitcoin header and the target is set absurdly easy, but the logic is identical.

  1. Take some fixed block data: toy block: prev=abc, txs=xyz.
  2. Append a nonce and hash it twice with SHA-256 (double SHA-256, as Bitcoin does).
  3. The toy rule: the hash must start with 000 in hex, which means it is below a target of 0x001000…0. On average that takes about 4,096 tries.
NonceDouble SHA-256 result (first 16 hex characters)Meets target?
09b70008c285d98c9…No
1b0aaefbfc2f5c16a…No
232310946003af279…No
……No
1,3190003cc46d8ca6fa3…Yes

Calculated by this site, input string toy block: prev=abc, txs=xyz|nonce=N. Illustration only.

Notice three things. Changing the nonce by one changes the whole hash unpredictably. Finding the answer took 1,320 attempts, but verifying it takes one hash, which is why anyone can verify a block cheaply. There was also nothing special about nonce 1,319: a different block, or a different timestamp, would need a completely different nonce. Real Bitcoin targets are vastly harder than this toy one, so real miners run through billions of attempts.

What happens when the 32-bit nonce runs out: the extranonce

A 4-byte field allows 232 values, which is 4,294,967,296. The Bitcoin developer guide notes that a single 4-byte header nonce is only “good for about 4 gigahashes”, which it treats as a narrow search space for mining hardware. So the nonce alone is not enough.

The fix is to change something else in the header. The Bitcoin mining guide explains that the new header is “created by adding extra nonce data to the coinbase field of the coinbase transaction”. The coinbase transaction is the first transaction in a block, the one that pays the miner. Changing its extra nonce changes its transaction ID, which changes the Merkle root in the header, which gives the hardware a fresh set of 4.3 billion nonces to try. The mining software can also update the time field. Pools that use the Stratum protocol hand miners the pieces to do this themselves: the software updates and re-hashes the coinbase transaction, rebuilds the Merkle root then updates the header.

The nonce does not decide how much the miner earns. The block reward follows its own separate schedule; see how the Bitcoin halving works.

Is there a nonce in proof of stake?

Not in the mining sense. Ethereum switched from proof of work to proof of stake at the Merge on 15 September 2022. ethereum.org states that “mining is no longer the means of producing valid blocks.” Block producers on proof-of-stake chains are chosen by the protocol rather than by a hashing race, so there is no block nonce to grind. The account nonce, covered next, is still central to Ethereum.

The account nonce: Ethereum’s transaction counter

On Ethereum, every account carries a nonce. The ethereum.org accounts documentation (page updated 6 August 2026) defines it as “a counter that indicates the number of transactions sent from an externally-owned account or the number of contracts created by a contract account.”

In practice, for a normal wallet address:

  • Your first transaction uses nonce 0, your second uses 1 and so on.
  • Each transaction you sign includes its nonce. Ethereum’s transaction documentation describes it as “a sequentially incrementing counter which indicates the transaction number from the account.”
  • The network processes your transactions in nonce order. A transaction with nonce 5 cannot be included before nonce 4.

Why the account nonce exists: replay protection

A signed transaction is just data. Without a nonce, anyone who saw your signed payment of 1 ETH to a friend could broadcast it again and again. Each copy would carry a valid signature. The nonce prevents that. As ethereum.org puts it, “only one transaction with a given nonce can be executed for each account, protecting against replay attacks”, meaning cases “where signed transactions are repeatedly broadcast and re-executed.” Once nonce 7 is used, any other transaction carrying nonce 7 from your account is invalid.

Stuck and pending transactions: what the nonce has to do with them

The ordering rule is also why transactions get stuck. If you send a transaction with too low a fee, it can sit pending for a long time. Every later transaction from the same account has a higher nonce, so it queues behind the stuck one, even if you paid more for it.

Comparison of speeding up versus cancelling a stuck Ethereum transaction by reusing the same account nonce with a higher fee
Only one transaction per nonce can confirm, so a replacement is a race, not a guarantee.

Because only one transaction per nonce can ever confirm, you fix this by sending a new transaction with the same nonce and a higher fee. Whichever version a block producer includes, the other becomes invalid. MetaMask’s support guide describes both options:

  • Speed up: resubmits the same transaction with a higher fee. Since it reuses the original nonce, you do not pay for gas twice.
  • Cancel: sends a replacement, typically a 0 ETH transfer to your own address, with the same nonce and a higher fee. It can only be attempted while the original is still pending.

For a manual replacement, MetaMask’s guide says to set the priority fee at least 10% higher and the max fee at least 30% higher than the original. Work from the oldest stuck transaction upwards: you cannot cancel nonce 10 before dealing with nonce 9. A replacement is a race, not a guarantee. If the original confirms first, the replacement fails.

Two other nonce problems come up often, especially for developers sending many transactions from one address:

  • Nonce gap: if you skip a number (send nonce 12 when the account is at 10), nonce 12 waits until 10 and 11 exist. Nothing behind the gap confirms.
  • Nonce collision: two scripts or two wallets sign from the same account at the same time and pick the same nonce. Only one of those transactions can ever confirm. The other is rejected because its nonce is already used. Teams running bots or backends usually manage nonces in one place for this reason; if you rely on a node provider, see the blockchain API and RPC provider comparison.

Nonces in smart wallets and EIP-7702

Account abstraction changes who manages the nonce. Smart contract wallets keep their own nonce logic. EIP-7702 (status Final) lets an ordinary address delegate to contract code by signing an authorization. That authorization carries its own nonce: the protocol requires the signer’s account nonce to equal the nonce in the authorization, then increases it by one. The EIP’s security notes point out two consequences. An account’s nonce can be incremented more than once in a single transaction. An account that bumps its nonce can also invalidate an authorization a relayer was about to use. It also says replay protection inside delegated code “should be implemented by the delegate and signed over.” For how smart wallets work more broadly, read what account abstraction is.

The cryptographic nonce in signatures (and why reusing it is dangerous)

Outside blockchain data structures, “nonce” is a general cryptography term: a value that must never repeat in a given context. One version matters a great deal in crypto because it protects private keys.

Bitcoin and Ethereum signatures use ECDSA. Each signature needs a fresh secret value, usually called k. If the same k is used to sign two different messages with the same key, anyone who sees both signatures can calculate k and then the private key. Two well-documented cases:

DateIncidentWhat went wrong
December 2010A group called fail0verflow recovered Sony’s PlayStation 3 ECDSA signing key, presented at the 27C3 conferenceSony used a static k instead of a fresh random one for each signature
August 2013Android Bitcoin wallets, including Bitcoin Wallet, the blockchain.info wallet, BitcoinSpinner and Mycelium, warned users of theft risk (bitcoin.org alert, 11 August 2013)Android’s secure random number generator was improperly initialized. Google’s Android developers blog (14 August 2013) said apps using its key generation and signing APIs “may not receive cryptographically strong values”

Sources: Wikipedia’s ECDSA article and its cited 27C3 presentation; bitcoin.org Android alert; Android Developers Blog, “Some SecureRandom Thoughts”.

The lesson: the security of a signature depends on a nonce you never see. It is one reason to use widely reviewed wallet software and keep your seed phrase offline.

Is a nonce the same as a salt?

No. A nonce exists to be unique, so a message, block or transaction cannot be replayed or repeated. A salt is random data added to a password before hashing, so that two identical passwords produce different hashes and precomputed attack tables do not work. A salt is usually stored alongside the hash it protects; a nonce, by definition, is not repeated in its context.

Common misconceptions about nonces

  • “The nonce is a random number.” Neither blockchain nonce is random. Miners count through block nonces; wallets increment account nonces by one. Only the signature nonce k must be unpredictable.
  • “Miners find the one correct nonce.” Many nonces can produce a valid hash. For a given header there may be none at all, which is why the extranonce exists.
  • “The nonce goes on each transaction in Bitcoin.” Bitcoin’s mining nonce is a field of the block header, not of individual transactions. The per-transaction counter is an account-chain feature, as on Ethereum.
  • “Nonces stop double spending.” On Ethereum the account nonce prevents the same signed transaction from running twice. Double spending more broadly is prevented by consensus and the ledger’s validation rules.

What this means for you

If you are learning how Bitcoin works, the nonce is the dial miners turn: it explains why mining takes so much computation and why verifying a block is cheap. If you use an Ethereum wallet, the account nonce is the reason a low-fee transaction can block everything behind it. The same nonce with a higher fee is how you get unstuck. If you build on Ethereum, treat nonce management as part of your infrastructure, especially with smart wallets and EIP-7702 delegations, where nonces can move more than once per transaction.

For related explainers, see what sharding is and how layer-2 sequencers order transactions, or browse all Guides.

This guide is general information, not financial or technical advice for any specific transaction. Double-check fees and nonces in your own wallet before sending. See the site’s disclaimer.

TG

Theo Gabriel

Theo Gabriel is a contributor at Crypto Infrastructure. He writes about blockchain development studios, smart contract auditors and node and RPC infrastructure, explaining what to check before hiring a technical partner.

How we research →