## What keeps the average block time at 10 minutes?

56

23

I've been told "the network" sets the difficulty level such that there will be one new block mined every ten minutes.

I imagine the rich would instead prefer to keep difficulty as high as possible to prevent other people winning their 50 BTC and causing inflation, whereas the poor would prefer as low a difficulty as possible in order to get a greater share of the BTC available.

(By rich and poor, I mean only according to how many BTC someone has.)

What's the force saying "No, forget your petty self-interest and set the difficulty to 10 minutes."?

55

The bitcoin network rules define which difficulty each block has. This is done through a simple formula that only depends on the block chain itself. This means that if you give me a blockchain with blocks 1 through N, I can tell you with 100% accuracy what the difficulty of block N+1 will need to be, and I can reject any block which has the wrong difficulty. This means it is not really "the network" deciding on a difficulty, but really each separate node calculating and enforcing it independently.

The actual formula is this: at every block N which is a multiple of 2016, look at the time stamps of the past 2015 blocks, and change the difficulty for what follows to old_difficulty*(2 weeks)/(time the past 2015 blocks took). Additional rules on which time stamps are allowed in blocks prevent cheating (mostly).

In short, by using a bitcoin client, you agree to its network rules, and those include the difficulty adjustment.

1@billpg - Correct. It would be more accurate to say difficulty is set by the algorithm. It is adjusted every 2016 blocks based on average execution time for prior 2016 blocks to ensure future average execution time remains ~10 minutes. Of course a miner could ignore/break this algorithm but then they wouldn't be mining valid bitcoin blocks (they would be mining a fork). – DeathAndTaxes – 2011-10-10T13:20:11.203

Just to be completely clear: "time the past 2015 blocks took" means "Timestamp of block 2016N-1 minus timestamp of block 2016N-2016"? And without the off-by-one bug, it would have been block 2016N-2017? – Meni Rosenfeld – 2012-01-22T06:09:06.713

And another question - is it multiplied by 2 weeks (1209600 seconds, the desired time to create 2016 blocks) or by 1209000 (the desired time to create 2015 blocks)? – Meni Rosenfeld – 2012-01-22T06:47:18.447

@MeniRosenfeld I believe so, yes. And it's "14 * 24 * 60 * 60; // two weeks" (first mention of nTargetTimespan in main.cpp) – Chris Moore – 2012-03-20T02:51:48.797

OH, it's 2 weeks and 2016 blocks, not 10 minutes. 2 weeks = 20160 minutes / 2016 = 10 minutes per block. – Chloe – 2017-12-23T18:19:43.433

What would happen if my bitcoin client where cheating and not agree to its network rules, and put less or more transactions in the block? – Damian – 2019-03-07T08:58:44.437

There is no rule that requires a specific number of transactions to be put in a block. This question and answer is about proof of work in blocks, not transactions. – Pieter Wuille – 2019-03-07T17:54:05.007

4Hmm, could you be more precise about the "time stamp" used? Afaik the time in the block header can be very inaccurate, and block propagation can induce some delay between nodes (so, if they record the time they first heard of the block, not everyone would exactly agree on the same difficulty). And, what would happen if one generated blocks with a computer whose clock is out-of-sync (like, days in the past/future)? (If this is not adequate as a comment I can make a separate question.) – Artefact2 – 2011-09-10T19:30:55.133

4

@Artefact2: from the wiki: "A timestamp is accepted as valid if it is greater than the median timestamp of previous 11 blocks, and less than the network-adjusted time + 2 hours. "Network-adjusted time" is the median of the timestamps returned by all nodes connected to you."

– None – 2011-09-10T21:55:49.927

I think the important thing is that it's not a buncha servers voting on what the difficulty should be, which is what it sounds like when people tell me that the difficulty is set by the network. – billpg – 2011-09-11T00:00:39.937

12

Each individual client checks the validity of each block it receives. If it receives an invalid block, it ignores that block as if it didn't exist.

If you mine a block and other clients ignore it, you don't get your 50 Bitcoins. You only get to keep your 50 Bitcoins if the block you mined becomes a link in the accepted public chain.

One of the first things that is checked by the client when it receives a block is that the block meets the difficulty target that it calculates based on how quickly blocks have been generated. If that client doesn't think that block meets the difficulty target that it calculated, then it ignores the block.

So you have to mine a block that other clients will accept, or you don't get your 50 Bitcoins.

4

Software. The Bitcoin network runs on a set of previously-agreed-upon rules that are built into the Bitcoin client software.

One such rule is that the difficulty should be changed every 2016 blocks to make a new block take, on average, 10 minutes to mine. As the economics change, miners will startup and shutdown making the average block take more or less than 10 minutes to find but the next time another 2016th block is mined, the difficulty will again be re-adjusted.

I would actually reword your question as well since a block's difficulty isn't technically set to a time but a number. Instead you might want to ask, "What keeps the average time to mine a block at 10 minutes?"

3

The difficulty is adjusted every 2016 blocks by the whole network so as to average the Bitcoin generation to a block every 10 minutes. If the coins were on average generated too fast since the last adjustment, the difficulty is increased, if they were generated too slow - it is decreased.

What the rich can only do is do their best to have the highest possible hashing speed. This would make them brake the block more often (they would earn more money), as well as increase the difficulty higher, so people with lower-end machines could not brake a block without using a pool in a reasonable time (as is the case currently).

What the rich can also do is hoard the Bitcoins, so their value would increase. Keep in mind that even if someone would own 99+% of all the Bitcoins the currency would still be as usable as with bigger pool of coins (Bitcoins currently can be divided to up to 8 decimal places, and there is nothing stopping a future implementation from dividing them up even further).

Of course if someone wants to depreciate the value he or she can undermine the trust people have in the coins. For example, the hacking of Mt.Gox caused a lot of people to be more reserved when handling the coins. On the other hand, if one wants to increase the value of Bitcoins, one should promote them, convince new people to invest in them and be a contributing member of the community.