What is mining in Bitcoin?

“Mining” is the process of confirming transactions and adding them to the blockchain.

Nodes that participate in mining are known as miners and form a critical part of the Bitcoin network. As part of the mining process, new bitcoins are created, which are “paid” to miners.

A nice way to better understand mining is to first see how BItcoin would work if it did NOT have mining.

Here’s how it’d work.

Let’s say this is a file.

File called a blockchain

It is stored on a computer.

Think of this file kind of like a Word doc.

And let’s call this file, the “blockchain“.

A blockchain is a distributed ledger of “blocks”.

I’ll dive deeper into blockchain in a later lesson, but for now, just know that each block contains a bundle of transactions.

Now imagine this is the Bitcoin Network.

Imagine this is the Bitcoin Network.

These are all computers, connected together across the internet, and they’re running the Bitcoin software.

They’re all sharing a copy of the same file, which is the blockchain.

If you want to send a bitcoin to someone, or transfer ownership of a bitcoin to someone else, you would initiate a transaction.

Bitcoin Mining: Send Bitcoin

The transaction is just a line of data (in purple).

Bitcoin transaction is a line of data

When you initiate a transaction, it gets sent to a node of the Bitcoin network.

Bitcon transaction gets sent to a node

If Bitcoin did NOT have mining, the way this would work is that this computer would record the transaction straight to the blockchain, the shared file.

Bitcoin transaction written straight to blockchain

Then the computer would pass on that transaction to the other nodes it is connected to and they will write the transaction data to their own file.

Those nodes would pass the transaction to every node they’re connected to and would also write the transaction data to their own file.

And so on….
Bitcoin nodes record transaction directly into their blockchain

This would continue until the transaction has propagated the ENTIRE Bitcoin network.

And every node has written it to their file.

So that’s a simple way of having a shared file or a shared “ledger” of transactions or a “distributed ledger”.

Bitcoin ansaction has propagated the entire network

Notice how ALL computers now have the purple line (transaction) stored on their file (blockchain).

When all the nodes have updated their copy of the file, the ownership of the bitcoin will have changed from one person to the next person.

All Bitcoin nodes have updated their copy of the file.

And that’s an example of a simple Bitcoin transaction. Congratulations!

But we have a problem…

There’s a problem that needs to be solved if we were to do it this way.

Let’s say you want to sell your bitcoin to this purple dude.

So you create a transaction to send bitcoin to the purple dude.

Send bitcoi to purple dude

Then you send this transaction to the node on this side of the Bitcoin network.

Send Bitcoin transaction to the node on this side of the network.

But let’s say you’re the shady type, and since you can’t help it, you try to do something shady.

Because it’s a network of connected computers, you create a SECOND transaction that sends the SAME bitcoin to a different person like this red dude (on the right side).

Send same bitcoin to red dude

Then you send this transaction with the red dude into another node on the network.

WTF?!

You’ve just inserted TWO separate transactions into the network that involves trying to spend the SAME bitcoin!

You can do this because it’s a network of computers located in different places all over the world.

What a sneaky jerk. Congratulations! You are shady as hell!

Send Bitcoin transaction to another node in network

So what will happen from here is that these two transactions will start propagating across the network.

Some nodes will receive the purple transaction. Other nodes will receive the red transaction.

Different bitcoin transactions propogate network

In the illustration below, when a computer tries to pass on its red transaction, this computer has already received the purple transaction spending this bitcoin so it would reject it

Which is good, but here lies the problem…

Bitcoin node rejects transaction
Now you have two CONFLICTING transactions on the network.

Remember, every computer on the network needs to share the SAME EXACT file.

Some computers can’t hold a file with the purple transaction, while others hold a file with the red transaction. They all have to pick one.

ALL computers have to pick the red transaction OR the purple transaction.

If Bitcoin were to operate this way where transactions are written directly to the file, you would create this DOUBLE SPEND problem.

Conflicting transactions on Bitcoin network

Bitcoin solves this problem!

If you’re interested in a video format of this topic, check out this excelent YouTube video from Learn Me a Bitcoin. Parts of this lesson were inspired from this video.

So how do the computers come to an agreement on which transaction is the legit one?

Mining is the solution.

Bitcoin solves this problem of not having conflicting transactions written to the blockchain, the shared “file”.

And this is where mining comes in.