This is one of the most important questions in Bitcoin. If thousands of miners around the world are all hashing, who tells them which block to work on? Who picks the transactions? Who coordinates the race?
The answer: nobody. There is no coordinator. No vote. No round-robin. No leader election. Every miner independently builds their own candidate block, and the network converges after the fact โ by everyone switching to build on whichever valid block wins the race.
Every mining node runs bitcoind (or equivalent software) and
maintains its own mempool. When it's time to build a candidate block, the
miner (or mining pool operator) does this locally:
Miner A in Texas Miner B in Kazakhstan Miner C in Japan
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Coinbase โ A's โ โ Coinbase โ B's โ โ Coinbase โ C's โ
โ address โ โ address โ โ address โ
โ โ โ โ โ โ
โ Txs: A's mempool โ โ Txs: B's mempool โ โ Txs: C's mempool โ
โ (slightly diff) โ โ (slightly diff) โ โ (slightly diff) โ
โ โ โ โ โ โ
โ Merkle root: โ โ Merkle root: โ โ Merkle root: โ
โ a1b2c3d4... โ โ e5f6g7h8... โ โ i9j0k1l2... โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
Hash away! Hash away! Hash away!
There is no "agreement" before the block is found. The agreement happens after:
The longest valid chain (more precisely: the chain with the most accumulated proof-of-work) is the one everyone follows. If you try to mine on an old block, you're racing not just against one block, but against the entire honest network that's already built on a newer tip. You would need to outrun the combined hashrate of everyone else โ which is why it's rational to always build on the tip.
Source: Bitcoin Developer Guide โ Block Prototypes; Satoshi Nakamoto โ Bitcoin Whitepaper, ยง3โ4Why does every miner end up hashing a different block header, even if they all have identical mempools?
Let's play a game. I'm thinking of a giant 256-sided die (well, actually, a number so big it has 78 digits). Your job is to roll the die over and over until you get a number smaller than 5.
That's hard! On average, you'd need to roll about 51 times to get a number under 5 (since only 1, 2, 3, and 4 count out of 256 faces). The more times you roll per second, the faster you'll find a winning roll.
Now imagine I make it harder: you need a number smaller than 1. Now the only winning roll is 0 โ and you'll need to roll about 256 times on average. Even harder: what if you needed to roll a number smaller than 0.00000000000000000001? You'd be rolling for a very, very long time.
This is exactly what Bitcoin mining is. But instead of a die, miners use a mathematical function called SHA-256 (applied twice). Instead of rolling, they feed the block header into SHA-256 and get a 256-bit number out. If that number is below the target, they win. If not, they change one number in the header โ the nonce โ and try again.
SHA-256 is a cryptographic hash function. Think of it as a fingerprint machine:
SHA256("Hello") = 185f8db3...a52f6f49 (starts with 1 โ not enough zeros)
SHA256("Hello!") = 336a6101...2b5a67b1 (completely different!)
SHA256("Hello!!") = 0a5f66c1...8829db4e (still no good)
Bitcoin uses DOUBLE SHA-256:
SHA256(SHA256(block_header)) must be < target
The nonce is a 32-bit number (0 to 4,294,967,295) in the block header. The miner's ASIC tries:
Try nonce = 0: SHA256ยฒ(header with nonce=0) โ 7a3f... Too big โ
Try nonce = 1: SHA256ยฒ(header with nonce=1) โ e2c1... Too big โ
Try nonce = 2: SHA256ยฒ(header with nonce=2) โ 9d4b... Too big โ
...
Try nonce = 847,203,661: SHA256ยฒ(header with nonce=...) โ 0000... Below target โโโ
โโโ BLOCK SOLVED! โโโ
Modern ASICs try hundreds of trillions of nonces per second. But 4 billion nonces isn't enough when the difficulty is high โ so miners also tweak the extra nonce in the coinbase transaction, which changes the Merkle root, giving them a fresh 4 billion nonces to try. They repeat this continuously until someone, somewhere, finds a valid hash.
You may have heard "miners look for a hash starting with many zeros." This is because the target is a very small number. In hexadecimal, small numbers start with zeros. The more leading zeros required, the harder the problem.
At the current network difficulty (~112 trillion), the target is so small that a valid block hash needs roughly 19 leading zeros in hex. The entire network โ around 800 exahashes per second โ takes about 10 minutes on average to find one.
Imagine every miner in the world has a magic bingo machine. Each machine shakes a giant bucket of numbered balls and spills them out. If the numbers that come out are all very small numbers (mostly zeros), the miner shouts "BINGO!" and wins a prize โ 3.125 brand-new bitcoins plus all the transaction tips.
The machines shake incredibly fast โ trillions of times per second. The whole world's machines shake together, but they all have slightly different buckets (because each miner's prize address is different, which changes the balls inside). The first machine to get a "bingo" wins, and everyone immediately resets and starts shaking for the next round.
The game automatically adjusts: if bingos start coming too fast (faster than every 10 minutes), the game makes the target smaller โ you need even smaller numbers. If bingos are too slow, it makes the target bigger. This happens every 2,016 rounds (~2 weeks).
That's Bitcoin mining. Trillions of magic bingo shakes per second, worldwide, with a new winner every ~10 minutes.
Why do miners also modify the "extra nonce" in the coinbase, instead of just trying all 4 billion nonce values?
Bitcoin's security doesn't come from trust, police, or a central authority. It comes from game theory and economic incentives.
A miner who plays by the rules earns:
Revenue per block = 3.125 BTC (subsidy) + fees from all included transactions
โ $300,000+ per block at current prices
Mining costs real money โ electricity, hardware depreciation, cooling, facility costs. A cheater who gets caught (or whose invalid block is rejected by the network) earns zero for all that work. The economic incentive is overwhelmingly to mine honestly.
A 51% attack (more accurately: a majority-hashrate attack) means an attacker controls more than half of the total network hashrate. With majority hashrate, they can:
To control 51% of the network (~400 EH/s), you'd need roughly $20โ40 billion in ASIC hardware, plus ongoing electricity costs of ~$10โ15 million per day. The attack burns money continuously while the honest chain keeps advancing.
You can't just "buy" 51% of the hashrate. ASICs are manufactured by a handful of companies (mostly Bitmain and MicroBT) with finite production capacity and long lead times. You'd need to outbid the entire existing mining industry for years of production.
400 EH/s consumes roughly 12โ15 gigawatts โ comparable to the entire electricity consumption of a mid-sized country. Finding that much power, getting grid connections, and building facilities takes years.
A successful 51% attack would destroy confidence in Bitcoin, crashing the price. The attacker's hardware (purpose-built for SHA-256 mining) would become near-worthless. The billions spent on the attack would vaporise. You'd spend $30B to maybe steal $5B โ and destroy the asset in the process.
Mining is spread across the globe โ United States, Kazakhstan, Russia, Canada, and dozens of other countries. No single jurisdiction can compel miners to collude. Pool operators can be pressured, but miners can switch pools in minutes.
A 51% attack is immediately visible (large reorgs, censored transactions). The community can respond: exchanges can raise confirmation requirements, developers can propose checkpointing or PoW changes, and honest miners have every incentive to coordinate a counter-response. The attacker can't do it secretly.
Mining pools introduce a subtlety. A single pool controlling >50% of hashrate is a theoretical concern โ and it has come close (GHash.io briefly exceeded 50% in 2014). But pool hashrate is not the same as attacker hashrate:
Even with 51% hashrate, you cannot rewrite arbitrarily far back. The further back you go, the more blocks you need to re-mine, and the honest chain keeps advancing while you try to catch up. The probability of catching up from k blocks behind decreases exponentially with k. This is why 6 confirmations is the standard โ after 6 blocks, the probability of a successful reorg by an attacker with even 40% of hashrate is effectively zero.
A common misconception: "If someone controls 51% of mining, they can steal everyone's bitcoin." This is false.
If an attacker gains 60% of the network hashrate, which of these can they NOT do?