Home › Glossary › Timelock

Timelock

Also called: time lock, time-lock, locktime, nLockTime, absolute timelock, relative timelock.

A timelock is a rule that stops bitcoin from being spent until a set block height or time, or until the coin has aged a set amount since it confirmed.

A timelock prevents a transaction or an output from being spent before a certain point. Bitcoin has two kinds, each available as a transaction field and as a Script opcode:

Absolute ("not before X") Relative ("not until N after confirmation")
Transaction field nLockTime nSequence (BIP 68)
Script opcode OP_CHECKLOCKTIMEVERIFY (BIP 65) OP_CHECKSEQUENCEVERIFY (BIP 112)
Measured in Block height or Unix time Blocks or units of 512 seconds
Enforced since Field: 2009; opcode: block 388,381 Block 419,328 (July 2016)

How timelocks work

The transaction fields say when the transaction itself may be mined. nLockTime values below 500,000,000 are block heights and larger values are Unix timestamps. The opcodes go further: they put the condition in the locking script, so the coins can't move until the time has passed, whoever signs. Time-based locks are measured against median time past, the median of the last 11 block timestamps (BIP 113), so miners can't game them by misreporting the time.

What timelocks are used for

  • Lightning channels and HTLCs, which need refund and penalty deadlines.
  • Vaults and inheritance plans, where a backup key only works after a delay.
  • Escrow that times out, and timelocked fidelity bonds (BIP 46).
  • Anti-fee-sniping: many wallets set nLockTime to the current block height.

Compare the two opcodes in BIP 65 vs BIP 112.

BIPs that define Timelock

  • BIP 65: OP_CHECKLOCKTIMEVERIFY: Deployed. Adds OP_CHECKLOCKTIMEVERIFY, a script command that keeps coins unspendable until a chosen date or block height. It enables time-locked savings, escrow with deadlines, and payment channels such as…
  • BIP 68: Relative lock-time using consensus-enforced sequence numbers: Deployed. Gives transactions a "relative lock-time," so a coin cannot be spent until a set number of blocks or amount of time has passed since it was confirmed. This is an essential building block for payment…
  • BIP 112: CHECKSEQUENCEVERIFY: Deployed. Introduces CHECKSEQUENCEVERIFY, a script instruction that lets coins be locked until a certain amount of time has passed since they were received. This 'relative timelock' is a key building block…
  • BIP 113: Median time-past as endpoint for lock-time calculations: Deployed. Changes how Bitcoin measures time for timelocked transactions, using the median time of the previous 11 blocks instead of a single block's timestamp. Because this value only moves forward, miners…
  • BIP 46: Address Scheme for Timelocked Fidelity Bonds: Draft. Defines how HD wallets create time-locked addresses for "fidelity bonds," where coins are locked for a period to prove a costly commitment. Such bonds can help resist fake identities in systems like…

Related terms

  • OP_CHECKLOCKTIMEVERIFY (CLTV): OP_CHECKLOCKTIMEVERIFY (CLTV, BIP 65) is an opcode that keeps an output unspendable until a chosen block height or time: an absolute timelock.
  • OP_CHECKSEQUENCEVERIFY (CSV): OP_CHECKSEQUENCEVERIFY (CSV, BIP 112) is an opcode that blocks spending an output until it has aged a set number of blocks or time since it confirmed.
  • HTLC: An HTLC (hashed time-locked contract) pays whoever reveals a secret before a deadline and refunds the sender after it; Lightning routes payments with them.
  • Vault: A vault holds bitcoin so that withdrawals must wait out a delay, during which the owner can send the coins to a safe recovery address instead.

Learn more

Guides