Miners are responsible for validating transactions, creating blocks and adding them to the blockchain. To create valid blocks, miners must operate machinery that can produce a valid Proof-of-Work. These machines search a number space to discover a solution to a mathematical function whose outputs cannot be predicted. The guesswork nature of the problem requires a certain amount of cost and energy to be expended in finding the solution.
The main costs associated with the mining process arise from the upfront investment in machines and the ongoing consumption of electricity. The expenditure of electrical energy inferred by a valid Proof-of-Work provides evidence to the network that a certain amount of time has passed, resulting in an objective time-ordering of the blockchain. To compensate miners for putting in the work to create a valid block and adding it to the blockchain, the protocol allows them to reward themselves with freshly minted bitcoin and claim all the transaction fees offered by senders in that block.
Over time, as bitcoin has increased in value, mining has evolved from a geeky hobby into a fiercely competitive global industry in which miners compete to generate valid Proof-of-Work most efficiently. In general, the most profitable miners are those with the most efficient machines, consuming the cheapest energy. Miners are therefore heavily incentivised to seek out the world’s cheapest sources of electricity.
The real-world costs of mining, coupled with the bitcoin-denominated rewards, also incentivises miners to act honestly within the network. As the purchase of mining hardware may be seen as a prepayment on future earned bitcoin, any malicious behaviour that would likely harm its exchange value would reduce the value of their hardware investments.