Research·Protocol

How Bitcoin Tells Time

Bitcoin has no clock. Each block carries a timestamp its miner chose, constrained only to be later than a median of recent blocks and no more than two hours ahead of what nodes believe the time is. Height is the reliable ordering; wall-clock time is an approximation the protocol tolerates rather than trusts.

Level
Advanced
Reading
7 min
Published
2026-11-19
Reviewed
2026-11-29

Bitcoin is often described as a timestamp server, and the whitepaper uses that phrase. It is accurate about the purpose and misleading about the mechanism, because the timestamps are not measurements. They are claims, made by whoever produced the block, inside bounds loose enough to be surprising.

What constrains a block’s timestamp?

Two rules, one on each side, and both are wider than people expect.

The lower bound is the median timestamp of the previous eleven blocks, which is also what the difficulty retarget measures against. A new block must be later than that median — not later than its immediate parent. Timestamps can therefore go backwards from one block to the next, and valid chains routinely contain blocks that appear to precede the block before them.

The upper bound is two hours ahead of the validating node’s own network-adjusted time: its system clock, offset by the median difference reported by its peers, with that offset capped. A block further in the future than that is rejected, and may become valid later as the clock catches up.

Inside those bounds the miner chooses. There is no authority to consult and no way for anyone to check whether the choice was honest.

Why is the lower bound a median?

Because any rule depending on a single previous block is a rule one miner can manipulate alone.

A median of eleven requires control of six of them to move, which means the attacker needs sustained majority influence rather than one lucky block. It is a cheap, effective piece of design: the constraint is strong enough to prevent individual manipulation and loose enough that honest miners with imperfect clocks never trip it.

The cost is that the chain’s notion of “now” lags. Median time past is roughly an hour behind the most recent block’s own timestamp, which matters as soon as anything is written against it — a contract that looks like it opens at noon opens somewhat later, and the gap is not fixed.

What did BIP 113 change?

It made timelocks compare against median time past rather than against the block’s own timestamp, and the reason is a nice illustration of the problem.

Before it, a transaction locked until some future time became spendable when a block carried a timestamp past that point. Since the timestamp was miner-chosen and permitted to run up to two hours ahead, a miner could include a transaction before it should have been valid by setting the block’s clock forward. The constraint was real and the party enforcing it was the party who benefited from bending it.

Comparing against the median removes that. A miner cannot move the median alone, so a locktime now means roughly what it says. The practical consequence is that locktimes take effect slightly later than a naive reading suggests, by about the lag described above, and contract designers have to allow for it.

Relative timelocks work the same way, and express their duration either in blocks or in units of 512 seconds — a granularity chosen so the value fits the field, not because anything cares about 512.

So what is the actual clock?

Height. Everything the protocol genuinely depends on counts blocks.

The halving schedule is 210,000 blocks. Difficulty retargets every 2,016 blocks. Soft fork activations have been specified by height. Coinbase maturity is 100 blocks. None of these consults a calendar, and all of them are exact.

Wall-clock time appears in exactly two places that matter: the difficulty calculation, which uses raw timestamps, and timelocks, which use the median. Everything else is counting.

This is why “a halving every four years” is a convenience rather than a fact. Blocks arrive at an average interval set by difficulty, which lands slightly under ten minutes because of an old off-by-one in the retarget arithmetic, so the schedule drifts earlier against the calendar by days per cycle. Anyone quoting a halving date to the hour is quoting a model, and the model’s error grows with every cycle it projects forward.

Where do raw timestamps still bite?

The difficulty retarget, which is the one place the median is not used.

The calculation takes the timestamp of the last block of a period and the timestamp of the first, subtracts, and rescales the target by the ratio. Both are raw, miner-supplied values. A majority attacker can therefore roll timestamps backwards at period boundaries to make periods appear longer than they were, driving difficulty down across repeated retargets — the time warp attack.

It is well understood, the fix is narrow, and it has not shipped, because any consensus change carries its own risk and the attack requires sustained majority hash rate to execute. That calculation is defensible and it is the clearest example on the protocol of a known defect left in place deliberately.

What does network-adjusted time actually do?

A small, old mechanism that is easy to miss and has caused real problems.

A node does not simply trust its own system clock for the upper bound. It asks its peers what time they think it is, takes the median of the offsets, and applies it — within a cap, so that a group of lying peers cannot drag it far. The intent was resilience against a single badly set machine.

The weakness is that it imports a shared opinion. A node surrounded by peers with a consistent wrong clock will shift toward them, and a node whose own clock is badly wrong will reject or accept blocks it should not. Bitcoin Core warns the operator when the adjustment is large, which is the practical mitigation: the software tells you rather than silently compensating.

The deeper point is that this is one of very few places where a node’s behaviour depends on what its peers claim rather than on what it can verify. Everything else in validation is self-contained. Time is the exception, because there is nothing in the chain to check a clock against, and that is the whole reason the bounds around it are so loose.

The practical advice is unglamorous and real: keep the machine’s clock synchronised. A node with a wrong clock is a node making different decisions from everyone else about what is valid right now.

Can a timestamp prove when something happened?

Loosely, and not in the way people reach for.

A transaction in a block has a timestamp, and the honest reading of it is “somewhere in a window of roughly a couple of hours around this, assuming the miner was not lying, and definitely before every subsequent block was produced”. That is useful. It is not a notarised time.

What the chain does prove exactly is order. A transaction in block N happened before everything in block N+1 and after everything in N−1, and that ordering is backed by the accumulated work of every block since. For the purposes the whitepaper cares about — establishing which of two conflicting spends came first — ordering is the whole requirement and calendar time is irrelevant.

Applications that want a real timestamp build it on top: committing a hash into a transaction gives you “this data existed before this block”, which is a one-sided bound and the strongest claim available. It cannot show that something did not exist earlier, because anyone could have held the data and published the commitment later, and no amount of protocol design fixes that — it is a property of what a commitment is.

Check it yourself

The looseness is visible in ordinary blocks and surprises people who have never looked.

# Timestamps of a run of blocks. They do not always increase.
for h in $(seq 800000 800010); do
  bitcoin-cli getblockheader "$(bitcoin-cli getblockhash $h)" | grep -E '"time"|"mediantime"'
done

Run that and compare the two fields. time is the miner’s claim; mediantime is what consensus uses for locktimes, and it lags by roughly an hour. Finding a block whose time is lower than its predecessor’s takes very little searching, and it is the fastest way to stop thinking of the chain as a sequence of clocks.

What remains uncertain

Whether the retarget gets its median. The fix is specified and unshipped, and the governance bar for any consensus change is the reason.

How much clock skew exists in practice. Nodes adjust against their peers within a capped offset, and a network-wide drift would be invisible from inside. Nobody measures it.

What breaks if a majority manipulates timestamps short of a full attack. Mild manipulation is possible and would show up as a small bias in difficulty, which is indistinguishable from variance over short windows.

Whether applications treating block time as authoritative are at risk. Many systems read a block timestamp as a time, including exchanges, accounting tools and smart contract bridges on other chains. The error is bounded and the consequences depend entirely on what was built on top, which nobody has surveyed, and which is exactly the kind of assumption that surfaces only when someone finally has a reason to exploit it.

Sources

Nearby