-
Notifications
You must be signed in to change notification settings - Fork 0
How Bitcoin Mining Works
A technical overview of Bitcoin mining for curious nerds.
Bitcoin mining is the process of:
- Collecting transactions into a block
- Finding a special number (nonce) that makes the block's hash meet a difficulty target
- Broadcasting the valid block to the network
- Receiving the block reward (currently 3.125 BTC + fees)
Every Bitcoin block has an 80-byte header:
| Field | Size | Description |
|---|---|---|
| Version | 4 bytes | Block version number |
| Previous Block Hash | 32 bytes | Hash of the previous block |
| Merkle Root | 32 bytes | Hash of all transactions in the block |
| Timestamp | 4 bytes | Unix timestamp |
| Difficulty Target | 4 bytes | Compact difficulty representation |
| Nonce | 4 bytes | The number miners iterate |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Block Header (80 bytes) β
ββββββββββββ¬ββββββββββββββββββ¬ββββββββββββββββββ¬βββββββββββ¬ββββββββββ¬ββββββββ
β Version β Prev Block Hash β Merkle Root βTimestamp β Bits β Nonce β
β 4 bytes β 32 bytes β 32 bytes β 4 bytes β 4 bytes β4 bytesβ
ββββββββββββ΄ββββββββββββββββββ΄ββββββββββββββββββ΄βββββββββββ΄ββββββββββ΄ββββββββ
The miner receives a block template from the pool (or Bitcoin Core):
- Previous block hash
- Transactions to include
- Coinbase transaction (where reward goes)
- Current difficulty target
The miner constructs the 80-byte header with:
- All fixed fields from the template
- A starting nonce (usually 0)
1. Compute SHA256(SHA256(header)) = hash
2. Check if hash < target
3. If yes β Found a block! Submit it.
4. If no β Increment nonce, go to step 1
When a valid hash is found:
- Submit to pool or Bitcoin Core
- Block propagates to network
- Other nodes verify and accept
- Miner receives reward
Bitcoin uses double SHA256 for security:
hash = SHA256(SHA256(block_header))
- Prevents length extension attacks
- Defense in depth - if SHA256 is partially broken, double hashing helps
- Satoshi's design choice
Block 125552 header:
0100000081cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000
e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122bc7f5d74d
f2b9441a42a14695
SHA256d hash:
00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d
Notice all the leading zeros - that's what makes it a valid block!
Difficulty is a measure of how hard it is to find a valid block. It adjusts every 2016 blocks (~2 weeks) to maintain ~10 minute block times.
The target is a 256-bit number. A valid block hash must be less than the target.
Difficulty 1 target:
0x00000000FFFF0000000000000000000000000000000000000000000000000000
This has ~32 leading zero bits.
As of 2025:
- Difficulty: ~148 trillion
- Required leading zeros: ~67-68 bits
- Target: astronomically small
new_difficulty = old_difficulty * (2016 blocks actual time / 2 weeks)
If blocks were found too fast, difficulty increases. If blocks were found too slow, difficulty decreases.
The nonce is a 32-bit number (0 to 4,294,967,295) that miners iterate.
At 350 MH/s, you exhaust all 4 billion nonces in ~12 seconds. But blocks take 10 minutes on average!
Pools provide an extranonce field in the coinbase transaction. When you exhaust the nonce space:
- Increment extranonce
- Recalculate merkle root
- Start nonce from 0 again
This gives effectively unlimited search space.
βββββββββββ shares ββββββββ block βββββββββββ
β Miner β βββββββββββββ> β Pool β ββββββββββββ> β Network β
βββββββββββ ββββββββ βββββββββββ
β
β proportional reward
βΌ
βββββββββββ
β Miner β
βββββββββββ
- Submit shares (low-difficulty proofs of work)
- Pool submits blocks to network
- Reward split among all miners proportionally
- Steady, predictable income
βββββββββββ block βββββββββββ
β Miner β βββββββββββββββββββββββββββββββββ>β Network β
βββββββββββ βββββββββββ
β
β full reward (if found)
βΌ
βββββββββββ
β Miner β
βββββββββββ
- Submit directly to network (via pool or Bitcoin Core)
- You keep the entire block reward
- Extremely unlikely to find a block
- Lottery-style mining
Your hashrate: 350,000,000 H/s
Network hashrate: 700,000,000,000,000,000,000 H/s
Your share: 0.0000000000005%
Hashes per day: 350 MH/s Γ 86,400 seconds = 30.24 trillion
Probability: 30.24T / (network_difficulty Γ 2^32) β 1 in 13 trillion
1 / (probability per day) β 37,000 years
Despite the odds:
- The Dream - One lucky hash = ~$300,000+
- No Pool Fees - Keep 100% of the reward
- Decentralization - Support the network
- Learning - Understand Bitcoin deeply
- Fun - It's a lottery ticket that does useful work