TeachMeBitcoin

The Nested SegWit Redeem Script

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

The Nested SegWit Redeem Script

To "Nest" SegWit inside a P2SH output, we use a very specific Redeem Script. This script acts as a cryptographic trapdoor: to an old node, it is just data, but to a new node, it is an instruction.

1. The Script Template

The Redeem Script for a P2SH-P2WPKH output is exactly 22 bytes long: 00 14 [20-Byte Public Key Hash]

2. On-Chain Footprint

When someone sends you Nested SegWit, they send to a standard P2SH ScriptPubKey: OP_HASH160 [20-Byte Hash of the 22-byte script] OP_EQUAL

Notice how small this is. The sender doesn't even know they are sending to a SegWit address.

3. The Unlocking Script (ScriptSig)

When you spend these coins, your ScriptSig must contain the 22-byte Redeem Script: 16 0014[20-byte-hash]

4. Why 22 bytes?

The 22-byte format is the signal for BIP 141.

  1. The BVM sees a P2SH spend.

  2. It checks the hash. It matches.

  3. It looks at the Redeem Script.

  4. It says: "Wait, this is exactly 22 bytes and starts with 00 14. This is a SegWit spend!"

  5. It then looks in the Witness field for the actual signature and public key.

Component Length Content
Witness Version 1 Byte 0x00
Push Opcode 1 Byte 0x14
PKH Data 20 Bytes The Hashed Identity

In the next section, we will discuss Backward Compatibility Mechanics.

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