TeachMeBitcoin

Marker and Flag Bytes

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

Marker and Flag Bytes

To maintain backward compatibility with old nodes, SegWit transactions use a clever trick involving two special bytes: the Marker and the Flag.

1. The Backward Compatibility Problem

Old nodes (pre-2017) don't know about SegWit. If they see a transaction with an empty ScriptSig and a massive block of data at the end, they might crash or reject the transaction as invalid.

2. The Solution: The "Empty Input" Trick

In a SegWit transaction, the bytes 00 01 are placed immediately after the 4-byte Version number.

Because old nodes see "zero inputs," they assume the transaction is some kind of special "Anyone Can Spend" output and they ignore the data at the end. Modern nodes, however, recognize 00 01 as the signal to look for the Witness.

3. The 0x00 Marker

The Marker is always 0x00. It ensures that the transaction structure is fundamentally different from a legacy transaction, which would have an input count of at least 1 at that position.

4. The 0x01 Flag

The Flag is currently 0x01. This allows for future upgrades to the Witness structure. If Bitcoin ever introduces a second type of witness data, it could use 0x02.

5. Visualizing the Byte Stream

[Version: 01000000]
[Marker: 00]
[Flag: 01]
[Inputs...]
[Outputs...]
[Witness...]
[Locktime: 00000000]
IMPORTANT

The Marker and Flag are stripped when calculating the TXID. This is why SegWit transactions can have a different "Hash" (TXID) than their "Witness Hash" (wTXID).

In the next section, we will discuss the Witness Items and Count.

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