How is the number of zeros in the target hash determined?

- Jean asks, how is the number of zeros that are the beginning of the target hash? How is that determined? So effectively the number of zeros is the difficulty, because the more zeros you have, the beginning of the target hash, the harder it is, if you think of the target hash as a number, the more zeros in front of it, the lower that number is.

Visualizing target hash difficulty

And as the number gets lower, it's harder to pick randomly a number that is below it. So think of this as a bar. A bar that starts out as a number that has 77 digits. So think of nine, nine, nine, nine, nine, nine 77 times being the maximum possible number you can fit in 256 bits and that's that bar. Now, if you're picking random numbers, the chances of you coming underneath that number is pretty good. So it's easy to find a number underneath that high bar. Now, if instead of nine, nine, nine 77 times, it's zero nine, nine, nine, nine 77 times. Now that's 10 times lower. Now we're doing this in binary. So it's actually cutting it in half. So now the bar is halfway down. Now, when you're picking random numbers, half of them are gonna fall above the bar. It's twice as difficult to find one that's below the bar. Now you put another zero binary, zero in front. Now that number is half as much. Now three quarters of the numbers you pick randomly are going to be above the bar. It got more difficult. And so that's what the difficulty means in mathematical terms. Think of it as Bitcoin miners, trying to do the limbo and the limbo bar keeps getting lower and lower and lower. And the reason this happens is simply because the hashing algorithm is like picking randomly. So you get a random result in the entire 256 bit range. And as the top of that range gets lower by half. Every time you make the first digit zero, and you keep having zero binary digits to the binary number, that means that the number gets half as big. And as a result, you have half as big target where you need to land your random guests and that makes it twice as difficult. So, the difficulty target is determined.

How is the difficulty target number determined?

The difficulty target is this number. Now, how is that number determined? And the way the number is determined is by pegging it to the 10 minutes blocked time. So the difficulty retargeting that happens every two weeks says blocks should take 10 minutes, 2016 blocks have elapsed. Since the last time we checked . Those 2016 blocks should've taken 10 minutes each therefore the total amount of time since our last difficulty retargeting should be a 20,160 minutes. So 2016 blocks times 10 minutes 20,160 minutes. How many minutes have actually elapsed? Well, if 22,000 minutes have elapsed, then blocks are coming out too slowly. And what we do is we divide 22,000 by the expected number 20,160. And we then adjust the difficulty proportionately by that number and reset the difficulty algorithm.

How do all nodes agree on the same difficulty target?

And that calculation happens in exactly the same way on every single node that participates in the network on the exact same block, the 2016th block in a row. And determines the difficulty for the next most block. And everybody gets the same answer because if they count from the timestamps in the blocks, the total elapsed time of the last 2016 blocks, they're gonna get the same answer. If they multiply that by the expected 10 minutes, they're gonna get the same answer. The amount that actually lives is gonna be the same answer if they divide the two, they're gonna get the same answer. And if they multiply the previous difficulty by this new adjustment factor, they're gonna get the same answer. So, thousands of nodes all around the world, at the exact same block height, do the exact same equation with the exact same inputs and arrive at the exact same answer, which tells them what the difficulty will be for the next block. And everybody knows what the answer is. So if the next block doesn't come in within that difficulty, it's not valid and miners know what number they need to reach 'cause they've done the exact same calculation. So that's how the target hash is determined. (upbeat music) - [Announcer] If you enjoyed this video, please subscribe like and share. All my work is shared for free. So if you want to support it, join me on Patreon.