Mining
Mining is the process used to organize and confirm transactions for new blocks added to proof of work blockchains. To incentivize this activity blockchains typically reward miners with the network’s native cryptoasset when they discover and verify new blocks.
New transactions are broadcast to a Proof of Work blockchains like Bitcoin as strings of text. These strings of text are stored in the network’s mempool. Waiting for miners to transform them into hashes that can be incorporated into future blocks added to the network’s distributed ledger.
When the process of hashing unconfirmed transactions individually is complete. A Merkle Tree is created for the transactions as a group for inclusion onto the blockchain in the next block.
The race is now on for miners to discover the next block and receive the block reward. By applying their hash power to discover the right combination of the previous block header, Merkle Tree for the candidate block, and nonce.
The previous block header and Merkle Tree do not change. Miners are tasked with guessing a nonce that can be combined with the previous block header and Merkle Tree. That will generate a hash the network will confirm as valid to add a new block.
When a miner identifies the correct combination needed to form the block hash. They broadcast it to the network for confirmation. When a majority of nodes verify the block is valid it is added to the chain. At this point the remaining miners who lost the race discard their candidate blocks and move onto trying to hash the next block for the chain.
The more hash power a miner has the more likely they are to find the correct nonce value first and receive the block reward.
What if two miners broadcast valid blocks at the same time?
Miners start to mine the next block based on which broadcast they received first. This triggers a temporary network fork since miners are mining based on different candidate blocks. A winner is determined when the next block is added to the chain.
Whichever block the new block is added to becomes the verified block for the chain. Orphaning its competitor, causing the miners who initially viewed it as valid to abandon it and switch to mining based on the winning block.
Further Reading Mining
How Much Money Can You Make From Crypto Mining?