Skip to content
LearnBitcoin

LearnGlossary

Difficulty Adjustment

The automatic recalibration of Bitcoin's mining difficulty every 2,016 blocks, also called retargeting, that keeps the average block interval near ten minutes. The new difficulty is the old one scaled by two weeks divided by the time the last window took, clamped to a factor of four either way.

Difficulty adjustment, also called retargeting, is the mechanism that keeps Bitcoin's average block time near ten minutes whatever the hash rate does. It is two short functions in src/pow.cpp, GetNextWorkRequired and CalculateNextWorkRequired, and the rule has not changed in substance since the first public code in 2009. The only edit, in July 2010, changed what a window measured as running backwards would do, and no window ever has.

The rule:

  • Every 2,016 blocks, about two weeks at ten minutes each, every node computes how long the window just finished actually took: the timestamp of its last block minus the timestamp of its first.
  • The new difficulty is the old one scaled by two weeks divided by that span. Blocks came too fast, difficulty goes up; too slow, it goes down. The target, the number a block hash must fall under, moves the other way.
  • The span is clamped to between a quarter and four times two weeks before the division, so no single adjustment can move difficulty by more than a factor of four in either direction. The upper clamp has bound once, at block 68,544 on July 16, 2010, when a window took 3.35 days; the lower one never has.
  • The new value takes effect on the first block of the next window and holds for 2,016 blocks. Between retargets nothing adjusts, however long blocks take.

Two quirks are worth knowing. The window's first and last block are 2,015 intervals apart, not 2,016, and the code compares that span with 2,016 times ten minutes anyway. Satoshi's off-by-one makes the target, by simple division, ten minutes and three tenths of a second, and once the statistics of dividing by a measured span are worked through, closer to ten minutes and six tenths. Nobody has noticed in practice, because hash rate has grown for most of Bitcoin's life and blocks have averaged under ten minutes regardless. The second quirk is more serious. The windows do not overlap, so the first timestamp of one window is never checked against the last timestamp of the window before it. That seam is the time warp attack, and closing it is the first rule of the Consensus Cleanup soft fork proposal. The timestamps themselves are bounded by the block timestamp rules: a median floor and a two-hour ceiling. Both quirks come from one line of Satoshi's 0.1.0 code, and The Time Warp traces them from the November 2008 draft to what a majority miner could do with the seam today.

There is no committee and no override. The network observes its own block times and corrects, on a fixed schedule, forever. A new mining farm does not change the issuance schedule; it triggers a higher difficulty at the next retarget, and everyone else's share of the blocks shrinks to match.

The mechanism has held through everything so far. China's 2021 mining ban took roughly half the hash rate offline; difficulty fell at four retargets in a row, 45 percent in all. The window that ended on July 3, 2021 ran at 13.9 minutes a block, and the retarget at block 689,472 cut difficulty by 27.9 percent, the largest downward step on record. The next window ran at 10.5 minutes. The 2022 bear market thinned the miners, and four halvings have each halved their subsidy overnight, and in every case the retargets absorbed it within two windows. The counting-in-blocks design does have a failure mode on paper: a chain that lost most of its hash rate at once would wait a long time for the retarget that saves it. That is the chain death spiral, and it is why minority forks such as Bitcoin Cash in 2017 bolted on an emergency difficulty adjustment, with results that argue for the slow window.

See the live current epoch progress and next-adjustment estimate in the Mining rabbit hole section 4 or on the Node page.

Key takeaways

  • Every 2,016 blocks (about two weeks) every node rescales the difficulty by two weeks divided by the time the window just finished took, measured from its first block's timestamp to its last; the ratio is clamped between a quarter and four
  • The window measures 2,015 intervals against a 2,016-interval target and does not overlap the previous window; the first is a harmless off-by-one, the second is the seam the time warp attack uses
  • No event has broken it: the 2021 loss of roughly half the hash rate took four downward retargets in a row, 45 percent in all, the largest a 27.9 percent cut on July 3, 2021, the biggest on record; blocks were back near ten minutes the window after it

On the mailing list

Topic timelines: Time warp, timestamps and the consensus cleanup (59 threads) and Mining and pools (224 threads).

Corrected

  • Was: The entry said the 2021 loss of half the hash rate ended at the next retarget, that the rule has not changed since 2009, and that after each halving the next window absorbed the change.

    Now: Difficulty fell at four retargets in a row in 2021, 45 percent in all, the largest a 27.9 percent cut on July 3. The rule has not changed in substance; a July 2010 commit changed what a backwards window would do, and none has ever run backwards. After each halving the retargets absorbed it within two windows. The entry adds that the upper clamp has bound once, at block 68,544 on July 16, 2010. Details

  • Was: The entry said each difficulty adjustment is clamped at +/-300%.

    Now: Bitcoin Core limits each adjustment to a factor of four either way, so at most +300% up or -75% down in one step. Details

Sources (7)

External references (3)

Related terms (18)

Published . Revised . Two corrections logged for this page.

Edit this page on GitHub