Hello everyone, this is my first topic here. I feel excited little bit lol. And sorry for my English, it is not my first language.

Ok so I've been interested in cryptoCurrencies since the August 2017, but lately I decided to learn more about the technology itself; blockchain. I know most of the parts about how it works. but some little details that I dont understand bothering me.

I have researched everywhere. I love researching and learning. But no success for this particular topic.

My questions is about mining (technical side). I understand how it works basically, I'm a home miner myself but couple things really annoying me.

1-) I'm looking at block 540494, its nonce is 2097181953 its hash is 00000000000000000024ada2........

so it starts with 18 leading zeros..

that means a miner starts from 0 calculates its hash with the nonce=0 IF no valid result, THEN increments nonce by 1. now nonce=1, and keep doing this until a hash is found with 18 leading zeros. Because current difficulty requires them to find a hash with 18 leading zeros, right?

Sub-question: I know difficulty changes every 2 weeks, it is now 7,019,199,231,177 but who decides how many leading zeros should be in the valid hash? is it something to do with "target difficulty" rather than the "difficulty number" itself? Are these 2 different difficulty parameters that define the difficulty?

So for this particular example (block 540494) the nonce is 2097181953

that means a miner tried every single nonce from 0 to 2,097,181,953, and calculated hash 2,097,181,953 (lets say 2 billions) times in total and found the valid result which is the hash starting with 18 zeros. (00000000000000000024ada2........)

Now what I dont understand is that an ASIC machine can hash 12 trillion times PER SECOND. and our nonce is 2,097,181,953. so that means winning miner spent only fraction of a second to calculate 2 billions hashes. But it cant be true because block time is 10 minutes, right? so what is wrong here?? What am I doing wrong with this calculation?

My understanding is like the following;

* Miner have a list of transactions and all the properties (headers I believe) to calculate the hash of the block.

* Miner calculates hashes for all the nonces between 0 and the current difficulty (it is now 7,019,199,231,177)

* IF miner finds a hash with at least 18 leading zeros (can be more than 18 zeros, right? since even if it has 20 leading zeros, it is still proof of the work.) that miner gets the reward.

* IF miner cant find a nonce between 0 - 7,019,199,231,177 then miner picks different set of transactions (since calculations with the current list of transactions wont be resulting valid hash.. So miner adds couple more transactions into the block and starts the whole process all over again with the new list of transactions.. hoping to find a valid hash with the nonce between 0 and 7,019,199,231,177 and with the new set of transactions.

So did I get it all wrong? and confused myself for nothing? 😄 or this is actually what is happening? I know there are couple of gurus here and can confirm if I'm right or wrong..

Thanks