TeachMeBitcoin

The Two-Week Retarget Rule

From TeachMeBitcoin, the free encyclopedia โฑ๏ธ 3 min read

The Two-Week Retarget Rule

Bitcoin's difficulty does not change on a minute-by-minute basis. Instead, it adjusts in discrete cycles called Difficulty Epochs. An epoch lasts for exactly 2,016 blocks, which serves as the statistical window used to calculate computing adjustments.


๐Ÿงฎ The Epoch Math: Why 2,016 Blocks?

To understand why 2,016 blocks was selected, we look at the target average block generation time of 10 minutes: * Blocks per Hour: 6 blocks ($60 \text{ minutes} \div 10 \text{ minutes}$) * Blocks per Day: 144 blocks ($6 \times 24 \text{ hours}$) * Blocks per Two Weeks: 2,016 blocks ($144 \text{ blocks} \times 14 \text{ days}$)

Thus, if the network has the perfect amount of hashrate, mining exactly 2,016 blocks should take exactly 2 weeksโ€”or precisely 20,160 minutes (1,209,600 seconds).


โš™๏ธ The Retargeting Formula

At the exact moment block 2,016 (and every subsequent multiple of 2,016, such as 4,032, 6,048, etc.) is mined, every validating full node in the world halts to perform the retargeting calculation.

The formula compares the Actual Time taken to mine the last 2,016 blocks against the Expected Time of 20,160 minutes:

$$\text{New Target} = \text{Old Target} \times \left( \frac{\text{Actual Time in Seconds}}{1,209,600 \text{ Seconds}} \right)$$

Codebase Quirk: The Off-By-One Bug

In Bitcoinโ€™s original C++ source code written by Satoshi Nakamoto, there is a minor math bug. The time difference is actually calculated between the first block of the epoch and the last blockโ€”spanning 2,015 intervals instead of 2,016.

Because fixing this bug would require a hard fork (and because it doesn't harm the network), this off-by-one quirk has been preserved as a consensus rule. Every modern node must implement this exact bug to remain synchronized with the blockchain.


๐Ÿ›ก๏ธ The 4x Dampening Filter (The Max Swing Limit)

If the global hashrate were to suddenly increase by 100x overnight, or if miners maliciously manipulated timestamps to trigger a massive difficulty drop, the network could become highly unstable.

To prevent wild swings, Bitcoin has a built-in safety regulator: the difficulty can never change by more than a factor of 4 in either direction during a single epoch.

       New Target Bound:
       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 0.25  โ”‚  4x Increase Limit    โ”‚  (If actual time < 3.5 days, cap at 0.25)
       โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
 1.00  โ”‚  No Change            โ”‚
       โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
 4.00  โ”‚  4x Decrease Limit    โ”‚  (If actual time > 56 days, cap at 4.00)
       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The adjustment ratio is strictly bound by the following logic: * If $\text{Actual Time}$ is less than 3.5 days (blocks were mined too fast), the ratio is capped at 0.25 (difficulty increases by exactly 4x). * If $\text{Actual Time}$ is greater than 56 days (blocks were mined too slow), the ratio is capped at 4.0 (difficulty decreases by exactly 4x).

Any value calculated outside the range of $[0.25, 4.00]$ is clipped. This ensures that even under extreme circumstances, the network remains stable and difficulty changes gradually and predictably.

โ˜• Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!