How Mining Works in Bitcoin & Cryptocurrency

Last Updated September 4, 2018
Posted By Luke      No Comments

To fully understand how blockchain works, you need to understand how mining works.

Mining is one of the most technically complex aspects of the cryptocurrency world.

We’re going to try to simplify things in a way that everyone can understand. This means that we’ll be leaving out some of the extremely technical information in an attempt to cover the basics in a universally understandable way.

We’re going to talk in-depth specifically about how bitcoin mining works.

Different cryptocurrencies and different blockchains have slightly different mining processes.

We’ll talk a little about those different methods of mining at the end of this post, but first, we’ll start with the biggest mining ecosystem in the world today.

And here’s something important to know:

If you walk away from this post and still don’t understand mining…

…that’s fine.

You do not need to understand mining to be active in bitcoin and cryptocurrency, just like you don’t need to understand the technical complexities behind how the internet works whilst in order to read this post.

How Bitcoin Mining Works

Bitcoin mining works by having miners — these are powerful computer rigs, not individuals sat working ferociously at their desks with a pick axe — that solve complex mathematical equations to verify transactions.

Known as cryptographic puzzles, these complex mathematics are used to create a trustless system — a seller doesn’t need to know a buyer, miners don’t need to know either party. All the parties need to know is that one can afford to pay the other, and that the transaction has gone through successfully.

Trust between parties is automatically generated, but also doesn’t exist at all — depending on which way you want to look at things.

Once a cryptographic puzzle is solved, the transactions in the block are checked and verified by a number of other miners before being confirmed as ‘the truth’.

This might sound complicated (and when you dig into the technicalities, it is extremely complex) but to get a basic understanding, things aren’t so difficult.

Let’s look at an example:

Let’s say that I was going to send you some bitcoin.

To send you 3 bitcoin, or 3 BTC, all I need to do is send it from my bitcoin wallet to your bitcoin wallet address — imagine this to be almost like an email address, but instead of a traditional email like yourname@yourbitcoinwallet.com, it’s a long string of letters and numbers that is automatically generated.

An example address would look like this:

19Ygxb78AXGpqXJcra1cREAbymN3aUdWTE

Interesting fact: there are more potential bitcoin wallet addresses than there are grains of sand on earth. In fact, if there was another planet earth for every grain of sand, there’d still be more potential addresses than sand grains across all 7,500,000,000,000,000,000 geographically identical versions of this planet!

So, if you want me to send you 3 BTC (yes, we’re still on the example here!) you generate a wallet address (if you haven’t already done so previously) which can be done at the click of a button on a website like Coinbase, and then you send your address to me.

I copy your address and then click send.

Approximately 10 minutes later, although it can sometimes take up to an hour, the money should be in your wallet and ready to be spent.

That transfer of bitcoin is all we see, but behind the scenes there is a whole world of complex verification processes (i.e. mining) taking place.

Let’s now look at the example again, but with a more detailed look at the mining process taken into account too:

First, I send 3 BTC to your address, exactly the same way as described above.

The first step in the mining process is to take an ‘input’, which in this case is our transaction, and run it through something called a ‘hash function’.

 

Hash Functions

How hash functions work

Hash functions, and hashes in general, were loved by Satoshi Nakamoto, Bitcoin’s founder, and they account for a great deal in how bitcoin’s blockchain works so successfully.

When an input — which in this case is our transaction — is run through a hash function, it cryptographically encrypts (protects and hides) it.

Instead of the public ledger saying that I am sending 3 BTC to you, it will instead say that someone sent 3 BTC to someone else. Both of us will be represented in the ledger as another long string of letters and numbers — our public wallet addresses.

An example of a hash looks a little something like this:

185F8DB32271FE25F561A6FC938B2E2…

That string of gibberish above is an SHA265 hash of the word ‘Hello’. That means ‘Hello’ is our input, and the hash is what we get as a result.

SHA265 is the hash function that Bitcoin uses — it was designed by the NSA.

If we change the letter ‘H’ from uppercase to lowercase in our input, so it becomes ‘hello’, the resulting hash is changed entirely:

2CF24DBA5FB0A30E26E83B2AC5B9E29…

The two strings are incomparable despite such a subtle difference.

If we were to go with ‘Hello.’ — adding just one character of punctuation — it again changes almost in its entirety:

2D8BD7D9BB5F85BA643F0110D50CB50… 

You’ll find out why this level of encryption is so important in a little while…

 

Ownership of Funds (Unspent Transactions)

Let’s get back to the transfer of my bitcoin:

Miners run something called nodes.

Nodes check the digital signature of our transaction to ensure that I am the rightful owner of the funds I am attempting to send to you.

