TeachMeBitcoin

Median Time Past (MTP)

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

Median Time Past (MTP)

To prevent miners from manipulating the clock (for example, by setting a block's time far in the past to influence the difficulty adjustment), Bitcoin nodes use a calculation called Median Time Past (MTP).

1. The Calculation

The MTP is the median timestamp of the last 11 blocks. * Why 11? 11 blocks (roughly 1 hour and 50 minutes) is a large enough window to smooth out any individual miner's clock errors or intentional manipulations. * The Rule: A new block's timestamp must be greater than the Median Time Past of the previous 11 blocks.

2. BIP 113: Consensus Enforcement

Originally, MTP was used for difficulty adjustments, but not for validating transactions. In 2016, BIP 113 made MTP the standard for enforcing Timelocks (nLockTime). * Old Rule: Use the block's actual timestamp. * New Rule: Use the MTP of the previous 11 blocks.

This makes timelocks more predictable and prevents "time-warp" attacks where miners could potentially spend locked coins prematurely.

3. Monotonicity

The MTP rule ensures that the "consensus clock" is monotonic, meaning it only ever moves forward. Even if a miner's local clock is slightly slow, they cannot set a timestamp that is earlier than the average of the recent history.

4. Example Scenario

If the last 11 blocks have these timestamps (simplified): 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150 * The median value is 125. * The next block (Block 12) must have a timestamp of 126 or higher, even if the miner's current local time is 124.

[!NOTE] MTP effectively puts a "floor" on the block time. It ensures that the blockchain history moves forward in a logical, verifiable sequence that cannot be rolled back by a single malicious actor.

Next, we will look at the "ceiling" of the block time: the 2-Hour Future Rule.

☕ 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!