SegWit: How Segregated Witness Changed Bitcoin Transactions

SegWit: How Segregated Witness Changed Bitcoin Transactions

SegWit (Segregated Witness) is a Bitcoin upgrade, specified in BIP 141 (Bitcoin Improvement Proposal 141), that moves the signatures and scripts unlocking an output into a separate witness structure left out of the transaction ID. BIP 141 also changes the block size limit to a block weight limit of 4 million weight units.

What Is the Witness in a SegWit Transaction?

A Bitcoin transaction has a version number, a list of inputs, a list of outputs, and a locktime, a field that holds a block height or a timestamp. Each input names an earlier output by its transaction ID and output index, and it carries data that satisfies that output’s locking script. Each output holds an amount and a locking script.

In a legacy input, the kind used before SegWit, the data that satisfies the locking script sits in a field called the signature script. In a typical input, that data is a signature and a public key. The witness is the same data, kept in a separate place, and it is also called witness data.

SegWit keeps the witness separate from the rest of the transaction. The witness follows the outputs, with one witness per input. A native SegWit output is one whose locking script is only a witness program, so the input that spends it leaves its signature script empty. The address section below explains witness programs.

The signature has not been removed, and upgraded nodes still check it. The ECDSA and Schnorr signatures entry explains what a signature is. A SegWit transaction is a transaction that carries witness data, which happens when it spends a SegWit output.

PartLegacy (before SegWit)In a SegWit transaction
Version<version number><version number>, followed on the network by a marker byte and a flag byte that show the transaction carries witness data
Inputs<previous transaction ID, output index> and a signature script, which in a typical input holds <signature, public key><previous transaction ID, output index> and an empty signature script for native SegWit outputs
Outputs<amount, locking script><amount, locking script>
Witnessn/a<signature, public key> in a typical case, one witness per input, placed after the outputs
Locktime<locktime><locktime>
Hashed to make the transaction IDAll of the parts aboveAll of the parts except the marker, the flag, and the witness

Why Does the Transaction ID Leave Out the Witness?

SegWit gives a transaction two IDs. The transaction ID (txid) is the SHA-256 hash, applied twice, of the transaction without its witness data. The witness transaction ID (wtxid) is the same double SHA-256 hash calculated over the transaction with its witness data included. The wtxid equals the txid when no input carries witness data.

Transaction malleability is the ability of someone other than the sender to change an unconfirmed transaction’s ID without changing what the transaction pays. In a legacy input, the signature does not cover the signature script, so the script can be altered. Altering it changes the txid, which can make a transaction appear to vanish from the network and can invalidate any later transaction that spends it.

SegWit moves the signature data into the witness, so malleability of that data no longer changes the txid. A legacy input’s signature script is still part of the data the txid hashes, because the txid leaves out only the witness. A transaction that spends another by txid therefore keeps the same reference to it when only the witness data changes.

How Do Block Weight and Virtual Size Count Witness Data?

Block weight is the measure SegWit uses to limit how much a block can hold. Each witness byte counts as 1 weight unit, every other byte counts as 4 weight units, and a block may hold at most 4 million weight units. BIP 141 writes the same rule as base size multiplied by 3, plus total size, where base size leaves out witness data and total size includes it.

Before SegWit, a block was limited to 1 million bytes (1 MB) of total size. BIP 141 changes that block size limit to a block weight limit. A witness byte counts for less than any other byte, so the weight rule counts witness data at a discount.

Virtual size is a transaction’s weight divided by 4, rounded up. Its unit is the virtual byte (vbyte). A transaction with no witness data has as many vbytes as it has bytes. A block holds at most 1 million vbytes, which is 4 million weight units divided by 4. That is the same number as the earlier limit of 1 million bytes.

Fee rates are usually quoted per vbyte, in satoshis per virtual byte (sat/vB). One satoshi is 0.00000001 BTC. A transaction’s fee equals its fee rate multiplied by its virtual size, so the witness discount changes the size that the fee rate is applied to.

