Finance / Bitcoin mining

Bitcoin mining

How a new block is made: gather transactions, guess numbers until a hash comes out small enough, let everyone check it in one step, and collect the reward. Then what it costs.

Intermediate7 steps~7 min
Miner — builds blocks and guesses nonces
Transaction — a payment waiting, with its fee
Node — checks every block against the rules
// THE SHORT VERSION

In 30 seconds

Mining is how Bitcoin adds a block without anyone in charge. A miner gathers waiting transactions and then searches for a number, the nonce, that makes the block’s hash fall below a target.

There is no shortcut, only guessing, so a valid block proves that work was done. Checking it takes a single hash.

The network retunes the target every 2,016 blocks to keep blocks about ten minutes apart. The winner earns new coins, an amount that halves every 210,000 blocks, plus fees. The guessing consumes a great deal of electricity.

Bitcoin mining, step by step

STEPS01 / 07

The search is real but tiny: SHA-256 once over the text “block 103 | prev 007e | nonce N”. Bitcoin hashes the 80-byte header twice, and a retarget is limited to a factor of 4 either way.

STEP 01 / 07 Collect transactions
THE MATH
mempool -> candidate block best fees first + one payment to the miner
  1. Step 1: Collect transactions. Signed transactions wait in each node’s memory pool. A miner fills a candidate block from it. Space is limited, so miners usually take the transactions offering the highest fee for the room they use. The first entry is special: it pays the miner the new coins and the fees.
  2. Step 2: The block header. The miner summarises the block in an 80-byte header. It names the previous block by its hash, commits to every transaction through one Merkle root, and states the target the hash must beat. The nonce is a free number with no meaning: it exists so the miner has something to vary.
  3. Step 3: Search for a nonce. The block counts only if the hash of its header is below the target. Here the toy target is: start with 000, a 1 in 4,096 chance per try. A hash cannot be steered, so the miner just tries nonce 0, 1, 2 and so on. Nonce 1791 is the first to work, after 1,792 tries.
  4. Step 4: Hard to find, easy to check. The winner sends the block to the network. Every node recomputes the single hash, sees it is below the target, checks the transactions and adds the block to its chain. The winning hash is the proof of work. All miners then drop their attempts and start on the next block.
  5. Step 5: Difficulty adjustment. More miners means blocks come faster. So every 2,016 blocks each node compares the time they took with the planned two weeks and rescales the target. If they took 7 days, the difficulty doubles: the target halves. Blocks stay about ten minutes apart however much hardware joins.
  6. Step 6: Reward and halving. The winner’s reward is the fees in the block plus newly created bitcoin, the only way new coins appear. The new-coin part began at 50 BTC and is cut in half every 210,000 blocks: 25 in 2012, 12.5 in 2016, 6.25 in 2020 and 3.125 in 2024. In time, fees must carry more of the reward.
  7. Step 7: Energy use. Every guess costs electricity, and all but the winning one are discarded. Miners add machines while the reward is worth more than the power, so energy use follows the reward’s market value, not the number of payments. Estimates put it near a mid-sized country’s electricity use, though figures are uncertain.
VALUES SO FAR
block5 txs + rewarddraft
header····rule
prev····input
target····toy
nonce····result
hash····result
check····rule
retarget····rule
halving····rule

Spotted a mistake on this page?