Miners act as accountants who continuously verify the integrity of a public record of all bitcoin transactions that have ever been made.
- Sam has 1.0 bitcoins which he wants to send to Robert.
- In order to send Robert 1.0 bitcoins, Sam broadcasts the details of the transaction (who the bitcoins are for, how much is being sent, who is sending the bitcoins) to every bitcoin "miner". Something called "Public key cryptography" allows Sam's and Robert's identities to remain anonymous. The amount of bitcoins being sent is public.
- Bitcoin "miners" grab a group of pending transactions (hopefully including Sam and Robert's transaction) and begin hashing (see "SHA-256") them together with the last officially verified group of transactions (a "block") with small variations. Sam can increase the chances his transaction is included in a miner's block by including a small transaction fee which will be awarded to a lucky miner who constructs a new block with a special property (see next step).
- The miners keep trying different hashes until one miner (let's call her Mary) produces a hash that has a very special property: the hash result contains a long continuous string of zeros. It is rare for a hash to have long strings of zeros. Figuring out how to get the hash to output long strings of zeros is the "mathematical puzzle" that people talk about.
- Then, Mary tells every other miner in the network the details of how exactly she produced her difficult-to-discover hash. These details are simple to explain (but very hard to discover in the first place) and the other miners can confirm her work very quickly.
- Once the miners successfully verify Mary's work, they all begin downloading and sharing the data she hashed and label it as the next block in the blockchain.
- All transactions Mary included in this block are now encoded into the block chain. The updated blockchain is transmitted to every person in the Bitcoin network.
- As a reward for her work, Mary gets to award herself 25 bitcoins (plus all the transaction fees associated with the transactions she included in her block) as the first transaction of the next block that all the other miners then begin constructing (which they begin hashing together with the block Mary just generated).
- Robert's bitcoin wallet program downloads the block Mary created and discovers Robert's bitcoin address tucked inside along with data proving (using public key cryptography) that he had received 1.0 bitcoins from an address (Sam's) that had 1.0 bitcoins.
- If Robert wanted to send his bitcoins to you, all your bitcoin wallet program would have to do in order to verify that Robert indeed had 1.0 bitcoins to spend would be to check Robert's bitcoin address against the public transaction history (the block chain every wallet keeps a copy of) to trace the history of those bitcoins all the way back to when those bitcoins were first created by some lucky miner long ago.
- Now Sam can no longer send those 1.0 bitcoins to anyone else. The public record proves Sam no longer has those 1.0 bitcoins. If Sam broadcasts a new transaction citing those same 1.0 bitcoins he gave to Robert, miners (equipped with the public transaction history) will detect the fraud attempt and drop Sam's fraudulent transaction.
In summary:
Miners act as accountants who continuously verify the integrity of a public record of all bitcoin transactions that have ever been made. Each addition to the public transaction record is called a "block". Miners verify the public transaction record ("block chain") by continuously hashing candidate blocks with the most-recently-proved block until a lucky miner's candidate block is found to have a special property. A candidate block is special if it produces a hash with a long continuous string of zeros when combined and hashed with the most-recently-proved block. As a reward for securely extending the block chain (which is literally the public transaction record of all bitcoins), miners get a bounty of new bitcoins (an amount that is halved every four years) plus any transaction fees associated with transactions they had included in special blocks they construct. Everyone has access to this public transaction record and can prove who has how much money (using bitcoin addresses which people can choose to keep anonymous).
Addendum:
In order to control the rate at which new blocks are discovered (and therefore how quickly bitcoins are generated by miners), the bitcoin program that miners use automatically adjusts the number of zeros required for a hash to be considered "special" so that the rate at which new blocks are discovered (a function of how many miners there are and how fast their computers can calculate hashes) is constant.
Feel free to write