How Does Bitcoin Mining Work on the Blockchain?

Mining is the process of adding blocks of Bitcoin transactions to the blockchain for consensus across every node on the Bitcoin Network which prevents fraudulent transactions.

In a distributed, peer-to-peer network miners ensure that all network participants have a consistent record of transactions and ownership to avoid double spending.

Bitcoin miners actually double hash network data through a cryptographic hash function called SHA-256 which takes a large chunk of transaction data and shrinks it into a 256 bit hash value.

Bitcoin Mining
Image by m@crovector

Approximately every 10 minutes a new block of transactions is mined through a computationally complex method called proof-of-work to immutably chain the block to all of the previous blocks on the blockchain.  

SHA-256 encryption makes mining easy to verify but difficult to execute.

The unbroken chain of blocks on the blockchain cannot be edited.  New blocks are added (amended) to the blockchain by successfully guessing (hashing) the candidate block’s transaction data to produce a hash value below a predefined value (target) which earns the miner a coinbase reward (not the exchange), called a block subsidy consisting of freshly minted Bitcoins. 

The Candidate Block is the ‘next block’ to be confirmed.  Miners are working hard to select unconfirmed transactions from the mempool to construct a valid block whose block header hashes to a number equal or less than the target.

Bitcoin Blocks

Each block on the Bitcoin Blockchain contains a standardized set of information for validation:

  • Magic Number: The 4-byte (8 char) field 0xD9B4BEF9 is the file format of the data structure for Bitcoin.  This number never changes.
  • Blocksize:  Another 4-byte field caps the amount of data that can be included in the block.  The maximum blocksize is 4 million weight units (WU, ~4 megabytes though the average blocksize is ~1.78 megabytes. 
  • Block Header: 80-byte field of six components we’ll review in the next section.
  • Transaction Counter: 1-9 byte field that displays the number of transactions in the block.
  • Transactions: The list of ALL transactions included in the block.  

Block Header

A block header summarizes the data in the block.  Blocks are layered on top of each other and referenced in ascending numerical order called block height on the blockchain. 

A block header is an 80-byte string of cryptographically verifiable data comprised of:

  • Version: 4-bytes
  • hashPrevBlock: 32-bytes
  • hashMerkleRoot: 32-bytes
  • Time (stamp): 4-bytes
  • Bits (difficulty target): 4-bytes
  • Nonce: 4-bytes 

Let’s look at an example Block 824191.

The block header for 824191 looks like this (fields are in table below):

0080b528bba4726c343e765c8b5050fc9819c958718f2553545e03000000000000000000e4332ab9387d9ff7812916388f11bc5b6f1de402192a2d65344da03e4a6cc9bb20959565b3e8031766de761c

These outputs can be complicated to read without a strong math background.  There’s a great summary of core block details on Bitcoin Developer.

FieldDescription
VersionVersion of the block which sounds insignificant but is crucial for soft forks.  
hashPrevBlock256-bit hash of the previously mined block which links blocks together.  
hashMerkleRoot256-bit hash of the Merkle Root of all transactions in the current block.
TimeThe Epoch timestamp (unix) of when the block is being hashed.
BitsBits are a condensed version of the target value (difficulty).
NonceThis 4-byte number used (once) to get the block hash of the block header.

The block header serves an important function in the mining process which consists of:

  • Version, timestamp, target and the latest block on the longest chain which took the most effort to build. Nodes always adopt the longest chain when faced with adopting a shorter chain as an alternative. 
  • Selecting unconfirmed transactions to be included in the candidate block.
  • Constructing the Coinbase (reward) transaction.
  • Creating a block message with the nonce and Merkle root of included transactions thus creating a full candidate block header.
  • Double verify the block header by hashing it twice with SHA256 and comparing the output with the network target. 

A hash is an alphanumeric code to represent encrypted data and secure information.  Transaction data run through a hash algorithm (aka – hash function) that produces a hash,  which is data output that cannot be reversed to discover the details of the inputs.  

If the block header hash is greater than the target, then the miner selects a new number for the nonce and proceeds with verification until the hash is below the target.  

Miners are competing against each other and whoever comes up with a valid hash wins the coinbase reward.  It’s an extremely competitive zero-sum race to win.  

When the block header hash is equal to or lesser than the target then a valid block is broadcast across the network by nodes for consensus.  

Each node adds the confirmed block to their blockchains because of the longest chain rule (measured by the ‘chainwork’ metric) and the miner earns a block reward plus Bitcoin network transaction fees.  You can also get the block header as long as you have the hash by using Chainquery’s tool.

What are Stale or Orphan Blocks?

Orphan blocks DO NOT have a parent block.  This happens when a node is made aware of a block before it receives notification that the parent block is confirmed.  

The orphan block then automatically moves to a staging area and the node waits for the parent.  This scenario was more common in the early days of Bitcoin, but modern nodes ignore downloading a full block if there is a missing parent block.  

Stale blocks are a more common occurrence.

Bitcoin nodes are pre-programmed to follow the best chain, also known as the longest chain.

The block height is an ascending number that refers to a specific block increasing by 1 each time a new block is added to the blockchain.  Miners work to assemble transactions into a new block and hash a number lower than the target every ~10 minutes.  When the block is completed, the number assigned to the block becomes the block height on the Bitcoin Blockchain.  

The longest chain has the most proof-of-work and nodes will use this while waiting to form consensus on which block will be accepted if two miners happen to simultaneously hash the target of two different blocks. 

The block NOT accepted, is referred to as a stale block.  

Pro Tip – When making a transaction, the general rule of thumb is to wait for at least 6 confirmations before your transaction can be considered completed and not orphaned.  

On to the next one.

How does mining work?

The block chain is a file of every confirmed transaction, like a ledger, which is maintained by each node on the Bitcoin Network and gets updates every ~10 minutes when a new block is mined.

Each new block is linked cryptographically to the previous block which, in turn, links with every block since Bitcoins first (Genesis) block mined by Satoshi on January 3, 2009.

We know that running a full node contributes to the overall health of the network.  Nodes are computers called Bitcoin clients connected on the network.  Nodes communicate with each other by running the exact same open source Bitcoin Core software.  

Nodes share information about new transactions and store these unconfirmed transactions in the memory pool.  

A Mining Node creates a Merkle root (cryptographic string of letters and numbers) which acts like a fingerprint to represent all of the unconfirmed transactions in the mempool which are included in the block they are mining. 

Merkle roots are an efficient way to take thousands of transactions in a block and compress the data similar to zipping a large file on your computer.  It’s a hash of all the hashes of all of the transactions. 

  1. Hashing the mempool creates an output looks like this: 

34XC8GbijKCCvppNvhw4Ra8QZdWsg8tC11

  1. The Merkle root is combined with a random 3-byte number called a nonce, and run through a Secure Hash Algorithm 256-bit* (SHA-256).
Merkle RootNonce
34XC8GbijKCCvppNvhw4Ra8QZdWsg8tC113271

*SHA-256 processes data in the following order: conversion to binary > creates hash values > initializes a constant > chunking data to bits > create a message schedule > process a compression loop > then modifying the final output values which will be the same length regardless of how big/small the input value are.  

  1. The output is a string of letters and numbers called a block hash (hash value).  The block hash must be equal to or less than the target (target hash) in order for the new block to be mined.  The target hash is a numeric value between 0 to 256 bits.

More on Bitcoin mining targets below…

What is the Bitcoin Mining Target?

The Bitcoin target  The target is a numeric value that begins with a certain number of zeros (0000…) determined by the difficulty adjustment.  

Miners generate hexadecimal hashes that look like this:

00000000000802da89fe958bed2101e56eff8542e94a36ba8f537e9679001000

Hexadecimal numbers can be converted into decimal numbers.  The Bitcoin network places a high value on the size of data being processed. Decimal numbers are larger than hexadecimal numbers which is why the target is a hexadecimal number.  

The goal is to generate a hash value below the target which can be calculated like this:

Target = targetmax / difficulty (expressed in decimal, but easily converted to hexadecimal)

Looking at the Block Header we see the different number formats AND the target is presented as a truncated number (little-endian) in the bits description and may require conversion to hexadecimal. Check out our technical post if you want to decode a Bitcoin transaction.

What is Bitcoin Mining Difficulty?

Bitcoin mining difficulty is a value that determines how many hashes (guesses) are estimated to solve the current block.  

On February 26, 2024 the current Bitcoin Difficulty is 81.73 T (81,725,299,822,043.00) at block 832,144.  

Satoshi planned for each block being mined in 10 minutes (block time target) having a preference for adding new blocks of transactions at regular intervals. 

Every 2,016 blocks mined (~2 weeks), nodes compute the actual time each block took to hash compared with the expected time of 20,160 minutes (10 x 2,016) to determine if these blocks were mined faster or slower than the 10 minute goal per block.  

If a bunch of new miners entered the network and collectively managed to mine a block in an average of 9 minutes then this is what our calculation looks like:

Based on our chart above, the Bitcoin mining network is averaging 9.92 minutes per block which is 0.08 minutes quicker than the Block Time Target (expected of 10 minutes).  

Block Time Target / Actual Time

20,160 (10 x 2,016) / ‘block time’ (avg or actual x 2,016)

20,160 / 19,998.72 = 1.008

  • If this calculation is greater than 1, then Difficulty Increases as the blocks are mined faster than 10 minutes.
  • If this calculation is less than 1, then Difficulty Decreases as the blocks are being mined slower than expected.  (this usually happens if miners unplug during bear market for example)

Our example estimates that difficulty will increase by 0.84% from 72.01 T to 72.61 T in 280 blocks which will initiate the next adjustment on the completion of 2,016 blocks.

Fast forward 30 days later (Feb. 2, 2024), mining difficulty increased by 7.33% reaching a new ATH of 75.50 T with an average hashrate of 540.27 EH/s.  

The Bitcoin network is dominated by a few major mining pools, Foundry USA (32%) and Antpool, who collectively control over 60% of the total hashrate. 

This is a bullish signal that competition is UP for miners who secure a resilient and growing network. 

What is a Bitcoin Hash Function?

A hash function is an algorithm that maps an Input Value (x) to an Output Value (y).

The (x) data value can be any size but always creates a fixed size (y) output value.  

The output value is called a hash, and the fixed size is called the hash length.  

For example, Bitcoin uses a SHA-256 hash function which always returns a 256 bit hash length output value.  Bits are 1s and 0s.  SHA-256 produces a string of 256 1s and 0s which are represented by a 64-character hexadecimal number for more efficient computation.

Still with me? 

Hash Functions are deterministic, meaning an input (x) always produces the same Hash (x).

The cryptographic properties of hash functions are:

  • Collision Resistant: infeasible, not impossible, to discover (x) and (y) data values by comparing Hash (x) = Hash (y).
  • Preimage Resistant: infeasible to to determine (x) value from Hash (x).
    • For example, if you’re given the value for (y), you can’t find (x) where the hashed output of ‘x’ or hash(x) == (y)
  • Avalanche Effect: Even a slight change to the input (x) value significantly changes the Hash (x) so there is no way to find a correlation between the input and output.
  • Puzzle friendliness: even if you know a little bit of the input (x), the probability of discovering the whole (x) value is still infeasible.

If the SHA-256 algorithm is ever cracked, which is highly unlikely without a quantum computing breakthrough, Bitcoin could quickly (or gradually) transition to a better hash function while preserving the previous ‘honest’ blocks on the blockchain by re-hashing everything.

Remember that by design, Bitcoin hashes data twice (SHA256^2 or ‘SHA256 function squared’) to make the data even more secure.  The first Hash (x) of input (x) is then hashed again to produce a Hash (y) with no correlation to the previous input or output values.  

Hash functions produce hashes which have many applications to keep Bitcoin secure.  

What is Bitcoin Hashrate?

Hashrate estimates the number of hashes generated by miners to complete a block on the Bitcoin blockchain. 

Hashrate is calculated using the current difficulty, target block time (10 mins), and the average block time of recent blocks.  

Hashrate is constantly changing KPI that acts like a proxy for security and network health. 

On January 4, 2024 the Bitcoin Hashrate was 583.15 EH/s down 17% from 695.09 EH/s All Time High (ATH) set 4 days earlier on December 31, 2023.

(click to tweet) The All Time High hashrate of 695.09 EH/s (ExaHash per second) is 695 Quintillion hashes every second and looks like this: 695,000,000,000,000,000,000 H/s (Hashes per second) 🤯

If you’re serious about getting into mining or just looking to go further down the Bitcoin rabbit hole check out this mining calculator and the “getnetworkhashps” command on your node.

h2What is Hash Power?

To a Bitcoin miner, a hash (hash value or block hash) is a numerical guess whose value MUST be equal to or less than the target hash.  

When more Bitcoin miners enter the network the result is more hashing powerMore hashing power increases the number of hashes (guesses) which statistically ensures that blocks will be solved quicker than 10 minutes requiring a difficulty adjustment

Miners are constantly changing the input values fed into the hashing function to produce a hash below the target.  Some of the variable inputs that can be used are: nonce, timestamp, or coinbase transaction. 

Trying to mine bitcoin as a solo-venture can be cost prohibitive, so many miners enter mining pools.  A mining pool is a collective group of miners who share their work (partial solution) and their rewards in fractions of bitcoin

If a new block is mined outside of the pool, the pool operator sends out new data using a protocol, like Stratum, and the pool begins working on a new block trying to avoid duplicating work to increase efficiency.

Bitcoin Mining Energy Consumption

All of this proof-of-work consensus model requires significant electricity consumption to power the ASIC mining machines.  It’s estimated the Bitcoin Network consumes 0.74% of the world’s electricity while producing 0.25% of the global electricity by transforming energy sources (ie hydro).  

Bitcoin mining consumes an estimated 161.93 Twh per year, compared to Gold mining consuming 131 Twh of electricity (copper mining 167 Twh).  To put this in context, Bitcoin mining consumes as much electricity as televisions (60 Twh) and refrigerators (104 Twh) in the US.   

Government regulations in 2024 are setting the table for oversight and potential overreach. 

For example, the US Energy Information Administration (an “independent”) sub-agency of the Department of Energy is requiring miners to report on energy consumption but the order is being challenged as illegal in court.  

Political pressure from Buttcoiners like Sen. Warren spurred the Department of Energy and Environmental Protection Agency to take action.

At the same time, the European Commission (ESMA & ECB) issued a report that could pave the way for a regional ban on mining.

China imposed a mining ban in 2021, but the country still accounts for ~21% of the global hash rate distribution. 

Only time will tell what the impacts on mining in the US and EU have on Bitcoin.

Fun Fact – The first blockchain was NOT created by Satoshi Nakamoto.  Stuart Haber and Scott Stornetta created the first public blockchain in 1991.

Satoshi’s Bitcoin Whitepaper includes eight (8) external citations and three (3 of 8) citations reference Haber’s work.  

The pair went on to start a cryptographic security company called Surety and are credited with maintaining the longest running blockchain.   

Every week since 1995, Surety publishes a summary Hash (y) (hash value) of their internal records in the New York Times ‘Notices’ (Classifieds) section.  This cryptographic ‘fingerprint’ of private data is a ‘widely witnessed’ validation of electronic records that remain immutable and publicly verifiable just like the Bitcoin Blockchain. 

The Blockchain has been around for a while and isn’t going anywhere. Good luck out there!

Note: Stratus does NOT provide investment, legal or tax advice.  All information in this article is for educational purposes and should not be interpreted as investment, legal or tax advice.  The opinions expressed are those of the author for informational purposes and neither Stratus nor the author are liable for any errors, inaccuracies or omissions.  Digital assets, such as cryptocurrencies or decentralized finance, present unique risks for investors.  For investment, legal, tax, or other financial guidance you should consult your own advisor.