The easiest way I can think of to explain this is to give you a die (dice) and say “If you roll less than a 6, i’ll give you $100”. It’ll be pretty easy to get the money, right? The only way you can lose is if you roll a 6
Now if I change the game to be “roll less than a 2”, it’s harder (less likely) that you’ll get it on your first go, because you have to roll a 1.
So lets say I am aiming for you to win $100 a minute, and you’re fast enough to roll about 3 times a minute. You start rolling and I notice with the difficulty set at 5, you’re winning a lot more often than once a minute, so I dial the difficulty number down (make it harder). Say we reach a point where with the difficulty set at “below 3” you are, on average, winning once a minute. Then you have a real streak of bad luck and it takes you 4 minutes to roll less than 3 – you just kept rolling 6’s for the first 3 minutes. I figure I’ll go easy on you, and I raise the difficulty number again because you’re having a bad streak so I’ll make it easier to win. Then you start doing really well, so i start reducing the number again.
On a regular basis, i’ll look back over the average time it took you to win recent games and decide whether to adjust the difficulty or not, and tweak it up or down to try and keep you to winning once a minute. If you get faster at rolling, i’ll make the game harder. If you get your buddy to roll with you, I’ll make it harder still. If you put the die away for a day then roll a win it’ll massively affect the average time for a win, and I’ll probably adjust thing so it’s easier.
This uses a 6 sided dice; the numbers involved in bitcoin are much much higher – at the time of writing the difficulty is about 15,000,000,000,000 and hashes can be between 0 and 2^224 (about 270,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000) but the premise remains the same – it’s a dice with 27000 vigintillion sides and you have to roll less than about 15 trillion. And you can buy devices that roll up to 16 trillion times a second. With your big rewards you can buy loads of these devices and fill a warehouse with them, increasing your odds of being the one to roll the win, if you can afford the power bill
The rolling of the dice is the generating of the hash code for the transactions the miner has decided to pack into a block.
In essence the miner packs a block with transactions, calculates the hash, it’s greater than the difficulty, they change one number in the block header (rather than go to the effort of packing another block of transactions – a lot more computationally expensive to do but would have the desired effect of changing the hashcode, which is the overall goal) called the nonce. So we change the nonce, re-do the hash, is it less than the difficulty? No. Change the nonce, redo the hash. Check the difficulty/change the nonce/hash/check/change/hash/check/change..
Eventually something happens:
- we find a hash less than the current difficulty – quick! announce it to the network and get the world to verify the work, accept it and we get the reward
- someone else finds a block of transactions that has a hash less than the difficulty, they get the reward, all the transactions they packed are completed/paid – we need to start over with a new block of transactions
- we run out of nonces (there are only 4 billion) because we’re hashing so fast (transaction blocks have a timestamp that increments, which also changes the hashcode, but even then coupled with the 4 billion nonces means if we hash faster than >4ghash/second we’ll run out of nonces before the time ticks up by a second, so we then go and modify one of the transactions slightly, or swap it out for another) – whatever is needed to bring about even a valid single byte change in the block will produce a different hashcode, so we make that change and carry on (probably back with the nonce changing method)
So who is the authority on what the difficulty should be? Same as anything else with bitcoin – everyone. The network decides on the difficulty, and because all (or most) of the network are good actors, you can’t cheat, you can’t write a program that claims a win with some hash, because everyone else proof checks the work and they don’t accept it if you cheated the hashcode, or lied about getting lower than the difficulty. It’s like everyone else in the casino watched you roll, and if you rolled a 6 but shouted “i rolled a 1!” they ignore you