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 nLockTime Explained: Block Height, Timestamp, and Transaction Finality

permalink THAMER
#bip113#bitcoin#consensus#nlocktime#transaction-finality

Bitcoin transactions can include a four-byte nLockTime field. It is a constraint on when a transaction becomes eligible for inclusion in a valid block, not a scheduler that broadcasts the transaction automatically. Understanding it requires distinguishing a transaction's locktime from its input sequence numbers and from Script-based spending conditions.

Height versus timestamp

Values below 500,000,000 are interpreted as block heights; values at or above that threshold are interpreted as Unix timestamps. A transaction with a nonzero locktime can become final when its specified height or time is strictly less than the height or time used for evaluation. The threshold does not mean the same integer can be interpreted both ways.

For example, a transaction with nLockTime = 850000 expresses a height-based condition. A transaction with nLockTime = 1800000000 expresses a timestamp-based condition. These are illustrative values, not assurances about the current chain or future inclusion.

Why input sequences matter

If every input has nSequence = 0xffffffff, the transaction is final regardless of nLockTime. At least one input must have a non-final sequence for locktime to constrain finality. This interaction is easy to miss when software sets the locktime field but leaves all sequences at their maximum value.

An input sequence may also carry relative-locktime meaning under BIP68, but absolute nLockTime and relative sequence locks are different checks. A transaction can be subject to both. Transaction version, sequence flags, and the context of validation determine which rules apply.

Median-time-past and BIP113

For time-based finality, Bitcoin consensus uses the median time past (MTP) of the previous block, rather than relying directly on a miner's proposed block timestamp. BIP113 made this approach part of consensus. The median of recent block timestamps is not a wall-clock guarantee, and the comparison is strict: reaching the locktime value is not the same as exceeding it.

For height-based finality, the candidate block height is the relevant context. A mempool may reject a non-final transaction before miners can validly include it, and relay policy can differ from what an eventual block will accept.

Practical validation checklist

A wallet should check the intended height/time unit, verify at least one sequence is non-final, distinguish absolute and relative conditions, and evaluate against chain state. It should not tell a user that a locktime guarantees execution at a particular moment: fee conditions, propagation, miner selection, and chain reorganizations still matter.

Primary references

Bitcoin developer reference — Transactions: https://developer.bitcoin.org/reference/transactions.html

BIP113 — Median time-past as endpoint for lock-time calculations: https://github.com/bitcoin/bips/blob/master/bip-0113.mediawiki

Bitcoin Core consensus validation source: https://github.com/bitcoin/bitcoin/blob/master/src/consensus/tx_verify.cpp

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