Level 3 · Advanced
Difficulty, targets and timestamps
In short
Each block header carries a target, and a block is valid only if its hash is at or below that target. A block's timestamp must be later than the median of the previous 11 blocks and no more than two hours ahead, and timestamps set the next difficulty adjustment.
02Difficulty, targets and timestampsnBits, retargeting math, median time past and the off-by-one.8 min
A block is valid only if its double-SHA-256 header hash, read as a 256-bit number, is at or below the target. The header stores the target compactly in nBits: one exponent byte and a three-byte mantissa. The genesis block's 0x1d00ffff defines difficulty 1; difficulty = max target ÷ current target.
- Every 2,016 blocks:
new_target = old_target × actual_time ÷ 1,209,600 s, with the time span clamped to between ¼ and 4× two weeks. - Timestamps must exceed the median time past (median of the previous 11 blocks) and be no more than two hours ahead of a node's clock.
- Quirk: the retarget measures 2,015 intervals, not 2,016, an off-by-one from the original code. Together with loose timestamp rules this enables the “time warp” attack that the Great Consensus Cleanup proposal aims to close.
Learn Bitcoin with real people.
Find meetups and Bitcoiners in your city, and ask the questions you'd never post online. Free to download on iPhone and Android.