LearnBitcoin

Glossary

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 since the first public code in 2009.

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 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 real target 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.

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; 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 next window absorbed it. 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 ended at the next retarget with a 27.9 percent cut, the largest downward step on record, and blocks were back near ten minutes a window later

Corrected

  • 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 . One correction logged for this page.

Edit this page on GitHub