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.
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.
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.
The transaction is just a line of data (in purple).
When you initiate a transaction, it gets sent to a node of the Bitcoin network.
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.
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….
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”.
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.
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.
Then you send this transaction to the node on this side of the Bitcoin 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).
Then you send this transaction with the red dude into another node on the network.
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!
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.
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…
Now you have two CONFLICTING transactions on the network.
Remember, every computer on the network needs to all 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.
Bitcoin solves this problem!
Please read my lesson on the Double Spending Problem if you’re not familiar with it.
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.