Mining is a key component of the Bitcoin system. It helps secure the network, is integral to the issuance of new coins, and in a sense ties everything together. But how does it work?
Well, it’s slightly complicated, so I’ll try to explain it in a condensed way that is simple but not “too simple”, so you hopefully get the gist of it:
On average every ten minutes, transactions on the Bitcoin network are bundled together into a “block”. But in order for a block to be accepted by the network, the creator of the block (i.e. “the miner”) needs to prove they did the proper “work”. This is known as “proof of work”.
Think of it like this: In order to create a block, you have to solve a math puzzle. The puzzles are hard to solve, yet easy to verify (sort of like a Sudoko puzzle). When a miner sends a solved block to the network, the other miners can quickly check if it’s correct, and then everyone starts working on the next block.
Obviously, unlike Sudoko puzzles, these proof-of-work “math puzzles” are solved by computers running the Bitcoin software, rather than people using a pencil and paper.
The puzzles are solved using brute force trial and error. There are scads of combinations tried every second from miners all around the world. In fact, a single miner will be computing trillions of “hashes” per second. You may hear the word “hash” or “hashing” being thrown around quite a bit in Bitcoin conversations. (You don’t really need to know what a mathematical hash function is, but essentially it is the math puzzle I am referring to).
In the early days of Bitcoin, mining could be done on any computer, simply with the computer’s CPU. Over the years, mining moved away from CPU to GPU, then to FGPAs, and finally to ASICs (Application Specific Integrated Circuits). Today, you need a specialized ASIC piece of hardware to mine (ordinary computers are far, far too slow.)
When a miner produces a block, they have to bundle all the transactions that will be included, and also refer back to the previous block. All this gets put into the hash function. Because each block refers to the previous, together they make a chain of blocks (hence the term “blockchain”).
Since the blocks are chained together, this is what creates the security for Bitcoin. No one can build an alternate history of transactions without redoing all the work for those blocks, and if this is attempted, the attacker will be too slow compared with the rest of the network that is continuing to extend the blockchain.
In addition to the normal transactions being bundled into blocks, miners are also allowed to include a special transaction on each block, called a coinbase transaction, which awards the miner with freshly minted coins. Thus, the mining process provides an economic incentive to participate in providing security, while it at the same executes the issuance schedule.
“Network hashrate” refers to the total aggregate amount of mining being done by all miners on the chain, and this tends to follow the price of the coin. The greater the financial rewards, the more the system attracts miners to compete for those rewards.
Finally, there is a difficulty adjustment, whereby, periodically the network will make it either easier or harder to solve blocks, based on how fast (or slow) blocks have been coming in. As the hashrate goes up, the difficulty will also adjust upwards, and the system will continually keep adjusting so that the average time between blocks is ten minutes.