My regular readers are probably aware by now that I more than dabble in Bitcoin. If you don’t know what Bitcoin is – well first of all, you’re probably reading the wrong article, but go ahead and watch this video and you should be up to speed. One of the most common points of confusion for new Bitcoiners is the concept of mining. Most Bitcoin newbies can’t wrap their head around the concept and practically every article on the topic (this one included) will warn you that it’s highly technical and not for the faint of heart.
Still, the topic of mining seems to spawn the majority of the questions every time I talk to someone about Bitcoin – and why not? It is the mechanism by which the currency is issued, and issuance is a very important topic to grasp if you’re going to use and trust a currency and Bitcoin’s issuance mechanism is, unfortunately, quite complex and technical. This article is going to attempt the near-impossible: a thorough explanation of how mining works but without any of the specific details that might scare the non-techies in the room.
Now I’m going to do my best to avoid technical terms, but there are a few core concepts and terms that are absolutely vital to understand if you want to wrap your head around mining. I’m going to keep these to a bare minimum and explain them as simply as possible.
In computing terms a hash is the result of some really complex math that’s easy to reproduce but impossible to reverse and hard to predict. Imagine, for example I tell you that I added two numbers together and the result was 14,862. Given only that number there’s no way you could tell me what two numbers I added to get that total, but it would be easy to reproduce my result if I asked you to add 3,608 and 11,254. Hashes are much more complicated than this, and while the output of a hash function seems completely random it’s actually the result of some crazy but easy-to-reproduce math.
In Bitcoin, transactions are bundled up into big chunks of data called blocks. These blocks are linked together in such a way that each one proves that the block before it was valid. When you see transactions in your Bitcoin client that say something like “12 confirmations” it means that the block containing that transaction is currently 12 blocks back from the current block. This is important because the more blocks deep a transaction is, the more work it would take for a would-be hacker to go back in time and change it.
Bitcoin contains a “difficulty factor” which is an arbitrary number that determines how hard it is to find a “winning” hash – more on this later, but for now just understand that difficulty is Bitcoin’s way of self-adjusting to the amount of computing power miners are throwing into the network. Blocks are supposed to be solved at a rate of about 6 per hour and difficulty adjustments allow Bitcoin to ensure that its math problems are hard enough that it always takes the combined efforts of all the miners around 10 minutes to solve a block.
So the basic concept of Bitcoin mining is that there’s a little chunk of each block that contains meaningless random data, and Bitcoin miners take all the data in the current block, shuffle up that random chunk and calculate the hash of the whole thing. Remember that while hashes are easy to reproduce, they’re impossible to predict and they seem to function completely randomly, so the miner has no way of predicting what chunk of random data will produce what hash, he just has to keep changing that chunk until he gets the result he’s looking for. Eventually, some miner somewhere finds a chunk of random data that produces a hash that is smaller than a certain value, as determined by the difficulty, and submits this block and its accompanying hash to the Bitcoin network. Once the network confirms the solution is correct, the miner is rewarded with a number of Bitcoins.
The number of Bitcoins in the reward depends on a number of factors. There is a base reward included in each block to encourage mining activity while Bitcoin is still in the early stages – currently the reward is 50 bitcoins but every so often the reward is cut in half until eventually it’s cut down to zero. Some transactions also pay a small transaction fee, which goes to the miners as well. Eventually these transaction fees will be the only reward for mining, but the hope is that by that time there will be enough transactions (and therefore enough fees) to make it worthwhile.
At the very beginning, the number of miners and the quality of their equipment was so low that what I’ve described above was all there was: a bunch of everyday computers doing lots of math at high speed and most of them got a few hundred bitcoins each day. Today, however, there are so many miners and their equipment is so much faster that $1,000 worth of mining equipment would spend two to three months working before you solved your first block. Something had to be done.
Mining pools sprung up to solve this problem. The concept is simple: A bunch of miners work together to solve blocks and when the pool solves one, they divvy up their earnings in whatever way seems most fair. There are, of course, arguments between pools about what the best way to split up the funds is, but that’s a fairly technical discussion for another article.
Those are the basic mechanisms, but there are a few important things to gather that may not be obvious at first:
- The hashes aren’t just to make life difficult for the miners. Because it takes so much computing power to find a hash that follows the rules, a would-be hacker trying to change the contents of a block would have to find a new hash that fits those rules again. Because he’s trying to rewrite history he not only has to find a new hash, he has to find it faster than the legitimate miners can, which would require a tremendous amount of computing power and confers very little benefit. The more miners there are, the higher the difficulty goes. The higher the difficulty goes, the harder it is to commit fraud on the Bitcoin network.
- Before anyone asks: yes, the difficulty is already high enough that it would cost hundreds of millions of dollars to be able to rewrite a single transaction, so not worth it unless you’re buying an aircraft carrier or something.
- Remember how I said the block reward gets cut in half every so often, and eventually goes to zero? That means that at some point, the system stops creating new bitcoins. At most there will only ever be about 21 million bitcoins.
- I also said that the number of miners and the speed of their hardware was getting better. This is an over-simplification. Bitcoin mining has been through some growing pains and still has a few more such pains to go through. In the beginning people mined with the regular everyday processors in their computers. One day some clever person realized that the kind of math required for mining actually ran hundreds of times faster on high-end video cards (the kind used for computer gaming) than on regular computer processors – this was like introducing sports cars to a horse-and-buggy world. At the time of this article, some companies are now designing completely custom-built devices that are drastically better than the video cards we’ve all gotten used to. These major leaps in technology are a big part of what makes it so risky to be a Bitcoin miner – you could get left in the dust by one of them at any time.
- All of these things cost money and use electricity, which also costs money. A few lucky miners live in college dorms or mine out of office buildings where they’re not responsible for the electric bills, but most miners have to pay for their electricity and in some areas this makes it very difficult to turn a profit.
- There is no central authority. As with everything else about Bitcoin, mining is distributed, meaning that everyone in the network both agrees to and enforces the rules. Any time I say “Bitcoin does this” or similar, what I’m really saying is that “The rules say this” and everyone in the network enforces those rules.
- Finally, every last factor I’ve already described operates completely separate from the factors that determine how much a Bitcoin is worth. This means that sudden changes in the value of a bitcoin can make or break mining operations. Granted if a drop in price knocks some miners out of the picture, difficulty will decrease to accommodate, but that takes time. Miners follow the market – the market does not follow the miners.
Hopefully this description is adequately detailed but written simply enough that it can be of some help to some new Bitcoiners out there. I know it can be tough to wrap your head around the technical details if you don’t come into the world of Bitcoin already understanding cryptography and programming.
If anything is unclear or if you think you’ve got something worth adding, let me know in the comments and I’ll do my best to keep everyone happy!
Update: This post has been getting a lot of attention lately and I’ve been overwhelmed with variations around one question: “What purpose does mining actually serve?”
The answer is twofold:
- Mining allows the initial supply of Bitcoins to be distributed without a centralized authority
Distributing currency is an easy task if you’ve just got a central authority – that authority just prints up some money and decides who to give it to. When you have no central authority and you don’t want any old schmuck printing up a ton of currency at will and destroying your money supply with inflation, you’ve got some hard problems to solve. Mining solves this problem by including a difficult proof-of-work problem in Bitcoin’s very protocol for which the reward is a chunk of currency.
- Mining solves the Byzantine Generals Problem.
This is the part of the explanation that gets long and complicated – really long and complicated. It’s a rabbit hole and a half, but if you’re willing to go down that rabbit hole, the best place to start is probably this post from Bitcoin creator Satoshi Nakamoto. For a more generalized explanation, I recommend the Wikipedia article on Proof-of-work systems. The short version is that it’s a method for resolving conflicting transactions and preventing double-spending.
Tip With Bitcoin
Each post has its own unique address, so your tips also tell me what you liked!