Sign in

Blocks and mining

A transaction sitting in a wallet is just a string of bytes. A transaction sitting in the Bitcoin network's mempool is just a string of bytes that many nodes happen to know about. Neither of those is settlement. The transaction is settled when it lands in a block, that block lands in the chain, and enough additional blocks pile on top of it that reversing the order would cost more than anyone would rationally spend. This lesson is about how that landing happens. Who builds the block. What's inside it. What the proof-of-work puzzle actually is. Why solving the puzzle is hard and checking the solution is trivial. And how new bitcoin gets minted into existence at the same moment each block is built.

From transactions to blocks

A block is a batch of transactions, plus a small header that gives the batch an identity and connects it to the previous block in the chain. Anyone running mining software is competing to be the one who builds the next block. The competition is the proof-of-work puzzle, and only the winner gets to add to the chain.

The winner gets two things in return for their work. First, all of the transaction fees from the transactions they bundled into the block. Second, a fresh amount of newly-created BTC, called the block subsidy, which is currently 3.125 BTC and halves every four years on a fixed schedule. Together these two things are called the block reward, and they're the only reason mining happens at all. Without the reward, there would be no incentive to spend electricity on hashing.

The pattern of one new block roughly every ten minutes is a deliberate choice you've already met. Slow block times leave room for new blocks to reach most of the network before the next one is produced, which keeps the network converging on the same chain. Faster blocks would mean more accidental forks. Ten minutes is conservative on purpose.

What's inside a block

A block has two parts.

A Bitcoin block Block header exactly 80 bytes version, prev_block_hash, merkle_root, timestamp, bits (difficulty target), nonce Transaction list typically 1 MB to 4 MB, thousands of txs tx 0: coinbase (creates new BTC) tx 1: ... tx 2: ... tx 3: ... ...thousands more... A tiny header sitting on top of a much bigger transaction list.

The disproportion in this diagram is the most important thing to notice. The block body is megabytes of transaction data. The block header is exactly 80 bytes, no matter what. This asymmetry is not an accident. A light-weight wallet running on a phone wants to verify that a particular transaction is in the chain without storing the entire chain. It can do this by storing only block headers and asking a full node for a Merkle proof when it needs to check a specific transaction. The headers add up to about 4 megabytes per year. The whole structure is shaped to make that lightweight verification work, which is one of the design choices that fell out of "public verifiability" in the framing lesson.

The six fields in a block header

Each block header packs six fields into exactly 80 bytes.

Block header (80 bytes total) version 4 bytes format flags prev_block_hash 32 bytes links to previous block merkle_root 32 bytes commits to all txs timestamp 4 bytes when mined bits 4 bytes difficulty target nonce 4 bytes what miners search Five fields are determined by the world. The nonce is the only one a miner gets to choose.

Take a closer look at three of these because they carry most of the meaning.

The prev_block_hash is the hash of the previous block's header. This is what makes the chain a chain: every block points backwards to one specific predecessor by hash. Change anything in any past block, even one bit of one transaction, and the Merkle root in that block's header changes, which changes that block's hash, which means every block built on top of it has the wrong prev_block_hash and the entire later chain is invalidated. This is the structural source of permanence.

The merkle_root is a single 32-byte commitment to every transaction in this block. It's computed by building a Merkle tree over the transaction list and taking the root. This is why the header doesn't need to grow with the block: no matter how many thousands of transactions are in the block, the commitment to all of them fits in 32 bytes. A light client can ask for a Merkle proof that a specific transaction is in this block, and verify the proof against the merkle_root in the header, without ever downloading the rest of the block.

The nonce is the only field a miner gets to vary freely. It's a 4-byte integer the miner increments while searching for a header whose hash falls below the difficulty target. Everything else in the header is constrained by the world. Only the nonce is up to the miner.

The mining puzzle

Now the puzzle itself. Bitcoin's proof-of-work puzzle has a clean statement.

Given a block header that's almost complete, find a value for the nonce such that the double-SHA-256 hash of the entire header, treated as a number, is less than the difficulty target.

That's it. That's the whole puzzle.

The "treated as a number" framing matters. A SHA-256 hash is 32 bytes, which is 64 hex digits when written out. Treating that hex string as a single very large number, the puzzle is just to make that number small. And the easiest way to make a number small in hex notation is to have it start with zeros. A hash like 8a4f2e9c... is huge. A hash like 0000abc... is much smaller. A hash like 00000000000000abc... is tiny.

So in practice, what miners are looking for is a hash that starts with a specific number of leading zero digits. Today, the target requires roughly 20 leading zero hex digits at the front of the hash before it qualifies. A miner who gets 18 leading zeros has missed and has to try a different nonce. A miner who gets 20 or more has found a winning block.

The mining loop no, try the next nonce pick a nonce start at 0, increment double SHA-256 hash the 80-byte header hash < target? compare to bits yes block is mined broadcast to the network What "hash < target" looks like in practice target: 0000000000000000000000abc4f2e9c1b7d3a8... attempt 1: 8a4f2e9c1b7d3a8b2c5e9f0123456789abcdef... too big (fail) attempt 2: 00f2a91c4b7d3a8b2c5e9f0123456789abcdef... still too big (fail) attempt N: 00000000000000000000007a91c4b7d3a8b2c5... smaller than target, winner The hash must have around 20 leading zero hex digits today to qualify. A miner runs this loop billions of times per second on dedicated hardware. The whole network produces one winner roughly every ten minutes.

The static picture is the structure. The thing that makes mining click is doing it once yourself, even at toy scale. Try the puzzle below before reading on. Change the data, watch the hash flip wildly, then mine for a hash that starts with a few zeros and feel how the work scales with each extra zero you ask for.

Block miningInvalid
Hash
 
Target: hash starts with 0000

Three properties of the puzzle make the whole system work.

The puzzle is hard. SHA-256 has the avalanche property you've already seen, so there's no way to look at the target and calculate which nonce will produce a hash below it. You simply have to try different values until one works. The target is small enough that almost every attempt fails. Today the network as a whole performs roughly 10²¹ hash attempts per second. That's 1,000,000,000,000,000,000,000 attempts every second, across all the mining hardware on the planet. Even at that rate, finding one winning nonce takes about ten minutes.

The puzzle is verifiable instantly. Once a miner publishes a winning nonce, any node can hash the header once, compare to the target, and confirm in microseconds. Hard to solve, trivial to check. This asymmetry is what lets the network agree quickly on which miner won.

The puzzle is tied to a specific block. The hash inputs include the prev_block_hash and the merkle_root, so a winning nonce for one block doesn't transfer to any other block. The proof of work is bound to this exact block on this exact chain. Reorganising a winning nonce into a different chain is impossible.

Mining pools

The math from the puzzle section has a consequence worth naming. A miner with a small share of global hashpower finds blocks rarely. With the network running at roughly 10²¹ hashes per second, an individual miner running modest hardware at a few terahashes per second would, on average, wait decades between finding a block. The reward when one finally lands is the same 3.125 BTC plus fees as anyone else's, but waiting decades for any income is not how a business runs. The standard response is mining pools. A pool operator builds a candidate block template and hands the header out to each connected miner along with the network's difficulty target. Each miner hashes nonces against that template exactly as it would solo. When a miner finds a hash that's below a much easier share target, easier than the real network target by some configurable factor, it submits that share to the operator as evidence of work done. The pool counts shares from everyone, and when one of the submitted hashes happens to also be below the real network target, the pool publishes the block and splits the reward in proportion to how many shares each miner contributed during the round. The participating miner's income changes from "3.125 BTC every several decades" to "a small payout every day," and practically every commercial miner today operates this way.

The cost is a centralization concern. A handful of large pools together control most of Bitcoin's hashpower at any given time. The pool operator is the one who decides which transactions go into the block template, so the operator effectively controls block contents on behalf of all the miners pointed at them. The underlying miners can switch pools if an operator misbehaves, and switching is fast with no lock-in, but the day-to-day power to censor or include transactions sits with a small number of pool operators rather than with the thousands of individual miners. This is one of the most-discussed structural tensions in Bitcoin and there's no clean fix to it.

The coinbase transaction and the supply schedule

Every block has a special first transaction called the coinbase transaction. Unlike every other transaction in Bitcoin, the coinbase has no inputs from any prior UTXO. It creates value from nothing. The miner sets the value of its single output to whatever the protocol's current block subsidy is, plus the total fees from every other transaction in the block, and sends that to an address the miner controls.

This is the only mechanism that ever creates new BTC. Every bitcoin in circulation was originally minted as the output of some coinbase transaction by some miner at some point in the past.

The block subsidy starts at 50 BTC and halves every 210,000 blocks, which is roughly every four years. The halvings so far:

  • Genesis (2009): subsidy was 50 BTC
  • First halving (November 2012): dropped to 25 BTC
  • Second halving (July 2016): dropped to 12.5 BTC
  • Third halving (May 2020): dropped to 6.25 BTC
  • Fourth halving (April 2024): dropped to 3.125 BTC, where it sits today
  • Next halving (expected April 2028): will drop to 1.5625 BTC
0 12.5 25 50 block subsidy (BTC) 2009 2012 2016 2020 2024 2028+ 50 25 12.5 6.25 3.125 Block subsidy halves every 210,000 blocks Asymptotically approaches zero around year 2140. Total supply caps at 21 million.

This schedule is enforced by the protocol. There's no governance body that can change it. A miner who tries to publish a block with an oversize coinbase output will have that block rejected by every honest node on the network. The constraint is structural.

Around the year 2140 the subsidy will drop to zero, and miners will be compensated only by transaction fees. The 21-million-coin cap follows from this halving schedule: each halving issues half as much as the previous, so the total approaches 21 million but never exceeds it. The cap isn't a separate rule. It's a consequence of the curve.

Difficulty adjustment

One last mechanism keeps the system stable: the difficulty adjustment.

The proof-of-work target is what determines how hard it is to find a winning nonce. If global hashing power doubles overnight, and the target stays the same, blocks start coming faster than ten minutes apart. If global hashing power crashes, blocks come slower.

Either situation is bad for the network. So every 2,016 blocks (about every two weeks), every node recomputes the target. The recomputation is simple: if the last 2,016 blocks took longer than two weeks to produce, the target is loosened. If they took less, the target is tightened.

The effect is that long-run block times stay close to ten minutes regardless of how much hashing power is pointed at the network. The difficulty has risen by roughly a factor of 100 trillion since Bitcoin launched in 2009. The block time has stayed at ten minutes the whole way.