Correction (Dec. 18, 2013): An earlier version of this article incorrectly stated that the long pink string of numbers and letters in the interactive at the top is the target output hash your computer is trying to find by running the mining script. In fact, it is one of the inputs that your computer feeds into the hash function, not the output it is looking for.
Before even starting out with Bitcoin mining, you need to do your due diligence. The best way to do this, as we’ve discussed, is through the use of a Bitcoin mining calculator. Bear in mind that mining costs money! If you don’t have a few thousand dollars to spare on the right miner, and if you don’t have access to cheap electricity, mining Bitcoin might not be for you.
How do they find this number? By guessing at random. The hash function makes it impossible to predict what the output will be. So, miners guess the mystery number and apply the hash function to the combination of that guessed number and the data in the block. The resulting hash has to start with a pre-established number of zeroes. There's no way of knowing which number will work, because two consecutive integers will give wildly varying results. What's more, there may be several nonces that produce the desired result, or there may be none (in which case the miners keep trying, but with a different block configuration).
As more miners join, the rate of block creation increases. As the rate of block generation increases, the difficulty rises to compensate, which has a balancing of effect due to reducing the rate of block-creation. Any blocks released by malicious miners that do not meet the required difficulty target will simply be rejected by the other participants in the network.
To add a new block to the chain, a miner has to finish what’s called a cryptographic proof-of-work problem. Such problems are impossible to solve without applying a ton of brute computing force, so if you have a solution in hand, it’s proof that you’ve done a certain quantity of computational work. The computational problem is different for every block in the chain, and it involves a particular kind of algorithm called a hash function.