Thanks, im going to have to go over that a few times before i can work out exactly what your talking about but i will get their in the end . Seems quite complicated.
So what decides what the current target is? are all mining clients synchronised and contain the answer to solving the block? why cant someone just look at the source to find whatever the target is and mine it instantly?
Imagine I told you that you had to roll a set of 15 six-sided dice repeatedly until you rolled a 6 on at least 10 of them simultaneously.
By changing the target that you need to hit, I can change the "difficulty" of getting a solution. I can set the target at "a 6 on at least 3 dice simultaneously" if I want to make it easier, or I can set the target as "a 6 on at least 14 dice simultaneously" if I want to make it harder. It doesn't change the process that you are using, it just changes the target you need to hit.
This is a good analogy of how bitcoin hashing works.
The hash is a mathematical process that works in a way that it is impossible to know ahead of time what the result will be until you calculate it. So, you have to pick a value, try hashing it, and see what the result is. If the result meets the target, then you "win". If the result doesn't meet the target, all you can do is pick another value and try again. You keep trying over and over until either you find a result that meets the target, or you receive a block from someone else that has successfully found a result that meets the target.
For bitcoin, the "target" is just a number that the result has to be smaller than. The results of a SHA256 hash will be somewhere between 0 and 1.158 X 10
77, but lets work with smaller numbers to make it easier to understand. Imagine that you have a hash function that results in a number between 1 and 100. It is impossible to predict what the result will be until you've calculated it to see. I tell you that the target is "50", meaning that any number smaller than 50 will count as a success. You can continue to use the same hash function, and I can make succeeding more difficult by lowering the target to "5", or I can make it easier by raising the target to "95".
Every full node that is running on the network use the same formula for calculating what the difficulty should be right now. Therefore, if any miner tries to broadcast a block that doesn't have a solution that meets the current difficulty, then every node on the network will just ignore that miner's block. It will get tossed out, and he will have wasted all of his effort in solving that block. Therefore, every miner has an incentive to make sure that he is using the same formula to determine the current difficulty as everyone else. If he sets his own difficulty too easy, then everyone will ignore his blocks. If he sets his own difficulty too hard, then he might find a valid solution that everyone would accept, but he won't notice it because he's checking against the wrong difficulty (and so he'll fail to broadcast that block and get paid for it).
The difficulty is adjusted every 2016 blocks. The formula for adjusting difficulty requires looking at the total amount of time that it took for those 2016 blocks to be solved. If it is more than 20160 minutes, then it took too long and difficulty is too hard. If it is less than 20160 minutes, then it didn't take long enough and difficulty is too easy. The current difficulty is adjusted by the exact same proportion as the amount of time that the 20160 minutes was missed by. So if the 2016 blocks were solved in 10080 minutes, they came twice as fast as they should, and the target is cut in half (difficulty is doubled). If the 2016 blocks were solved in 22176 minutes, then they came 10% too slow, and the target is increased by 10% (difficulty is reduced by 10%).