Bitcoin TXID vs WTXID Explained: Witness Data and Transaction Identity
A SegWit transaction can have two identifiers because its witness data is separated from the traditional transaction serialization. This distinction matters when tracking transactions, constructing descendants, and verifying block commitments.
TXID: the traditional identifier
The TXID is the double-SHA256 hash of the transaction serialized without witness data. Its human-readable hexadecimal representation is conventionally displayed with reversed byte order relative to the internal hash bytes. Outpoints refer to a previous transaction by TXID and output index, not by WTXID.
WTXID: the witness-inclusive identifier
For a transaction serialized with witness data, the WTXID is the double-SHA256 hash of its witness serialization, including the marker, flag, and witness fields. For transactions without witness data, WTXID equals TXID. The coinbase transaction's WTXID is treated as 32 zero bytes when building the witness Merkle tree for the block commitment.
Why the difference matters
Changing witness bytes can change the WTXID without changing the TXID, although signatures and consensus rules restrict what modifications are valid. SegWit moved signature material out of the TXID commitment and addressed the major historical form of third-party transaction malleability; it does not mean every transaction is impossible to replace or that every script has identical malleability properties.
The block header commits to the traditional transaction Merkle root. A SegWit block also includes a witness commitment in a coinbase output, binding the witness Merkle root together with a 32-byte witness reserved value.
Common developer mistakes
Do not identify a UTXO using WTXID. Do not calculate the TXID by hashing a SegWit raw transaction with its witness bytes still included. When debugging a block, distinguish the transaction Merkle root from the witness commitment.
Primary references
Bitcoin Developer Reference — Transactions: https://developer.bitcoin.org/reference/transactions.html
BIP141 — Segregated Witness: https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki
BIP144 — Segregated Witness Peer Services: https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki
