Sign in

Blocks and mining

Suggest an edit

Bitcoin has no list of participants, so the right to add a block is sold for computational work, and a million fake participants pay a million times the electricity bill. The design philosophy lesson called this proof of work. The participants who do the work are called miners. They compete to build the next block, and only the winner gets to add to the chain. That lesson left one question open, which is what the work itself should be.

The work has to meet four requirements

Hard to do. The work has to cost a real resource. If it were cheap, a million fake participants would be cheap too.

Cheap to check. Every node verifies every block itself, so checking that the work was done has to take almost no time on an ordinary computer.

Tied to one block. The proof has to depend on the block's transactions and on the block it builds on. Otherwise a miner could do the work once and attach the same proof to any number of blocks, or copy the proof from someone else's block onto their own. In both cases a block is added without new work.

Adjustable. Miners join and leave and hardware gets faster, but blocks have to keep arriving about ten minutes apart, so that each block reaches most of the network before the next one is produced. The difficulty of the work has to be a number the protocol can move.

A hash function gives all four. In the hashing lesson you saw that a hash looks random, that the only way to find an input with a required hash is to try inputs one by one, and that computing one hash is fast. So the work can be a search for an input whose hash meets some condition, and checking the result takes one hash. If the input is the block itself, the result belongs to that block only. If the condition is that the hash, read as a number, is below a threshold, called the target, then moving the target changes how many attempts the search takes.

The puzzle is a header hash below a target

A block is a batch of transactions plus a small header, and the header is what miners hash.

Bitcoin block structure: 80-byte header and transaction listA Bitcoin block has two parts: a small block header on top and a much bigger transaction list below. The header is exactly 80 bytes and holds the version, previous block hash, merkle root, timestamp, bits, and nonce, while the transaction list is typically 1 MB to 4 MB, starting with the coinbase transaction and followed by thousands more. 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.

Three of the header's fields matter here. The first is the hash of the previous block's header, which links the blocks into a chain, as in the What is blockchain lesson. The second is the Merkle root of the block's transactions, one hash that commits to every one of them. The third is the nonce, a number the miner is free to change. Every other field is fixed before the search begins.

Six fields of a block header, totaling 80 bytesThe header holds six fields: version, prev_block_hash, and merkle_root in the top row, then timestamp, bits, and nonce below, each labeled with its byte size and role. Five fields are set by existing data, while the nonce is the only field a miner chooses. 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.

With that header, Bitcoin's proof-of-work puzzle can be stated in one sentence.

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.

Double-SHA-256 means SHA-256 applied twice. A SHA-256 hash is 64 hex digits when written out. Read as one very large number, a hash is small when it starts 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.

Mining loop: pick nonce, hash header, compare to target, mine blockA flowchart shows a miner picking a nonce, hashing the 80-byte header with double SHA-256, and checking if the hash is less than the target: if not, it tries the next nonce, and if yes, the block is mined and broadcast. Below, three example hashes show two failed attempts that are too big and a winning attempt with about 20 leading zero hex digits, smaller than the target. 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.

Mining is easiest to understand by doing it once yourself, even on a small 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

The puzzle meets the first three requirements as follows.

The puzzle is hard. The target is small enough that almost every attempt fails. Today the network as a whole performs roughly 10²¹ hash attempts per second, and 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, so the network agrees quickly on which miner won.

The puzzle is tied to a specific block. If a miner changes one transaction or builds on a different previous block, the header hash changes and the search starts over.

The target moves to keep blocks ten minutes apart

The fourth requirement is met by the target. The target 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 about five minutes apart. If global hashing power crashes, blocks come slower.

So every 2,016 blocks (about every two weeks), every node recomputes the target. If the last 2,016 blocks took longer than two weeks to produce, the target is loosened, which means raised so that more hashes qualify. 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, and the block time has stayed at ten minutes the whole way.

The winning miner is paid in fees and new bitcoin

The miner who finds a block gets two things in return for the work. First, all of the transaction fees from the transactions bundled into the block. Second, a fresh amount of newly created BTC, called the block subsidy. 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 reward is paid by the first transaction in every block, 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.

The block subsidy started at 50 BTC and halves every 210,000 blocks, which is roughly every four years. Since the fourth halving in April 2024 it is 3.125 BTC. This schedule is enforced by the protocol, and 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 21-million-coin cap is not a separate rule. It follows from the halving schedule. The first 210,000 blocks issued 50 BTC each, which is 10.5 million BTC. Each following period of 210,000 blocks issues half as much as the one before, 5.25 million, then 2.625 million, and so on. Each period adds half of what is still missing to reach 21 million, so the total approaches 21 million but never exceeds it.

Bitcoin block subsidy halving, 50 BTC in 2009 down to 3.125 BTC by 2024A step chart shows the block subsidy in BTC on the y-axis and years from 2009 to 2028+ on the x-axis. The subsidy starts at 50 BTC and halves every 210,000 blocks, dropping to 25, 12.5, 6.25, and 3.125 BTC, approaching zero near year 2140 with total supply capped at 21 million. 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.

Around the year 2140 the subsidy will drop to zero, and miners will be compensated only by transaction fees.

Small miners pool their work for a steady income

A miner with a small share of global hashpower finds blocks rarely. Take a miner with 10¹⁵ hashes per second, one millionth of the network's 10²¹. On average it finds one block in a million, and a million blocks at ten minutes each is about 19 years. The reward when one finally lands is the same 3.125 BTC plus fees as anyone else's, but waiting two 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 as they 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 once in about two decades to a small payout every day, and practically every commercial miner today operates this way.

The cost is that 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. Bitcoin has no clean fix for this.