Satoshi Nakamoto explains in an email how Proof of Work provides a probabilistic solution to the Byzantine Generals Problem, which means the confidence that a consensus is reached is growing with every block added to the chain, but it never reaches 100%.
In Blockchain, the PoW algorithm is used to confirm transactions and produce new blocks to the chain. Miners compete against each other to complete transactions on the network and get rewarded. Users send each other digital tokens and a decentralised ledger gathers all the transactions into blocks. The responsibility for confirming the transactions and arranging the blocks falls on special nodes called miners, and a process called mining.
The difficulty is to find an agreement among members (consensus) on the order of transactions which must be added. Proof of work is one of the mechanisms used in which this agreement can be made while guarding the security of the network, specifically that a new member must first be demonstrate involvement before its blocks can be added to the blockchain. In blockchain, this involvement requires putting computing capacity at the disposal of the members of the network. The computing power is used for how to find the input knowing the output (hash functions), calculating numbers as a multiplication of two other numbers (prime factorisation) and if need be, for finding a chain of hash function values (guided tour puzzle protocol).
Miners solve the puzzle, form the new block and confirm the transactions. How complex a puzzle is depends on the number of users, the current power and the network load. The hash of each block contains the hash of the previous block, which increases security and prevents block violation. If a miner manages to solve the sent puzzle, the new block is formed. The transactions are placed in this block and considered confirmed.
The problem can be solved because all nodes agree on a common truth and nothing ever goes wrong: