Mining Academy

Connect to the pool

How Bitcoin Mining Works: Block, Hash, Nonce, Halving

Bitcoin mining is a continuous search in which a device computes the hash of a block header, changing a number called the nonce until the result falls below a target value set by network difficulty. Whoever finds such a hash first adds the block to the chain and collects the reward: the block subsidy plus transaction fees. The right value can only be found by trial and error, yet any node can verify it instantly, and that asymmetry is what secures the network.

The block and its header

The Bitcoin blockchain is a chain of blocks, each containing a set of transactions and a reference to the previous block. That reference makes the chain tamper-resistant: to alter a transaction in an old block you would have to redo that block and every block after it.

For mining, what matters is not the whole block but its header, 80 bytes of data from which the device computes the hash. The header contains:

  • the version of protocol rules;
  • the previous block hash, the link that chains blocks together;
  • the Merkle root, a single hash representing all transactions in the block: changing any transaction changes the root and therefore the whole header;
  • the timestamp of block creation;
  • bits, the encoded difficulty target;
  • the nonce, the number the miner varies.

The first transaction in a block is special and is called the coinbase: in it the miner creates new coins and names who receives them, and also collects the fees from all other transactions in the block.

The hash: why it cannot be worked out by thinking

A hash function turns any data into a fixed-length string. Bitcoin uses SHA-256 applied twice. The function has these properties: identical input always yields identical output; the slightest change to the input completely changes the output; and from the output you cannot recover the input or predict how to alter the input to get a chosen result.

That last property makes mining a fair lottery. The only way to get a hash with the required property is to try variants. Changing the nonce gives a completely new, unpredictable hash. Each attempt is an independent trial with the same probability of success. Your chance of finding a block therefore depends only on the number of attempts, which is your hashrate.

Nonce, extranonce and the difficulty target

The task is stated like this: the header hash, viewed as a very large number, must be below a target. The smaller the target, the fewer valid hashes exist and the harder a block is to find. It is often pictured as requiring the hash to start with a certain number of zeros, although the real condition is numeric.

The nonce field is 4 bytes, around four billion values. Modern ASICs run through them in a fraction of a second. When the nonce is exhausted, the miner changes other data, such as the timestamp or the so-called extranonce in the coinbase transaction, which changes the Merkle root, and the search starts anew. In practice pools hand different ranges to different devices so nobody repeats another's work. How a job reaches an ASIC and how found solutions return to the pool is explained in What is Stratum.

Difficulty: how the network keeps a ten-minute rhythm

Miners' computing power on the network keeps changing: new ASIC models appear and farms connect and disconnect. If the condition never changed, blocks would sometimes come every minute and sometimes once a day. To prevent that, the protocol regularly adjusts difficulty. The target time between blocks is about ten minutes. Every 2016 blocks, roughly every two weeks, the network compares the actual time taken with the expected time and adjusts: if blocks came faster, difficulty rises; if slower, it falls.

A practical takeaway for a miner: difficulty tends to rise over the long run as new capacity comes online. If your hashrate stays the same while the network grows, your share shrinks and, all else equal, your income in coins drops. Payback calculations should therefore leave room for difficulty growth.

Note that difficulty does not change how fast your device runs; it changes what share of attempts succeed. The ASIC still computes the same number of hashes per second, but each one is less likely to be a winner. That is why rising difficulty cannot be offset by tweaking settings: the only answers are more efficient hardware or cheaper electricity. Networks with other algorithms, such as Litecoin, work in a similar way, but each has its own block parameters and difficulty adjustment rules.

To get a feel for the scale, imagine a lottery where your ticket has the same tiny chance in every draw. If your hashrate is one millionth of the network's, on average you get one millionth of the blocks, roughly one block per million blocks, which at a ten-minute rhythm means about twenty years of waiting. That is an average, not a schedule: you might find a block tomorrow or not for a decade. This arithmetic is the main reason solo mining with a few devices is practically never used.

The reward: subsidy and fees

The block reward has two parts.

  • The subsidy is newly created coins issued by the protocol. This is the only way Bitcoin enters circulation.
  • Fees are the sum of fees that senders paid to get their transactions into the block. Under heavy network load their share grows noticeably.

A word on fees: block space is limited, so transactions compete for it. When assembling a block, a miner takes the ones paying more first, and that is how the market price of a transfer is formed. For a miner this means fee income fluctuates with network load and cannot be planned as firmly as the subsidy.

The subsidy is not constant. This is where the halving comes in.

Halving

A halving cuts the subsidy in half every 210,000 blocks, about every four years. The reward started at 50 BTC per block; after the halvings of 2012, 2016, 2020 and 2024 it has fallen to 3.125 BTC. The next cut is expected around 2028. Because of this schedule Bitcoin's total supply is capped at 21 million coins, with the last coins issued around the year 2140, after which miners' rewards will consist of fees.

For a miner a halving means a sharp cut in coin income for the same hardware. The ones who stay are those whose equipment is efficient enough and whose electricity is cheap enough for the work to make sense at the new reward. You can see upcoming dates and the reward trajectory on the halving page. Litecoin follows the same principle of block search but uses a different algorithm (Scrypt) and its own reward-reduction schedule.

What happens when a block is found

  1. The device that found a valid hash sends the block to neighboring nodes.
  2. Nodes verify the hash, the difficulty, the validity of each transaction and the absence of double spending.
  3. If verification succeeds, the block propagates further and every node appends it to its chain.
  4. All miners immediately drop the old job and start on the next block, which references the one just found.

Sometimes two miners find a block almost at the same time. The network then splits temporarily: some nodes see one version, others see another. The conflict resolves itself: when the next block appears, the longer chain wins, and the losing block becomes "orphaned" and its reward disappears. That is why transactions are considered securely confirmed only after several blocks.

Where the pool fits in

The lottery described above is fair but far too rare for a small participant. A pool combines hashrate and, instead of blocks, pays you for shares, the "almost valid" hashes that prove you are doing real work. This gives regular earnings without waiting for your own luck. The roles of different network participants, including pools and industrial farms, are described in Who are miners. A general introduction for beginners is in What is mining.

FAQ

How long does one block take?

About ten minutes on average, but that is just the average. Some blocks appear within a minute, others take half an hour: the process is random.

What is a nonce in plain words?

A number the miner changes in the block header to produce different hashes. It is the only "knob" for trying variants until a suitable one turns up.

Why does mining difficulty keep growing?

Because total network power keeps growing. Difficulty adjusts so that blocks still arrive about every ten minutes regardless of how many miners there are.

What happens when all 21 million bitcoins are mined?

The subsidy ends and miners receive only transaction fees. On the current halving schedule that is not before the next century.

Why can't a suitable hash simply be computed faster?

Because of how hash functions work, a suitable nonce cannot be computed without trying values. The only way to speed up is more attempts per second, meaning more powerful and efficient hardware.