With the current hashrate, how does it still take 10min to solve a bitcoin block?

No matter how high the difficuly is (or how low the target is), I don't understand how the Bitcoin network takes an average of 10 minutes to solve each block.

For any given block header, there are only 2^32 possible values for the nonce. Even if we take into account that the timestamp can be changed by up to 1 hour (for example), that's 3600 x 2^32 possible combinations, which is approximately 1.5e13

On blockchain.info it says the current hash rate of the network is 7,991,378,504 GH/s, which means that, every second, there are multiple orders of magnitude more hashes being calculated than the number of possible hashes that can result from the current block header.

So howcome blocks aren't solved in only a few seconds, and take about 10 minutes instead?

I understand that miners want to include as many transactions as they can in a block to collect the fees, so one could argue it's best to wait until there are many transaction in a block before solving it. But even that doesn't make sense, because there's absolutely nothing to lose in solving each block as fast as possible anyway.

Mining basically works like this:

1. Make a candidate block, try all nonces.
2. If none yielded a valid block, change something in the coinbase transaction.
3. Repeat from step 1.

Miners collect transactions and then try to create a valid block by bruteforcing nonces. The difficulty of creating a block is related to the maximum hash value a valid block may have.

For example the current blockchain head (while posting this) has a block hash of 00000000000000000077d9c18fdbd5cf45b2652fe6db9089558eb8fc9fc3b397. As you can see it has many leading zeros, because most hashes above this value are rejected. With the 2^32 nonce values and other header fields you cannot try enough blocks to be likely to hit any block hash small enough. Miners will switch some bytes in transactions (normally in the coinbase) to create even more new block candidates.

Furthermore different miners will try different blocks, as they should have different receivers of the coinbase transactions.

• So the current difficulty is so high that even if a miner computes the hashes for all possible 2^32 nonces, it is still unlikely to find one below the current target. Thus, it needs to keep trying with a different coinbase until one of the 2^32 nounces actually works. Could you please point me to some documentation explaining all about coinbase transactions and new block candidates? I think that's what's missing in my puzzle. Commented Sep 4, 2017 at 15:13
• @EdwardEisenberg: Basically, miners are free to choose which transactions, or even if any at all, they would like to include in a mined block. Run through all the nonces? No problem, just add or remove a transaction and you've immediately got another few trillion hashes to try. Commented Sep 4, 2017 at 20:29
• It is not necessary to remove or add transactions. There are some malicious miners which even mine empty blocks (apart from the coinbase), so have nothing to change in that regard. The coinbase transaction can contain arbitrary data and just putting some additional nonce bytes in there is sufficient. Commented Sep 5, 2017 at 10:28
• @EdwardEisenberg en.bitcoin.it/wiki/Transaction#Generation Commented Sep 5, 2017 at 10:30

That happens because it becomes increasingly hard to mine as more hashpower is deployed to the network.

Every 2016 blocks (2 weeks) the required difficulty (leading zeroes in the block hash) for a block to be accepted as valid increases (or decreases) according to how fast the past 2016 blocks were mined. This is done by comparing the timestamp declared in the block with the timestamp that would be expected if 10 minute blocks were assumed.