What are Bitcoin Timelocks?
Bitcoin timelocks are programmable restrictions that prevent a transaction from being spent until a certain condition is met. They are a fundamental building block for advanced Bitcoin applications like payment channels, atomic swaps, and vault systems.
There are two main types of timelocks in Bitcoin: absolute timelocks which lock funds until a specific point in time or block height, and relative timelockswhich lock funds for a period of time after they are received.
Absolute vs Relative Timelocks
Understanding the difference between absolute and relative timelocks is crucial for building Bitcoin applications:
- Absolute timelocks (CLTV) - Lock funds until a specific block height or unix timestamp. Example: "Cannot spend until block 900,000" or "Cannot spend until January 1, 2026"
- Relative timelocks (CSV) - Lock funds for a duration after they are confirmed on-chain. Example: "Cannot spend until 144 blocks after confirmation" (~24 hours)
Absolute timelocks are set at the transaction level using the nLockTime field, while relative timelocks are set per-input using the nSequence field.
CLTV (CheckLockTimeVerify) Explained
CLTV was introduced in BIP65 and enables absolute timelocks in Bitcoin Script. The locktime value is interpreted differently based on its magnitude:
If locktime < 500,000,000 → Block heightIf locktime >= 500,000,000 → Unix timestampFor example, a locktime of 850,000 means the transaction is valid at block 850,000. A locktime of 1735689600 (unix timestamp for Jan 1, 2025) means the transaction is valid after that date.
CSV (CheckSequenceVerify) Explained
CSV was introduced in BIP68 and BIP112 to enable relative timelocks. The sequence number encodes the lock duration in a specific format:
- Bit 31 - If set, relative timelock is disabled
- Bit 22 - Type flag: 0 = blocks, 1 = time (512-second units)
- Bits 0-15 - The lock value (max 65,535 blocks or ~388 days)
For block-based locks, the value represents the number of blocks. For time-based locks, each unit equals 512 seconds (~8.5 minutes). This allows locks up to about 1 year.
Common Use Cases for Timelocks
- Payment Channels - Lightning Network uses timelocks to ensure users can recover funds if a channel partner becomes unresponsive
- Atomic Swaps - Cross-chain trades use timelocks to create trustless refund paths if the swap fails
- Vault Systems - Cold storage vaults use timelocks to create a delay window where unauthorized transactions can be detected and stopped
- Inheritance Planning - Bitcoin can be locked until a future date, enabling trust-minimized inheritance setups
- Escrow - Timelocks can release funds automatically after a deadline, useful for dispute resolution
- DCA (Dollar Cost Averaging) - Lock funds to enforce a savings schedule
Frequently Asked Questions
What is the difference between nLockTime and nSequence?
nLockTime is a transaction-level field that creates absolute timelocks - the transaction cannot be mined until a specific block height or timestamp. nSequence is an input-level field that creates relative timelocks - the input cannot be spent until a certain time has passed since the referenced output was confirmed.
How do I know if a locktime is a block height or timestamp?
Bitcoin uses a simple threshold: values below 500,000,000 are interpreted as block heights, while values at or above 500,000,000 are interpreted as unix timestamps. This threshold was chosen because block 500,000,000 won't be reached for over 9,000 years.
What is BIP68 and why does it matter?
BIP68 defines how the nSequence field enables relative timelocks. Before BIP68, nSequence was only used for transaction replacement (RBF). BIP68 repurposed certain bits to encode a relative lock duration, enabling powerful new Bitcoin applications like Lightning Network.
Can timelocks be combined?
Yes, a transaction can have both an absolute timelock (via nLockTime) and relative timelocks (via nSequence on each input). All conditions must be satisfied for the transaction to be valid. Scripts can also use OP_CLTV and OP_CSV opcodes to add additional timelock conditions.
What happens if I set nSequence to 0xFFFFFFFF?
Setting nSequence to 0xFFFFFFFF (all bits set) disables both relative timelocks and Replace-By-Fee (RBF) for that input. This is the default value for inputs that want no special sequence behavior.
How accurate are timelock estimates?
Block-based timelocks are more predictable than time-based ones because blocks are mined at a variable rate. On average, blocks are mined every 10 minutes, but this can vary significantly. For time-sensitive applications, consider using block heights with a buffer.
Can timelocks be bypassed?
No, timelocks enforced by the Bitcoin protocol cannot be bypassed. Once a transaction has a timelock, it cannot be included in a block until the condition is met. This is enforced by all full nodes on the network through consensus rules.
What is the maximum duration for a relative timelock?
BIP68 relative timelocks use 16 bits for the value, allowing up to 65,535 blocks (~455 days) or 65,535 units of 512 seconds (~388 days) for time-based locks. For longer durations, you would need to use absolute timelocks or chain multiple transactions.
Build with Bitcoin
Spark is a Bitcoin L2 for developers. Instant payments, stablecoins, and programmable money - all on Bitcoin.