TeachMeBitcoin

Bitcoin Timelocks (CLTV, CSV, and nLockTime)

From TeachMeBitcoin, the free encyclopedia Reading time: 3 min

Bitcoin Timelocks (CLTV, CSV, and nLockTime)

A standard Bitcoin transaction settles in approximately 10 minutes. However, Bitcoin contains an extremely rich scripting system that allows users to write smart contracts. One of the most powerful features of these smart contracts is the ability to lock coins in Time.

A Timelock is a protocol-level rule that restricts bitcoins from being spent until a specific block height is reached or a specific date has passed.


️ The Two Axes of Timelocks

To understand Bitcoin’s timelock system, you must look at how they are categorized across two distinct axes:

 ┌───────────────────────┬────────────────────────┐
 │ TRANSACTION-LEVEL │ SCRIPT-LEVEL │
 │ (Locks entire Tx) │ (Locks specific UTXO) │
┌──────────────┼───────────────────────┼────────────────────────┤
│ ABSOLUTE │ nLockTime │ CLTV │
│ (Specific) │ (Header Parameter) │ (BIP 65 Opcode) │
├──────────────┼───────────────────────┼────────────────────────┤
│ RELATIVE │ nSequence │ CSV │
│ (Elapsed) │ (Input Parameter) │ (BIP 112 Opcode) │
└──────────────┴───────────────────────┴────────────────────────┘

Absolute Timelocks: Specific Points in Time

Absolute timelocks dictate that coins cannot be spent until a specific point in history is reached.

1. nLockTime (Transaction-Level)

This is the oldest timelock parameter, embedded directly into the transaction header.

2. CheckLockTimeVerify (CLTV) (Script-Level — BIP 65)

Activated in 2015, CLTV allows developers to embed absolute timelocks directly into the scriptPubKey (locking script) of a UTXO.


⏳ Relative Timelocks: Elapsed Time Since Confirmation

Relative timelocks state that coins cannot be spent until a certain amount of time has elapsed after the previous parent output was mined.

1. nSequence (Transaction-Level — BIP 68)

In 2016, the 4-byte nSequence field inside transaction inputs was repurposed to act as a relative transaction-level lock.

2. CheckSequenceVerify (CSV) (Script-Level — BIP 112)

Activated alongside nSequence, CSV allows relative timelocks to be written inside custom scripts.


⚡ Why Timelocks Are Crucial for Layer-2 Networks

Timelocks are not just simple gimmicks; they are the architectural scaffolding that makes the Lightning Network possible.

In the Lightning Network, users update payment channels off-chain. If your channel partner goes offline, or attempts to cheat by broadcasting an outdated channel balance, you need time to respond and challenge the transaction.

By using CheckSequenceVerify (CSV), the channel script ensures that if a partner broadcasts a state unilaterally, their coins are locked for, say, 144 blocks (24 hours). This relative delay gives your node a 24-hour window to detect the breach, broadcast a penalty transaction, and safely claim all channel funds before their lock expires!

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