Level 3 · Advanced
Transaction anatomy and weight
In short
A transaction lists inputs (the coins being spent), outputs (the new coins and who can spend them) and witness data such as signatures. Its size is measured in weight units, where witness bytes count a quarter as much, and a block can hold up to 4 million weight units.
03Transaction anatomy and weightFields, byte layout, witness data, txid vs wtxid, timelocks.10 min
Values are 8-byte integers in sats; most integers are little-endian. SegWit transactions add a marker and flag after the version, and a witness stack per input before the locktime.
- Weight = 4 × non-witness bytes + witness bytes. Blocks are capped at 4,000,000 weight units. vbytes = weight ÷ 4.
- The txid excludes witness data, which fixed third-party malleability; the wtxid includes it.
- Coinbase outputs can't be spent for 100 blocks.
- Timelocks:
nLockTimeandOP_CHECKLOCKTIMEVERIFY(BIP 65) for absolute;nSequenceandOP_CHECKSEQUENCEVERIFY(BIP 68, 112) for relative. Lightning depends on both.
version 4 bytes marker, flag 2 bytes segwit only input count varint prev txid 32 bytes ┐ outpoint prev vout 4 bytes ┘ scriptSig varint + script sequence 4 bytes output count varint value 8 bytes sats scriptPubKey varint + script witness per input segwit only locktime 4 bytes
Learn Bitcoin with real people.
Find meetups and Bitcoiners in your city, and ask the questions you'd never post online. Free to download on iPhone and Android.