How does the proof-of-work system help secure Bitcoin?

How does the proof-of-work system help secure Bitcoin?

Bitcoin uses the Hashcash proof of work with a minor adaption. To give a general idea of the mining process, imagine this setup:

 payload = <some data related to things happening on the Bitcoin network>
 nonce = 1
 hash = SHA2( SHA2( payload + nonce ) )

The work performed by a miner consists of repeatedly increasing "nonce" until the hash function yields a value, that has the rare property of being below a certain target threshold. (In other words: The hash "starts with a certain number of zeroes", if you display it in the fixed-length representation, that is typically used.)

As can be seen, the mining process doesn't compute anything special. It merely tries to find a number (also referred to as nonce) which - in combination with the payload - results in a hash with special properties.

The advantage of using such a mechanism consists of the fact, that it is very easy to check a result: Given the payload and a specific nonce, only a single call of the hashing function is needed to verify that the hash has the required properties. Since there is no known way to find these hashes other than brute force, this can be used as a "proof of work" that someone invested a lot of computing power to find the correct nonce for this payload.

This feature is then used in the Bitcoin network to allow the network to come to a consensus on the history of transactions. An attacker that wants to rewrite history will need to do the required proof of work before it will be accepted. And as long as honest miners have more computing power, they can always outpace an attacker.

Also see Hashcash and Proof-of-work system and SHA2 and on Wikipedia.