By using digital signatures, miners will never need to see any of your balances in order to verify that you can (or can’t) afford to send funds.

To ensure that I can afford to send 3 BTC to you, ownership of funds is proven via links to all of my previous transactions on the blockchain. Yes, that’s every transaction ever made since the blockchain began.

To make things significantly more efficient, nodes only need to search for unspent transactions.

The idea of unspent transactions is essential to the way bitcoin works for the following reason:

Each of your previous transactions can only be used as an input once, ever.

So, if Dave sent me 5 BTC a year ago and that’s the only bitcoin I’ve ever been sent, the nodes (and miners) use that transaction as the input for our transaction, in order to prove that I can afford to send you 3 BTC.

However, I would then technically be unable to send my remaining 2 bitcoin anywhere else — because my one and only unspent transaction has been used up. To avoid this issue, the system will automatically resend my remaining 2 bitcoin back to myself.

There is then proof on the blockchain that I have 2 unspent bitcoin remaining and that it can be used as the input for future transactions.

Miners don’t ever need to know (and are unable to know) if I have 5 bitcoin or 5,000 bitcoin in my balance, all they need to be able to see is that I’ve previously been sent at least 3 bitcoin and have not yet spent it, and can therefore afford to send it to you.

This fact is checked and confirmed by multiple miners before the transfer of the funds can be completed.

Whilst all of this is going on, our transaction, along with all other new transactions, will be grouped together by miners. It’s then suggested to the rest of the mining community that this new group of transactions should form the next block on the blockchain. Remember, all of this is done automatically by mining software.

There is then a race to solve the cryptographic puzzle on the suggested new block.

When the puzzle is solved, it is broadcast to all other miners and the block is added as the next in the chain. On average, this happens every ten minutes.

When the block with our transaction inside is added to the blockchain, you will see your 3 BTC showing your pending balance.

After our transaction has been confirmed by enough miners, you’ll be able to spend your new funds.

 

Merkle Trees

When the puzzle of a block is solved, the hash of every transaction in the block is run through something called a merkle tree.

A merkle tree combines hashes in pairs and runs them back through the hash function, so that each pair now has only one hash.

It keeps recombining the new hashes into pairs until it is left with just a single hash for the block. This is known as the ‘root hash’; the hash of all the hashes.

This diagram should explain that process a little more clearly:

How merkle trees work

The above might all sound a little confusing, but it’s important to know why the root hash is so incredibly crucial to the way the bitcoin blockchain works:

As we saw with the ‘Hello’ and ‘hello’ hash examples a little earlier, even the slightest change to information will result in a totally — and noticeably — different hash.

If I ever tried to go back and reverse my transfer of bitcoin to you at a later date, or if someone tried to hack our transaction for whatever reason, it would change the hash of our transaction and therefore the root hash — also known as the merkle root — of the block too.

Every new block refers to the hash of the previous block.

If the tiniest piece of information were to be changed, all of the newer blocks would no longer refer to the correct hash.

If someone were to attempt to change something within a transaction, the entire block (and every block that came after it) would need to be re-mined.

This is an impossibility, as the mining software would instantly realise that the hashes for the blocks were incorrect, and simply reject it.

 

Mining Game Theory

Hopefully you’ve not got too much of a headache from the explanation above!

If you have, we’re sorry — let’s lighten the mood by looking at the game theory behind mining.

Bitcoin mining

Game theory is pivotal to the upkeep and maintaining of the blockchain.

The basic aim of the game is simple:

The miner that calculates the cryptographic hash function in the quickest possible time gets the financial reward for that block.

When bitcoin was first invented, the reward for solving the puzzle on every block was 50 BTC (which is now worth over £250,000!).

The reward for solving blocks is halved every 210,000 blocks — remember, there are only 6 blocks an hour on average. This means the prize for solving the cryptographic hash drops approximately every 4 years.

This dropped to 25 BTC in late 2012.

Currently, the reward is at 12.5 BTC. This will drop to 6.25 BTC per block around June 2020.

By releasing fewer bitcoin into the marketplace, it leads to deflation. Bitcoin increases in value as a finite resource — only 21,000,000 will ever exist.

This is in completely contrast to regular fiat currencies (such as pounds, dollars and euros) that suffer from inflation and decreases in value — the average price of a house in the UK was worth just £2,530 in 1960. Nowadays, the cost is almost one hundred times that amount, but it is not necessarily because houses are worth more — just that your money is worth less.

Because bitcoin is in limited supply, it means that the race to mine them — and therefore support the whole infrastructure of the blockchain — is hotter than ever.

