Live model · Bitcoin mining

How Bitcoin Mining Actually Works

Bitcoin miners are guessing. Each one hashes an 80-byte block header with SHA-256, twice, changing a number called the nonce each time, until the hash falls at or below a target: it starts with a long run of zero bits. Nobody can aim for that; the only way is to try. The winner adds the block and collects the reward.

Mining one block, nonce by nonce

The header packs the previous block's hash, the merkle root of 3 transactions, the time and the target, nBits 0x1f100000. A winning hash must start with 12 zero bits. Only the nonce is left to change.
StopProof of work
Zero bits neededSecond transaction
Tries0Target12 zero bitsChance per try1 in 4,096

Block header: 80 bytes

FieldBytesValue
version40x20000000
previous block32000b8a…8091
merkle root32e32dfa…33d8
time42026-10-21 12:00:12 UTC
nBits (target)40x1f100000: 12 zero bits
nonce4·

Header hash

SHA-256, twice

Tries by leading zero bits

Each extra zero bit is about half as common as the one before.

Watch the Python behind this model run, line by line

How to read the stage

The table is the header: the previous block's hash, the merkle root of three transactions, the time, the target and the nonce. The cells are the first 12 hex digits of the hash, each over its 4 bits. This target needs 12 zero bits, 1 hash in 4,096. The best hash climbs from 4 zero bits to 11, and nonce 3,955 wins on try 3,956. The bars count every try by its zero bits.

Why zeros mean work

SHA-256 has no shortcut: change the nonce by one and the whole hash scrambles, so every try is a fresh lottery ticket. Each zero bit the target asks for halves the odds and doubles the average work, while checking a winner takes one hash. Bitcoin moves the target every 2,016 blocks to keep blocks about 10 minutes apart. At the difficulty of October 21, 2026, a hash needed about 79 zero bits, not 12.

Block 0, hashed for real

The same code hashes Bitcoin's first block, mined on January 3, 2009, from the six fields in Bitcoin Core's source. Out comes the hash Bitcoin Core checks block 0 against, 000000000019d668… ending 8ce26f: 43 zero bits, where its target asked for at least 32. Move the nonce by one and the hash lands nowhere near.

Bitcoin's block 0, hashed from its fields

Block 0, mined 2009-01-03 18:15:05 UTC. Six fields, 80 bytes: numbers are stored little-endian, so the time and the nonce 2,083,236,893 read backwards as bytes.
StopBlock 0
Change the nonce by
Nonce2,083,236,893Zero bits·

Block 0's header

FieldValueAs bytes
version101000000
previous blocknone: all zeros00…00
merkle root4a5e1e…a33b3ba3ed…1e5e4a
time2009-01-03 18:15:05 UTC29ab5f49
nBits0x1d00ffffffff001d
nonce2,083,236,8931dac2b7c

The hash as explorers show it

the digest's bytes, reversed

SHA-256

Watch the Python behind this model run, line by line

Why nobody can edit an old block

Each header holds the previous block's hash, and its merkle root commits to every transaction. Turn block 2's 3 BTC into 30 and its hash changes, misses the target, and block 3's link to it breaks. The forger has to re-mine block 2 and every block after it, 437 more tries here, while honest miners keep extending the real chain. As the whitepaper puts it, the forger must catch up with and surpass them.

Forging a payment in block 2

Four blocks, mined honestly: 1,297 tries in all. Each header holds the hash of the block before it, and each hash starts with 8 zero bits.
StopA chain of blocks
Edit the payment in blockZero bits needed
Honest work1,297 triesForger's work0 tries

Each block names the one before it

prev ✓prev ✓prev ✓Block 1✓000ed33a…Block 2✓007cf079…Block 3✓0094975b…Block 4✓00b34106…

Blocks, each hash needing 8 zero bits

BlockPaymentPrev namesNonceHashValid
1Ana pays Ben 1 BTC000b8a2f…556000ed33a…✓
2Ben pays Cal 3 BTC000ed33a…545007cf079…✓
3Cal pays Dee 2 BTC007cf079…80094975b…✓
4Dee pays Eve 4 BTC0094975b…18400b34106…✓
  • CH1 forged payment

Watch the Python behind this model run, line by line

What the model leaves out

Real transactions are signed inputs and outputs, not lines of text; the model hashes text through the same merkle tree. The target here is 1 in 4,096 so a re-run takes milliseconds, and the model stops at 20,000 tries, where a miner runs through all 4.29 billion nonces and then changes the time or the coinbase. Real nodes also check far more than the hash.

Questions

What are Bitcoin miners actually computing?
SHA-256 of SHA-256 of an 80-byte block header, over and over, with a different nonce each time, looking for a hash at or below the target the header's nBits field encodes. Nothing else is calculated: the winning hash is the proof that the work was done.
How long does it take to mine a block?
About 10 minutes on average, for the whole network together. Every 2,016 blocks, Bitcoin compares how long they took with two weeks and adjusts the target, so blocks stay near 10 minutes as miners join and leave.
What do miners get for a block?
The block subsidy, 3.125 BTC since the halving at block 840,000 in April 2024, plus the fees of the transactions they include. The subsidy halves every 210,000 blocks; the next halving comes at block 1,050,000.
Why do Bitcoin block hashes start with zeros?
A valid hash must be at or below the target, and a small number written as 64 hex digits starts with zeros. The hash is also shown with its bytes reversed, so the zeros SHA-256 left at the end of the digest appear at the front.
What is the nonce?
A 4-byte number in the header that the miner is free to change. It holds about 4.29 billion values. Once they're all tried, Bitcoin's developer reference says the time can be updated or the coinbase transaction changed, which changes the merkle root, and the nonces start again.

More of how it works