Bitcoin Difficulty Adjustment Explained: The 2016-Block Retarget
Bitcoin aims for an average block interval of approximately ten minutes. It does not enforce a ten-minute delay between blocks. Instead, Bitcoin mainnet periodically adjusts the proof-of-work target to respond to changes in network hash rate.
What happens every 2016 blocks?
On Bitcoin mainnet, a difficulty retarget occurs at heights divisible by 2016 (after the initial period). The protocol compares timestamps from the retarget window with an expected timespan of 2016 × 600 seconds, or 1,209,600 seconds (two weeks). The new target is calculated from the previous target and the measured timespan, subject to consensus bounds.
The actual comparison uses the timestamp of the last block in the preceding period and the timestamp of its first block, rather than the elapsed wall-clock time over an idealized exactly 2016 full intervals. That detail matters when reproducing Bitcoin Core's consensus calculation.
What limits the change?
For mainnet, the measured timespan used in retargeting is clamped to between one-quarter and four times the expected period. The target is also bounded by the network's proof-of-work limit. Since difficulty is inversely related to the target, a higher target means easier mining and a lower target means harder mining.
The block header stores a compact encoding of the target in nBits; 'difficulty' is a convenient relative measure, not a field directly stored in the header.
Does difficulty react immediately to hash-rate changes?
No. Between retargets, changes in total hash rate can make blocks arrive faster or slower than the ten-minute average. A retarget does not promise perfectly spaced blocks afterward. Bitcoin testnet networks have special difficulty rules; developers should not assume mainnet retarget logic applies unchanged to every network.
Primary references
Bitcoin Core source — pow.cpp: https://github.com/bitcoin/bitcoin/blob/master/src/pow.cpp
Bitcoin Developer Reference — Block Headers: https://developer.bitcoin.org/reference/block_chain.html
Bitcoin whitepaper, Section 4: https://bitcoin.org/bitcoin.pdf
