The Mining Process: nonce, extranonce & the coinbase
We know the goal: find a block header whose double-SHA-256 hash falls
below the target. We know it’s a lottery you win by sheer
volume of tries. But a header is only 80 bytes, and the nonce is only 4
of them — that’s a mere ~4.3 billion guesses, which modern hardware exhausts in a blink. So what does
a miner actually do when the nonce runs out and no block has been found? This page is the concrete
loop, and it has more moving parts than the cartoon “just increment the nonce” version suggests.
Step 1: assemble a candidate block
Section titled “Step 1: assemble a candidate block”Before hashing anything, a miner builds a candidate block:
- Collect transactions from the mempool, generally preferring those paying the highest fees per byte (the economics of which are covered under miner incentives).
- Create the coinbase transaction — the special first transaction that pays the miner the block subsidy plus the fees. It has no real inputs; its input field is free-form space the miner controls.
- Build the Merkle tree over all those transactions. Its root — the Merkle root — is a single 32-byte fingerprint that commits to every transaction and their order. Change any transaction, or even reorder them, and the root changes completely.
- Fill in the header: previous block hash, the Merkle root, the current timestamp, the
bits(target), and a startingnonce.
┌────────────────────── 80-byte block header ──────────────────────┐ │ version │ prev block hash │ MERKLE ROOT │ timestamp │ bits │ NONCE │ └────────────────────────────────────────────▲──────────────▲──────┘ │ │ changes when the coinbase changes the easy knob (4 bytes)The two highlighted fields — the nonce and (indirectly) the Merkle root — are the miner’s search space.
Step 2: roll the nonce
Section titled “Step 2: roll the nonce”The fast inner loop is just: hash the header, check against the target, increment the nonce, repeat.
for nonce in 0 .. 2³²-1: header.nonce = nonce if SHA256d(header) ≤ target: → WIN, broadcast the block # ...fell through without a winThe nonce is a 4-byte field, so it offers only 2³² ≈ 4.3 billion distinct headers. At today’s
difficulty a serious miner blows through all 4.3 billion in a tiny fraction of a second and finds
nothing. The nonce alone is nowhere near enough randomness to be likely to win. We need more
headers to try — which means we need to change the header in some other way.
Step 3: roll the extranonce (change the Merkle root)
Section titled “Step 3: roll the extranonce (change the Merkle root)”Here’s the trick. The coinbase transaction’s input contains an arbitrary data field (the “coinbase scriptSig”) that the miner can stuff with anything. A few bytes of it are designated as the extranonce. When the miner increments the extranonce:
- the coinbase transaction’s bytes change, so
- the coinbase’s hash changes, so
- the Merkle root changes (the coinbase is a leaf of the tree), so
- the header changes — handing the miner a brand-new 4.3-billion-nonce search space to grind through.
extranonce = 0 → new coinbase → new Merkle root → fresh 2³² nonces to try extranonce = 1 → new coinbase → new Merkle root → fresh 2³² nonces to try ...So mining is really a two-level loop: the cheap inner loop sweeps the 4-byte nonce; when that’s exhausted, the outer loop bumps the extranonce, rebuilds the Merkle root, and the inner sweep starts over. Between them they provide effectively unlimited headers to test — enough to keep an entire mining farm busy for the full ~10 minutes between blocks.
Step 4: vary the timestamp too
Section titled “Step 4: vary the timestamp too”The header’s timestamp is a third, smaller knob. Miners are allowed to nudge it within the consensus bounds (it must stay above the median of the last 11 blocks and not too far ahead of real time). Each distinct timestamp is yet another distinct header to hash. In practice the extranonce does the heavy lifting and the timestamp is a minor extra source of variation — but it’s part of why two miners working on “the same” block almost never collide on the same exact header.
The whole thing is brute-force search
Section titled “The whole thing is brute-force search”Step back and the picture is stark: there is no algorithm, no shortcut, no insight that finds a winning header faster than trying candidates and checking each one. Mining is brute-force search over a space of headers, parallelized across as much hardware as a miner can afford. The “smartest” miner and the “dumbest” miner use the identical procedure; the only thing that differs is how many candidates per second they can test (their hashrate). That equality of method is exactly why the winner is decided by expended work and nothing else.
The thread
Section titled “The thread”How does this help untrusting strangers agree on one ledger? The mining loop is where abstract “work” becomes a concrete, mechanical grind that anyone can audit. The winning header simultaneously commits to a specific set and ordering of transactions (via the Merkle root) and proves the energy spent to propose them (via the sub-target hash). A stranger receiving the block re-hashes once and gets both guarantees at no cost. The miner’s freedom to roll the nonce, extranonce, and timestamp is just bookkeeping for the search; the ledger everyone agrees on is whatever the winning header happened to commit to.
Check your understanding
Section titled “Check your understanding”- Why is the 4-byte nonce, by itself, not enough search space at modern difficulty?
- Trace the chain of effects when a miner increments the extranonce — from coinbase bytes all the way to a fresh nonce search space.
- Why is the coinbase transaction the natural place to put the extranonce, rather than some other transaction?
- Name the three header-affecting knobs a miner varies, and rank them by how much search space each provides.
- In what sense is mining “brute-force,” and why does that make the winner purely a function of hashrate?