The numbers below are round numbers chosen for the arithmetic, not a real transaction. They describe a transaction with 100 bytes of non-witness data and 100 bytes of witness data.

  1. Weight: 100 non-witness bytes multiplied by 4 give 400 weight units, and 100 witness bytes multiplied by 1 give 100, so the transaction weighs 500 weight units.
  2. Virtual size: 500 weight units divided by 4 give 125 vbytes.
  3. Comparison: the same 200 bytes with no witness discount, every byte counted as 4 weight units, would weigh 800 weight units and measure 200 vbytes. A fee equals the fee rate multiplied by virtual size, so this example has a virtual size of 125 vbytes. The numbers describe size only, not a real fee.

What Is a SegWit Address, and What Does Native SegWit Mean?

A SegWit address is an address that pays to a witness program. A witness program is a witness version number from 0 to 16 followed by a short block of data of 2 to 40 bytes.

Native SegWit means the witness program makes up the whole locking script of the output, and the spender leaves the signature script empty. Nested SegWit, as BIP 141 calls it, places the witness program inside an ordinary pay-to-script-hash (P2SH) output. A nested address looks like a normal P2SH address and begins with 3, so a sender whose software supports only P2SH can still pay a SegWit receiver. BIP 141 describes the address of a nested witness program as backward compatible with older clients.

Each output type has a standard acronym, and the table says what each one locks the output to.

TypeVersion and programWhat the output locks to
P2WPKHVersion 0, 20-byte programThe hash of one public key
P2WSHVersion 0, 32-byte programThe SHA-256 hash of a script
Nested SegWitWitness program nested in P2SHThe hash of a script that contains the witness program
Taproot, a later soft forkVersion 1, 32-byte programA 32-byte x-only public key

Native SegWit addresses for witness version 0 use the Bech32 format of BIP 173. On the main Bitcoin network they begin with bc1. They are 42 characters long for P2WPKH and 62 characters long for P2WSH.

Witness version 0 outputs use ECDSA signatures, as the ECDSA and Schnorr signatures entry describes. Witness version 1 is Taproot, whose outputs use Schnorr signatures. BIP 141 reserves versions 1 to 16 for future use, and Taproot took version 1.

How Did SegWit Activate as a Soft Fork?

SegWit was deployed as a soft fork, a protocol change that tightens the rules, so some blocks and transactions that were valid before become invalid. Blocks that follow the new rules also pass the old rules, so nodes that have not upgraded keep accepting them.

SegWit’s deployment used BIP 9 (Bitcoin Improvement Proposal 9) version bits, a mechanism in which miners signal support in the version field of the blocks they find. The deployment was named segwit and used bit 1. Its start time was November 15, 2016 at 00:00 UTC, and its timeout was November 15, 2017 at 00:00 UTC. Once at least 1,916 of the 2,016 blocks in one period signaled support, the deployment locked in, and it became active after one further 2,016-block period.

SegWit became active at block 481,824. The block timestamp reads August 24, 2017 at about 01:57 UTC. The miner who found the block sets that timestamp, so the time is approximate.

What Does BIP 141 Not Change?

BIP 141 covers the transaction ID, the witness, and block weight. It does not address the 21 million BTC supply cap or the target of one block every 10 minutes. SegWit is an upgrade to Bitcoin, not a separate network or a separate coin.

A sender does not need SegWit support to pay a legacy address. Wallets without SegWit support can still send to traditional P2PKH addresses, which pay to the hash of a public key, and BIP 141 says older software continues to operate without modification. Legacy, nested, native SegWit, and Taproot address types all exist side by side.

SegWit does not promise a particular fee. The witness discount changes how a transaction’s virtual size is counted, while the fee still equals the fee rate multiplied by that size.

Nodes that have not upgraded do not validate witness data. Only upgraded nodes check SegWit signatures.

November 18, 2026

GoMining News

You might be interested in: