Transaction Locktime Overview
Transaction Locktime (nLockTime)
The final 4 bytes of every Bitcoin transaction are reserved for a field called nLockTime. This field allows a user to specify the earliest moment that a transaction can be included in a block.
1. The Concept of "Finality"
By default, most transactions are created with a locktime of 0, meaning they can be mined immediately. However, if a user sets nLockTime to a future block height or date, the transaction is considered "non-final."
-
Mempool Behavior: Nodes will usually not accept a non-final transaction into their mempool.
-
Miner Behavior: Miners will reject any block that contains a transaction whose nLockTime has not yet been reached.
2. Location in the Transaction
In the raw hex data of a transaction, nLockTime is always the last 4 bytes. This is because the nodes need to read the entire transaction structure before determining if it is time-locked.
3. The 4-Byte Format
The field is a 4-byte Unsigned Integer (uint32) stored in Little-Endian.
-
Hex:
00000000-> Locktime 0 (Immediate) -
Hex:
808d5b5d-> A Unix Timestamp
4. Why Use Locktime?
-
Post-Dating: You can write a transaction today that "unlocks" your funds for a recipient next year.
-
Fee Bumping Protection: Locktime is sometimes used in complex protocols to ensure a transaction isn't mined before a certain state is reached.
-
Anti-Fee-Sniping: Modern Bitcoin Core wallets set nLockTime to the current block height by default. This prevents "Fee Sniping," where miners re-mine old blocks to steal transaction fees.
| Property | Value |
|---|---|
| Size | 4 Bytes |
| Position | Final field in the TX |
| Storage | Little-Endian |
| Scope | Transaction-wide |
In the next section, we will discuss the 500 Million Threshold and how it determines if a lock is based on blocks or time.
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: