THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

Bitcoin Timelocks Explained: CLTV, CSV, nLockTime, and nSequence

permalink THAMER
#bitcoin-timelocks#cltv#csv#nlocktime#nsequence

Bitcoin timelocks restrict when a transaction can be mined or when a particular output can be spent. The distinction matters: transaction-level locktime affects the entire transaction, while Script timelock opcodes constrain the spending conditions of a specific output.

Absolute transaction locktime: nLockTime

A transaction's nLockTime specifies a minimum block height or median-time-past threshold for finality. Values below 500,000,000 are interpreted as block heights; larger values are Unix timestamps. At least one input must have a non-final nSequence for nLockTime to have effect. A transaction with a future nLockTime can be validly constructed yet not currently eligible for confirmation.

Absolute script timelock: OP_CHECKLOCKTIMEVERIFY

BIP65 defines OP_CHECKLOCKTIMEVERIFY (CLTV). CLTV compares a stack value against the spending transaction's nLockTime, checks that both use compatible height/time units, and requires the input sequence not to be final. It does not set nLockTime itself. A wallet constructing the spending transaction must satisfy both the script and transaction-level requirements.

Relative transaction locktime: BIP68

BIP68 interprets certain nSequence bits as relative age constraints for version 2 or higher transactions. Height-based delays count blocks; time-based delays use units of 512 seconds and median-time-past. A sequence disable flag opts out of relative-locktime interpretation. Not every arbitrary sequence number is a relative timelock.

Relative script timelock: OP_CHECKSEQUENCEVERIFY

BIP112 defines OP_CHECKSEQUENCEVERIFY (CSV). CSV constrains the spending input's sequence value and interacts with BIP68 rules. It is useful for delayed recovery paths and channel security. CSV does not independently advance time or guarantee a transaction will be mined as soon as a delay expires.

Engineering example

A vault design might allow an immediate spend with one authorized key and a recovery spend after a relative delay with a different key. The locking script must encode the branches; the spending transaction must select a valid branch and meet its sequence constraints. Exact behavior depends on the script version and consensus rules.

Common mistakes

  • Treating CLTV and CSV as interchangeable: one uses absolute locktime, the other relative age.
  • Assuming nLockTime alone protects an existing UTXO: it restricts a transaction, not every possible alternative spend.
  • Confusing eligibility with confirmation: satisfying a timelock does not ensure miner inclusion.
  • Using wall-clock time in place of Bitcoin's median-time-past semantics.

Primary references

BIP65 — https://bips.dev/65/
BIP68 — https://bips.dev/68/
BIP112 — https://bips.dev/112/
BIP113 — https://bips.dev/113/

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects