What is Bitcoin Mining?
Mining is the process of adding transaction records to Bitcoin's public ledger of past transactions. This ledger of past transactions is called the blockchain as it is a chain of blocks. The block chain serves to confirm transactions to the rest of the network as having taken place. Bitcoin nodes use the block chain to distinguish legitimate Bitcoin transactions from attempts to re-spend coins that have already been spent elsewhere.
Mining is intentionally designed to be resource-intensive and difficult so that the number of blocks found each day by miners remains steady. Individual blocks must contain a proof of work to be considered valid. This proof of work is verified by other Bitcoin nodes each time they receive a block. Bitcoin uses the hashcash proof-of-work function.
The primary purpose of mining is to allow Bitcoin nodes to reach a secure, tamper-resistant consensus. Mining is also the mechanism used to introduce Bitcoins into the system: Miners are paid any transaction fees as well as a "subsidy" of newly created coins. This both serves the purpose of disseminating new coins in a decentralized manner as well as motivating people to provide security for the system. If you clicked the button above, then you are currently mining bitcoin, the math-based digital currency that recently topped $1,000 on exchanges. Congratulations. (It won’t do anything bad to your computer, we promise.)
New bitcoins are created roughly every 10 minutes in batches of 25 coins, with each coin worth around $730 at current rates. Your computer—in collaboration with those of everyone else reading this post who clicked the button above—is racing thousands of others to unlock and claim the next batch. For as long as that counter above keeps climbing, your computer will keep running a bitcoin mining script and trying to get a piece of the action. (But don’t worry: It’s designed to shut off after 10 minutes if you are on a phone or a tablet, so your battery doesn’t drain).
So what is that script doing, exactly?
Let’s start with what it’s not doing. Your computer is not blasting through the cavernous depths of the internet in search of digital ore that can be fashioned into bitcoin bullion. There is no ore, and bitcoin mining doesn’t involve extracting or smelting anything. It’s called mining only because the people who do it are the ones who get new bitcoins, and because bitcoin is a finite resource liberated in small amounts over time, like gold, or anything else that is mined. (The size of each batch of coins drops by half roughly every four years, and around 2140, it will be cut to zero, capping the total number of bitcoins in circulation at 21 million.) But the analogy ends there.
What bitcoin miners actually do could be better described as competitive bookkeeping. Miners build and maintain a gigantic public ledger containing a record of every bitcoin transaction in history. Every time somebody wants to send bitcoins to somebody else, the transfer has to be validated by miners: They check the ledger to make sure the sender isn’t transferring money she doesn’t have. If the transfer checks out, miners add it to the ledger. Finally, to protect that ledger from getting hacked, miners seal it behind layers and layers of computational work—too much for a would-be fraudster to possibly complete.
And for this service, they are rewarded in bitcoins.
Or rather, some miners are rewarded. Miners are all competing with each other to be first to approve a new batch of transactions and finish the computational work required to seal those transactions in the ledger. With each fresh batch, winner takes all. It’s the computational work that really takes time, and that’s mostly what your computer is doing right now. It’s trying to solve a kind of cryptographic problem that involves guessing and checking billions of times until it finds an answer. If this all seems pretty heady, that’s because mining is an elaborate solution to a tough problem that plagues every currency—double spending.
Double spending and a public ledger
As the name implies, double spending is when somebody spends money more than once. It’s a risk with any currency. Traditional currencies avoid it through a combination of hard-to-mimic physical cash and trusted third parties—banks, credit-card providers, and services like PayPal—that process transactions and update account balances accordingly.
But bitcoin is completely digital, and it has no third parties. The idea of an overseeing body runs completely counter to its ethos. So if you tell me you have 25 bitcoins, how do I know you’re telling the truth? The solution is that public ledger with records of all transactions, known as the blockchain. (We’ll get to why it’s called that shortly.) If all of your bitcoins can be traced back to when they were created, you can’t get away with lying about how many you have.
So every time somebody transfers bitcoins to somebody else, miners consult the ledger to make sure the sender isn’t double-spending. If she indeed has the right to send that money, the transfer gets approved and entered into the ledger. Simple, right? Well, not really. Using a public ledger comes with some problems. The first is privacy. How can you make every bitcoin exchange completely transparent while keeping all bitcoin users completely anonymous? The second is security. If the ledger is totally public, how do you prevent people from fudging it for their own gain?
Is there no such thing as a bitcoin account?
Bitcoin’s ledger deals with the privacy issue through a bit of accounting trickery. The ledger only keeps track of bitcoin transfers, not account balances. In a very real sense, there is no such thing as a bitcoin account. And that keeps users anonymous. Here’s how it works: Say Alice wants to transfer one bitcoin to Bob. First Bob sets up a digital address for Alice to send the money to, along with a key allowing him to access the money once it’s there. It works sort of like an email account and password, except that Bob sets up a new address and key for every incoming transaction (he doesn’t have to do this, but it’s highly recommended).