Mining and Network Security

How Bitcoin Mining Works From Hashing to Block Rewards

A conceptual walkthrough of proof of work mining: transactions, hashing, difficulty targets, block rewards, fees and why the process secures the Bitcoin network.

On this page
  1. What miners are for
  2. Step 1: collecting transactions
  3. Step 2: hashing
  4. Step 3: the search for a valid hash
  5. Step 4: broadcasting and agreement
  6. Step 5: rewards and fees
  7. Keeping the pace steady
  8. Hardware, costs and scale
  9. Why this secures the network
  10. What mining does not do

What miners are for

Bitcoin has no central operator who decides which transactions are valid or in what order they happened. Instead, thousands of independent computers keep copies of a shared ledger, and a process called mining decides who gets to add the next page of that ledger, known as a block. Mining does two jobs at once: it orders transactions in a way that is expensive to rewrite, and it releases new bitcoin into circulation on a fixed schedule.

This article describes the process at a conceptual level. Details such as exact data layouts are left out on purpose.

Step 1: collecting transactions

When someone sends bitcoin, their wallet broadcasts a transaction to the network. Nodes check it against the rules: the coins must exist, must not already be spent, and must be authorised by a valid digital signature. Valid transactions wait in a holding area on each node, often called the mempool. When demand for block space is high, transactions offering higher fees tend to be picked first, which is the reason mempool congestion can make transfers slower or costlier.

A miner (or the pool it belongs to) selects a set of waiting transactions that fits within the block size limits and assembles them into a candidate block. The first entry in that block is a special transaction, often called the coinbase transaction, which pays the miner the block reward plus the fees from the included transactions.

Step 2: hashing

A hash function takes any input and produces a fixed-size output that looks random. Bitcoin uses SHA-256, applied twice, on a summary of the candidate block called the block header. The header includes a reference to the previous block, a fingerprint of the chosen transactions, a timestamp, the current difficulty setting and a number called the nonce.

Two properties matter. Changing even one character of the input completely changes the output, and there is no known shortcut to work backwards from an output to an input. The only practical way to get a particular kind of output is to try many inputs.

Step 3: the search for a valid hash

The network defines a target number. A block is valid only if the hash of its header, read as a number, is below that target. Because outputs look random, the chance that any single attempt succeeds is simply the target divided by the full range of possible outputs. That chance is tiny, so miners change the nonce, hash again, and repeat, trillions of times per second across the whole network. When the nonce runs out of useful values, miners also vary other parts of the block, such as the coinbase data.

This is the proof of work. Finding a valid hash is costly in electricity and equipment, but checking it takes a single hash calculation. Every node can therefore verify in an instant that a block really did require a lot of effort.

A useful comparison is rolling dice until you get a result below some threshold. Nobody can predict which roll will succeed, and rolling faster raises your chance of being first. That is why miners who control a bigger share of total computing power find a proportionally bigger share of blocks over time, although any single block is still a matter of luck.

Step 4: broadcasting and agreement

The miner who finds a valid header broadcasts the block. Other nodes check every transaction and the hash, and if all is well they add the block to their copy of the chain and start building on top of it. Miners then move on to the next block, using the new block as their starting point.

Occasionally two miners find blocks at nearly the same moment, and the network briefly has two competing tips. Nodes follow the chain with the most accumulated work, and the tie is usually resolved when the next block arrives on one branch. The abandoned block is called stale or orphaned, and its transactions return to the waiting pool. This is one reason people often wait for several confirmations before treating a payment as final; the longer a block is buried under later blocks, the more work would be needed to replace it.

Step 5: rewards and fees

The block reward started at 50 bitcoin in 2009 and is cut in half every 210,000 blocks, roughly every four years. That scheduled cut is covered in detail in the explanation of halving mechanics. Combined with the rule that the reward keeps shrinking, it produces the fixed supply cap of 21 million coins. Over time, transaction fee revenue is expected to make up a larger part of what miners earn, though how that will play out is uncertain.

Newly created coins in the coinbase transaction cannot be spent until 100 more blocks have been added, which protects against rewards disappearing if a block is later orphaned.

Keeping the pace steady

If more computers join, blocks would be found faster. To prevent that, the network adjusts the target periodically so that blocks arrive on average about every ten minutes. This mechanism is the subject of its own article on the difficulty adjustment. The average is only a target: individual gaps between blocks vary a lot, from seconds to over an hour.

Hardware, costs and scale

Early on, people mined with ordinary computers. Today the work is done mainly by specialised chips called ASICs, built to do one thing, which is compute SHA-256 quickly with little energy. Miners face equipment costs, electricity bills, cooling and hosting. Many join groups that share rewards, a practice covered in the explanation of mining pools. The total computing power devoted to the network is usually discussed as its hash rate.

Why this secures the network

To rewrite history, an attacker would need to redo the work for the block they want to change and for every block after it, while the honest network keeps moving forward. The more work stacked on top of a transaction, the more expensive that becomes. Mining rewards pay for this security: honest miners are paid in new coins and fees, while an attacker would have to spend heavily with no guarantee of success. How realistic a majority attack is on a large chain is looked at separately.

What mining does not do

Mining does not set the price of bitcoin, and it does not decide the rules; node operators and users enforce those. The link between miner economics and the market is indirect and often overstated. Prices of cryptocurrencies are volatile, past behaviour does not predict future results, and people can lose everything they put in. Nothing here is financial, tax or legal advice.

Keep exploring

Guides from other topics

All topics →