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 SegWit Explained: Witness Data, Weight, and Transaction IDs

permalink THAMER
#bip141#bitcoin-segwit#transaction-weight#txid#witness-data#wtxid

Segregated Witness (SegWit) is a Bitcoin consensus upgrade activated in August 2017. It changes how transaction authorization data is serialized and committed to blocks. For developers, the most important practical distinctions are base transaction data versus witness data, txid versus wtxid, and transaction weight versus raw byte count.

What problem does SegWit address?

In legacy transactions, signatures were embedded in the input scripts and contributed to the transaction identifier. This made certain signature-related changes capable of changing the txid without changing the payment's economic meaning. SegWit moves authorization material for witness programs into a separate witness structure, reducing this form of transaction malleability for SegWit spends.

SegWit does not eliminate every possible form of transaction malleability across all Bitcoin transactions. The exact guarantee depends on the input and transaction construction.

What is witness data?

A SegWit transaction can include a witness stack for each input. A native P2WPKH input typically carries a signature and public key in its witness; a P2WSH input supplies the data needed to satisfy its witness script. Taproot, introduced later, also uses the witness framework but defines version 1 spending rules.

The base transaction still contains inputs, outpoints, outputs, amounts, and other fields. Witness data is not a second payment: it is authorization data for spending an existing output.

What is the difference between txid and wtxid?

The txid is computed from the transaction serialization without witness data. The wtxid commits to the witness-inclusive serialization for witness transactions. This distinction matters when building explorers, tracking transactions, or comparing raw transaction payloads. For transactions without witness data, the identifiers coincide.

How does transaction weight work?

SegWit introduces weight accounting:

weight = (stripped_size × 4) + witness_size

Here, stripped_size is the serialization size without witness data, and witness_size is the difference between total serialized size and stripped size. Virtual size is ceil(weight / 4) in vbytes. Fee rates are commonly quoted in sat/vB.

Illustrative calculation: A transaction with 150 stripped bytes and 110 witness bytes has 710 weight units, or 178 vbytes after rounding up. These numbers are examples, not a recommended fee rate.

How should wallet developers use this distinction?

  • Track both txid and wtxid when your use case requires them.
  • Estimate fees using weight or virtual size, not only total serialized bytes.
  • Treat witness data as spending authorization, not as additional outputs.
  • Check the destination's witness version before assuming the wallet supports it.

Primary references

  • BIP141 — Segregated Witness: https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki
  • BIP143 — Transaction Signature Verification for Version 0 Witness Program: https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki
  • BIP144 — Segregated Witness Peer Services: https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki

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