Proof of Work
Proof of Work is a concept that helps to secure the transactions in a blockchain. In the context of Bitcoin, it is a mechanism to ensure that the newly created block has not been tampered with. The concept is quite simple. A miner, before including a block in the chain, has to solve a mathematical puzzle. This puzzle is expected to be solved within a certain time frame. The first miner who solves the puzzle is considered as the lucky miner who has mined the block. The process of solving the puzzle is known as “mining”.
In order to secure the transactions, a difficulty level is assigned to the puzzle. This difficulty level is automatically adjusted such that the puzzle is solved by a miner roughly every 10 minutes. Thus, the time taken to mine a block is directly proportional to the difficulty level assigned to the puzzle. Once a miner mines a block, the block is broadcasted to the entire network. The other miners in the network then verify the newly mined block and if they find the block to be valid, they add it to the chain. This creates a consensus in the network that the block is valid and it should be part of the chain.
The proof-of-work concept was introduced in order to implement a distributed timestamp server on a peer-to-peer network. This is an additional implementation added to each block in the blockchain.
To achieve this, a nonce value is added to each block. The nonce is a number that ensures the generated hash of the block meets a certain criterion. For example, the generated hash must have its leading four digits as zero (e.g. 000010101010xxx).

The miner starts with a nonce value of 0 and continuously increments it until the hash meets the specified criterion. Generating the desired hash is a random process and cannot be controlled by the miner. It may take multiple iterations until the desired hash is generated.
The expected time to generate a block in the Bitcoin system is 10 minutes. Once a miner successfully generates a block, it is added to the end of the chain and the miner is rewarded with bitcoins.
Competition among miners to generate a legitimate block is common. The miner with more computing power has a higher chance of winning the competition. However, this could lead to attacks on the system by those who possess a large amount of processing power. This issue will be discussed later in the tutorial.