TeachMeBitcoin

Transaction Locktime Overview

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

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."

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.

4. Why Use Locktime?

  1. Post-Dating: You can write a transaction today that "unlocks" your funds for a recipient next year.

  2. Fee Bumping Protection: Locktime is sometimes used in complex protocols to ensure a transaction isn't mined before a certain state is reached.

  3. 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.

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