Mining involves the process of producing a hash whose value is less than the target value. When this hash has been found, it is called a valid hash and hence proof of work is achieved.
The mining algorithm uses a counter known as the nonce to generate the hash using the SHA256 cryptographic function. A hash algorithm always produces the same arbitrary length data given the same inputs. It is impossible to compute the same hash with two different inputs. It is also impossible to predict the output of any given data in advance.
The value of nonce is initialised to 0. Mining is finding the nonce, the only input that changes every time we run the hash function. The goal is to find a value for the nonce that will result in hash lower than the target. So, the mining node might need to try billions or trillions of nonce values before it gets a valid hash. As you can see, mining is like playing the slot machine, there is no way to predict when can you strike a jackpot.
It is very easy to prove that the nonce found indeed produces a valid hash. All the information are available, everyone in the network can run the hash function and confirm if the hash is valid or not. Because it is also impossible to predict what the nonce will be, it also acts as a proof that the miner has indeed achieved Proof-of-Work.
Calculation of the Valid Hash
(The numbers are based on block #540909)
The formula to calculate the current target of the block is
Current target= maximum target ÷ difficulty
Maximum target is set to
This is a hexadecimal number. After conversion to a decimal number
Difficulty is (as given in the block)
The hash of the block is
After converted to a decimal number, the value is as follows:
The hash value is approximately 8.95×1051
Clearly, the hash value is less than the current target, therefore it is a valid hash.