Bitcoin
15 min

How Does Bitcoin Mining Work? SHA-256, Nonces & Proof of Work Explained

Published
· Updated

What Is Bitcoin Mining?

Bitcoin mining is the process by which new bitcoins are created and transactions are verified and added to the blockchain. It's a competitive process where miners race to solve a cryptographic puzzle using their computational power.

The Mining Process Step by Step

1. Collect Transactions

Miners gather unconfirmed transactions from the mempool — a waiting area for transactions that haven't been included in a block yet.

2. Build a Candidate Block

The miner constructs a block header containing:

  • Version number
  • Previous block's hash
  • Merkle root (hash of all transactions)
  • Timestamp
  • Difficulty target (how hard the puzzle is)
  • Nonce (a number the miner can change)

3. Hash the Block Header

The miner runs the block header through SHA-256 twice (double hashing) to produce a 256-bit hash.

4. Check Against the Target

If the resulting hash is below the difficulty target, the block is valid! If not, the miner increments the nonce and tries again. This is why it's called "Proof of Work" — you must demonstrate that computational effort was expended.

5. Broadcast the Block

Once a valid hash is found, the miner broadcasts the new block to the network. Other nodes verify it and add it to their chain.

Understanding SHA-256

SHA-256 (Secure Hash Algorithm 256-bit) is the hash function used in Bitcoin mining. Key properties:

  • Deterministic: Same input always produces the same hash
  • Fast computation: Computing a hash takes microseconds
  • Avalanche effect: A tiny input change produces a completely different hash
  • Pre-image resistance: You can't reverse-engineer the input from the hash
  • Collision resistance: It's practically impossible to find two inputs with the same hash

Example

Input: "Hello"
SHA-256: 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969

Input: "Hello!"  (added one character)
SHA-256: 334d016f755cd6dc58c53a86e183882f8ec14f52fb05345887c8a5edd42c87b7

Notice how adding just "!" completely changes the hash. There's no way to predict what the new hash will be without computing it.

Mining Difficulty & Target

The difficulty target determines how hard it is to find a valid block. The target is a 256-bit number. A valid block hash must be numerically less than the target.

How Difficulty Adjusts

Every 2,016 blocks (approximately 2 weeks), Bitcoin automatically adjusts the difficulty:

  • If blocks were found too quickly → difficulty increases (target gets smaller)
  • If blocks were found too slowly → difficulty decreases (target gets larger)

This ensures blocks are found approximately every 10 minutes on average, regardless of how much mining power joins or leaves the network.

Block Rewards & Bitcoin Economics

When a miner successfully mines a block, they receive:

  1. Block subsidy: Currently 3.125 BTC (after the 2024 halving)
  2. Transaction fees: Sum of all fees from transactions in the block

The Halving

The block subsidy is cut in half every 210,000 blocks (~4 years):

  • 2009: 50 BTC per block
  • 2012: 25 BTC
  • 2016: 12.5 BTC
  • 2020: 6.25 BTC
  • 2024: 3.125 BTC

This creates Bitcoin's famous 21 million supply cap.

Hash Rate & Mining Power

Hash rate measures how many hashes a miner can compute per second.

  • 1 MH/s = 1 million hashes/second
  • 1 GH/s = 1 billion hashes/second
  • 1 TH/s = 1 trillion hashes/second

The total Bitcoin network hash rate exceeds 700 EH/s (700 quintillion hashes per second), making it the most powerful computing network on Earth.

Why Mining Matters for Security

Mining isn't just about creating new bitcoins. It's the security mechanism that makes Bitcoin virtually impossible to attack:

  • To reverse a transaction, an attacker would need more than 51% of the network's hash rate
  • The cost of such an attack would be billions of dollars in hardware and electricity
  • The economic incentives ensure miners are better off playing by the rules

Try Mining Yourself

On ZeroToBlock you can experience mining firsthand through our interactive simulator inside the Bitcoin Proof of Work course. Watch as you search for nonces, see hashes change, and find valid blocks — all in your browser. New to Bitcoin? Begin with the Bitcoin 101 course for the foundations.

Ready to Learn By Doing?

Stop reading. Start building. Our interactive simulations teach you blockchain mechanics through hands-on experience.

Explore Courses