Everything you need to know about Bitcoin mining
The primary purpose of mining is to allow Bitcoin nodes to reach a secure, tamperresistant 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.