The rewards are greater than they ever will be again.

This means more people get involved in mining.

More people upgrade their computer equipment to mine more efficiently.

Solving a block is not easy. In fact, the chances of ever solving one on your own, with a regular computer, are extremely slim indeed. This leads people to join mining pools to combine their processing power; each person taking a smaller piece of the reward if a block is solved, but getting the rewards more frequently.

Whilst the puzzles are solved automatically by mining computers that continually and quickly attempt to figure out the answer, they are impossible to predict in advance, or even guess by chance when they do arrive.

On average, it takes 100,000,000 gigahash attempts from the mining community to solve a block. A gigahash is 1,000,000,000 (one billion) hashes.

That means a block is solved roughly every 100,000,000,000,000,000 hashes.

And remember, this only takes the community ten minutes.

Once the first miner (or mining pool) solves the puzzle and claims the block reward, a number of other miners then verify that the puzzle has been solved correctly.

Like with a sudoku, solving it can be tricky and time consuming, but getting someone to check to see if a completed puzzle is correct is far quicker.

But miners are not just puzzle solvers and prize collectors. 

Far from it.

And this is what makes the game theory behind bitcoin so fascinating.

Miners are the entire lifeblood of the whole bitcoin ecosystem.

 

51% Attacks

If a miner, or mining pool, manages to get 51% or more of the computing power of the entire blockchain, this is the only way that they could potentially hack the network or take it down.

In 2015, The Economist wrote that Bitcoin miners had the power of the world’s 500 biggest supercomputers…multiplied by 13,000. Estimates on that number would be significantly higher today.

Even you could become a miner if you wished.

So, what we’re trying to say here is…it’s extremely unlikely that a party could get hold of 51% or more.

But even if they did…

The game theory behind the blockchain means that even if someone gained 99% of the entire blockchain’s hash power, it would be far more rewarding for them to simply mine and be rewarded with the block prizes on an extremely regular basis.

A 51% attack is theoretically possible, but realistically (and economically) improbable.

Before we move on to discussing how other blockchains operate, let’s quickly highlight the benefits that mining brings us…

 

The Benefits of Mining

  • Decentralised; no party controls it or can make decisions that the majority don’t like; untrustworthy sources can’t edit or remove information
  • Private; anonymity means that prying eyes can’t see or sell our personal information to advertisers or fraudsters
  • Fast; although transfers aren’t yet instant like they would be with Visa or PayPal, it’s still much faster for many people that can’t afford a bank account (such as those in third world countries)
  • Borderless; we aren’t hit by unnecessary (and extortionately high) fees to send money across the world
  • Incentivised; upkeep of the blockchain is a permanent inevitability. There would be no reason (other than the destruction of the entire planet) that would stop 100% of miners from mining, due to the rewards for staying put
  • Fairness; power is much more equally distributed, meaning there’s significantly less likelihood of dictatorships

 

Other Types of Mining

We aren’t going to dive into insane details again here, but it’s important we take a quick look at some of the mining methods that other blockchains are using.

The bitcoin blockchain puzzle-solving approach is known as ‘proof-of-work’.

Ethereum, the second largest cryptocurrency, also uses proof-of-work (though not with SHA256).

There are many different benefits and drawbacks to each type of ‘proof’ system, but the main downside with proof-of-work is, along with the threat of 51% attacks if someone obtained enormous computer power, regular people are unable to compete to solve blocks with the processing power that is possible from the huge mining warehouses that are run in China.

Alternatives to proof-of-work include:

 

Proof-of-Stake

With proof-of-stake, the creator of the next block is chosen based on a mix of random selection, how long a miner has been mining and how much wealth they have.

Whilst this makes it tougher for new miners to earn rewards, it means that they’re much more incentivised to stay long-term once they are established.

There is no block reward with proof-of-stake, just transaction fees that are collected by miners.

Because proof-of-stake requires miners to have significant holdings in a cryptocurrency, it makes them much less likely to try to attack the blockchain. By doing so, they’d be attacking their own wealth.

Ethereum is actually moving from a 100% proof-of-work system to one that switches to proof-of-stake once in every one hundred blocks.

It is estimated that proof-of-stake could be up to several thousand times more cost-effective than proof-of-work.

 

Proof-of-Importance

The two methods above are the most popular in cryptocurrency, and there is hot debate about which of the two should be favoured, but there are other methods too.

These include proof-of-importance and proof-of-stake-velocity.

Proof-of-importance is used by a blockchain called NEM, and proof-of-stake-velocity was pioneered by Reddcoin.

We won’t go into detail about these in this post.

That’s enough knowledge for one day!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

*