Reviewed Aug 2026
DE
BA-06 · LESSON 10

Native and nested SegWit scripts

KEY DEFINITIONS

Terms used in this lesson

SegWit
Segregated Witness: a Bitcoin upgrade that separates authorization data from the transaction identifier and introduces versioned witness programs.
P2WPKH
Pay to Witness Public Key Hash: a native SegWit output for one public-key hash.
P2WSH
Pay to Witness Script Hash: a native SegWit output that commits to a witness script.
P2SH
Pay to Script Hash, a legacy Bitcoin output template that commits to a redeem script.
Witness
Signatures, scripts, or other data supplied to satisfy a Bitcoin output’s spending condition.
Hash160
SHA-256 followed by RIPEMD-160, producing the 20-byte hash used by several Bitcoin spending conditions.
OP_0
A Bitcoin Script operation that pushes an empty byte string, also used as the version marker for version-zero SegWit programs.
SHA-256
A cryptographic hash function used throughout Bitcoin to produce fixed-size 256-bit digests.
Sighash
The exact transaction digest and signature mode that determine which fields a Bitcoin signature authorizes.
CHECKMULTISIG
The Bitcoin Script operation that checks a threshold number of ordered signatures against a list of public keys.

Construct P2WPKH, P2WSH, P2SH-P2WPKH, and P2SH-P2WSH outputs and follow each redeem, witness, hash, and signature check.

45 min Difficulty 2/5 Not started

Loading lesson visuals...

01

Learn the idea

SegWit outputs use a version byte and witness program. Native P2WPKH and P2WSH put that program directly in ScriptPubKey. Nested P2SH-P2WPKH and P2SH-P2WSH wrap the witness program in a redeem script whose HASH160 appears in P2SH. The ScriptSig then reveals only that witness-program redeem script, while signatures and witness scripts remain in the witness.

GUIDED EXPLANATION1/5 ideas inspected
1

Build native P2WPKH

ScriptPubKey is OP_0 followed by a 20-byte key hash. The witness contains signature and compressed public key. The key hash and SegWit signature both must verify.

Inspect each idea before the worked example.
The worked example follows the explanation

Inspect every idea above to open it.

Important distinctionP2SH-P2WSH stores the complete witness script in ScriptSig.

ScriptSig reveals only the version-0 witness program. The complete witness script appears as the final witness item and must match the program's SHA-256.

02
FINISH LEARNING FIRST

The questions unlock after every required learning activity

Inspect every guided idea, open the worked example, rebuild its mechanism, and complete the deterministic lesson tool. Your progress is saved automatically.