A timelock stops coins from moving until a time or block height. Bitcoin has four tools, at two levels.
Transaction-level, absolute: nLockTime
Every transaction has a 4-byte nLockTime. Values below 500,000,000 are block heights. Higher values are Unix timestamps. The transaction cannot be mined before then. It only counts if at least one input has an nSequence other than 0xffffffff. Since BIP113 (2016), time locks compare against the median time past of the last 11 blocks, not the block's own timestamp, so miners cannot game it.
Limitation: whoever holds the private key can just make another transaction without the lock.
Script-level, absolute: OP_CHECKLOCKTIMEVERIFY (BIP65)
CLTV, activated in December 2015, redefined OP_NOP2. In a script, <expiry> OP_CHECKLOCKTIMEVERIFY OP_DROP makes the script fail unless the spending transaction's nLockTime is at least the expiry, and of the same type. The coin itself is locked.
Transaction-level, relative: nSequence (BIP68)
nSequence on each input can mean "not until N blocks or N×512 seconds after the output being spent was confirmed". Bit 31 disables it, bit 22 selects time instead of blocks, and the low 16 bits hold the value. This applies only to transactions with version 2 or higher.
Script-level, relative: OP_CHECKSEQUENCEVERIFY (BIP112)
CSV redefined OP_NOP3, and activated together with BIP68 and BIP113 in July 2016. 144 OP_CHECKSEQUENCEVERIFY means the output can only be spent at least 144 blocks (about one day) after it was confirmed.
Where they are used
- Lightning: CSV delays the broadcaster's own outputs, giving the other side time to punish an old state. CLTV sets HTLC deadlines.
- Inheritance and recovery: "my key now, or my heir's key after one year".
- Vaults: delays before withdrawals, with an emergency key.
- Anti fee-sniping: wallets like Bitcoin Core set nLockTime to the current height to discourage miners from rewriting recent blocks.
Watch out: relative timelocks are capped at 65,535 blocks or units, which is about 15 months in blocks.