What is Bitcoin mining and how does it work?

Understanding the Bitcoin mining process for beginners

Everyone with some knowledge of Bitcoin knows that mining requires powerful computers to perform calculations to provide security to the network.

However, not many know what the actual process consists of and how it works from start to finish.

This article will explain how Bitcoins mining works from A to Z in its most basic terms.

Bitcoin basics: What is SHA-256?

Before we dive into mining, we have to understand how security in Bitcoin works.

Bitcoin uses a hashing function called SHA-256 to protect its blockchain. SHA-256 is an algorithm that converts an arbitrary data input of any length to a hexadecimal code of a fixed length —64 characters, to be precise. This 64-digit string of code is what we know as “hash.”

Bitcoin mining works hand in hand with the SHA-256 algorithm.

The SHA-256 algorithm will always return the same hash if you input the same data. However, if you change something as small as a capital letter, the hash obtained in return will change completely.

There’s no correlation whatsoever between the 64-digit code and the original message, so it’s virtually impossible to deduct the data introduced by knowing the hash without proper equipment.

Give it a try! Use this SHA-256 hashing simulator to see how you can encrypt data and how hashes change when you modify the input.

Bitcoin blocks and mining difficulty

Blockchains store data in small containers linked to each other called blocks —hence the name. These blocks are, in turn, linked to their predecessor, hence forming a “chain.”

Bitcoin blocks have a capacity of 1MB, which enables them to store two sets of information:

  • A handful of Bitcoin transactions.
  • The block’s metadata — called block header.

In turn, the block header contains:

  • The hash of the previous block, needed to link back to the chain.
  • The mining difficulty under which the block was found, a timestamp, and the block’s nonce (we’ll come back to this term later).
  • The merkle root — a data structure that summarizes all the transactions included in that block.

How are blocks recorded in the blockchain? Once miners compile all the information required to make their block valid, they must meet the network’s difficulty target.

Bitcoin adjusts its difficulty by setting a specific target for a new block’s hash. All new blocks need to have a hash equal to or less than the target set. To achieve that, hashes need to start with N amount of zeros.

0000000000000000000af8ea3aa782a1c74e91b45d306663c2145235b362904a —Hash of block #710859

The first miner to find a hash that meets these requirements gets to record the block and earn the reward. Now, let’s see how they can do that.

Bitcoin mining and how to “find blocks”

Let’s rewind a little: We started this article by explaining how the SHA-256 function returns a 64-digit string of code specific to a particular data input.

We’ve also seen how miners have to find a hash that meets the difficulty requirements of the network to create and record a block in the blockchain. Miners can do this by adding a particular number to the block: the nonce —or number only used once.

Bitcoin mining consists of performing millions of calculations to find a hash that meets the network's difficulty target.

Remember how even the slightest modification to the data input would make the SHA-256 function return a completely different hash? This is precisely what miners do to try to find a hash that meets the difficulty targets. And this is also the particular part of the process popularly referred to as mining.

By adding a random number —the nonce— to the block’s data, miners get a different hash for that block. They keep trying other nonces until the hash they obtain in return meets the difficulty targets.

The reason why miners are constantly trying to expand their hashrate is that the more of these “guesses” you can try per second, the more likely you are to be the one who finds it first, thus earning the reward.

Don’t forget that each block contains the previous block’s hash, so once a block is confirmed and added to the ledger, miners have to start again from scratch. That is also why miners race against each other to be the first to record a block.

Would you like to learn more about how miners earn money? Check out our article here: Understanding Bitcoin mining revenue

Bitcoin mining is very competitive, as miners race to be the first to find blocks and earn the rewards.

Final steps and considerations

After miners find a block, they transmit it —along with its valid hash and all the data— to validator nodes, who check that the block effectively meets the networks’ parameters.

Once nodes verify the block, they record it on the public ledger permanently. The process then starts again, with miners including other transactions in a new block.

Summing up, the Bitcoin mining process can be broken down into these steps:

  • Bitcoin establishes a difficulty target for new blocks’ hashes according to the network’s total hashrate.
  • Miners select the transactions and data they want to include in a block and start “guessing” by trying a different nonce until they come up with a valid hash.
  • After they “find the block,” they send it to validator nodes, who verify that it meets all the requirements and record it on the blockchain.

We hope this article was helpful and cleared some of your doubts about the very complex process that is Bitcoin mining.