Private key โ P2SH-P2WPKH address (nested SegWit)
The 3โฆ nested-SegWit address: hash the compressed public key, wrap the 20 bytes as 0x0014โprogram, hash that 22-byte script again, and Base58Check the result with version byte 0x05. Six layers, all of them shown.
Enter a value above and press Convert. Not sure what to type? Press โUse exampleโ to load the sample from the placeholder.
What this page computes
This is the nested SegWit address: SegWit locking logic hidden inside a P2SH wrapper so
that it produces an ordinary-looking 3โฆ address. There are six layers, and this page prints every
one of them:
Because the inner value is hashed twice โ once as the public key, once as the redeem script โ this address type lives in a slightly awkward middle ground between legacy P2PKH and native SegWit. The comparison table near the end quantifies exactly how much that costs.
1. P2SH: pay to script hash
P2SH was added by BIP16 and activated on 1 April 2012. Before it, a sender had to reproduce the
recipient's full spending conditions in the output: a multi-signature address, for example, meant putting the whole
2 <key> <key> <key> 3 OP_CHECKMULTISIG program โ hundreds of bytes โ into the
transaction, and paying for them.
P2SH inverts that. The output commits only to the hash of a script, and the script itself is revealed only when the coins are spent:
P2SH scriptPubKey: OP_HASH160 <20-byte script hash> OP_EQUAL
the spender later supplies: <...the full redeem script...>
The rules that make this safe are the interesting part:
- The spender's unlocking script must contain the redeem script whose hash matches, plus whatever that script requires to be satisfied.
- The interpreter hashes the supplied script, compares it with
OP_EQUAL, and only then executes the script as a program of its own. - The redeem script is not part of the address. An address is only a hash, so it cannot tell you what the spending conditions are โ a subtlety that matters for the whole SegWit design.
| Legacy "pay to the script" | P2SH | |
|---|---|---|
| Where the conditions live | in the sender's output, in full | only their hash; the script appears at spend time |
| scriptPubKey size for a 3-of-3 multisig | โ 105 bytes | 23 bytes, always |
| Who pays for the large script | the sender (at receive time) | the spender (at spend time) |
| Address prefix, mainnet | โ | 3โฆ (version byte 0x05) |
BIP141 added one extra consensus rule on top of P2SH: when a P2SH spend's unlocking script consists of exactly
one push, and the pushed bytes look like a valid witness program (a version byte plus a 2โ40 byte program), the
script is not executed in the legacy way. Instead the transaction's witness is validated against that
program. That single rule is what makes nested SegWit possible โ the same 3โฆ-style output can carry
either a legacy redeem script or a witness program.
2. What SegWit changed
SegWit ("segregated witness", BIP141, activated 24 August 2017) moved the signature data โ the witness โ out of the structure that the transaction ID is computed over, and gave it a cheaper accounting unit:
| Before SegWit | After SegWit |
|---|---|
| Signatures live inside the input's scriptSig, which is part of the txid hash | Signatures live in a separate witness field, not covered by the txid |
| Any third party could alter a signature's encoding and change the txid (malleability) | The txid is stable before confirmation โ a prerequisite for Lightning |
| One size unit: 1 byte = 1 byte of block space | Two units: base bytes cost 4 weight units, witness bytes cost 1 |
| 1 MB block limit | 4 000 000 weight limit = up to ~4ร more transactions |
| Script hash inside the scriptSig | Witness program in the scriptPubKey: OP_0 <20 or 32 bytes> |
The size accounting is the part you can feel in your fees. Weight is measured in weight units (WU) and the effective size in virtual bytes (vB):
So every witness byte costs a quarter of what a base-layer byte costs, which is why SegWit inputs are cheaper
to spend. A native P2WPKH output is simply OP_0 <20-byte hash160> โ 22 bytes, no OP_DUP,
no OP_CHECKSIG, nothing to execute beyond "the witness must satisfy this program".
Old nodes still see a witness output as "anyone can spend" and would happily accept a transaction that ignores the witness. The witness rules are enforced only by upgraded nodes, which is why segwit spends are judged against a stricter flag set: uncompressed public keys, for instance, are not allowed inside witness programs (see the mistakes section).
3. Why nested SegWit exists at all
SegWit's native address format is bech32: bc1qโฆ. In 2017 that was a new string format that older
wallets, exchanges and payment processors simply did not understand โ many would reject it as invalid, and some
would refuse to send to it at all.
Nested SegWit (3โฆ) solved the deployment problem, not a cryptographic one:
- A
3โฆaddress is indistinguishable from an ordinary P2SH address. Any wallet that could already pay a multisig3โฆaddress needed no upgrade to pay a SegWit one โ the sender does not have to understand witness at all. - The recipient gets the SegWit benefits: signature malleability is gone and the spend is discounted by the weight rule. (The recipient pays the fee on the way out, so they keep the saving.)
- The trade-off is real: the wrapper adds a 22-byte redeem script to the scriptSig and an extra hash, so
nested SegWit is more expensive than native
bc1qโฆ. BIP49 standardised the derivation pathm/49'/0'/0'/0/iso that wallets could restore these addresses deterministically.
It gave the ecosystem a way to adopt SegWit gradually: receiver upgrades first, senders follow whenever they
feel like it. Today bech32 support is universal in maintained wallets, so new wallets default to
bc1qโฆ; nested SegWit remains common for restored 2017โ2019 wallets and for services that adopted it
during the transition.
4. The redeem script, byte by byte
The redeem script is the smallest valid witness program there can be for a single key โ 22 bytes, and every one of them is accounted for:
| Offset | Length | Bytes | Meaning |
|---|---|---|---|
| 0 | 1 byte | 0x00 | OP_0 โ pushes an empty array, which doubles as witness version 0 |
| 1 | 1 byte | 0x14 | push the next 0x14 = 20 bytes |
| 2 โ 21 | 20 bytes | 21f57b6dโฆ9012 | the witness program: hash160 of the compressed public key |
| โ | 22 bytes total | 001421f57b6debcfc5b67182dfb4af1641f0a8189012 | what gets hashed for the P2SH script hash |
Two details are worth noticing. First, the version byte is OP_0, not a separate "version" field โ
the witness version is encoded as a small script number, which is why v1 (Taproot) starts with OP_1
(0x51) and uses bech32m instead of bech32. Second, this 22-byte string is identical to a native
P2WPKH scriptPubKey: the same program is used two different ways, once directly in the output and once wrapped
inside a P2SH hash.
redeem script (22 bytes) = 00 14 21f57b6dโฆ9012
P2SH scriptPubKey (23 bytes) = a9 14 823333d5โฆ8b6e 87
โ โ โโ 20-byte hash160(redeem script)
โ โโโโโ push 20 bytes
โโโโโโโโ OP_HASH160 โฆ OP_EQUAL (87)
5. The double hashing, and what it costs
For a native P2WPKH address the chain is: hash the key once, bech32-encode the 20 bytes. For a nested address the chain is: hash the key, build the 22-byte script, hash that, then Base58Check-encode the second hash. Two hash operations over two different inputs produce two unrelated 20-byte values โ and the second one is what the address carries.
| Layer | Input | Output | Demo value |
|---|---|---|---|
| Hash 1 | 33-byte compressed pubkey | 20-byte witness program | 21f57b6debcfc5b67182dfb4af1641f0a8189012 |
| Script | 0x0014 โ program | 22-byte redeem script | 001421f57b6debcfc5b67182dfb4af1641f0a8189012 |
| Hash 2 | the 22-byte redeem script | 20-byte script hash | 823333d5fd23a83661e8e47629552c4a5bfc8b6e |
| Encode | 0x05 โ script hash โ checksum | 25 bytes โ Base58Check | 3DZT76KyKyc5zkzvLugP8umgt4RPY4XPQw |
At spend time the scriptSig must carry that 22-byte script (1 push opcode + 22 bytes = 23 bytes) so the network can hash it and see the witness program. Those 23 bytes sit in the base part of the transaction and cost 4 weight units each, which is the whole reason nested SegWit is not as cheap as native:
| Input type | Base bytes | scriptSig | Witness bytes | Weight (WU) | Size (vB) | Fee at 10 sat/vB |
|---|---|---|---|---|---|---|
| P2PKH (legacy) | 36 + 1 + 4 = 41 | 107 | 0 | 592 | 148 | 1480 sat |
| P2SH-P2WPKH (this page) | 36 + 1 + 4 = 41 | 23 | 108 | 364 | 91 | 910 sat |
| P2WPKH (native) | 36 + 1 + 4 = 41 | 0 | 108 | 272 | 68 | 680 sat |
Nested SegWit therefore saves about 57 vB (38%) against legacy P2PKH but still pays 23 vB (25%) more than native bech32. The output side is smaller in both SegWit cases, because the scriptPubKey is shorter: 32 bytes for a P2SH output, 31 for P2WPKH, 34 for P2PKH.
6. Comparison table
| P2PKH | P2SH-P2WPKH | P2WPKH | |
|---|---|---|---|
| Mainnet address | 1โฆ | 3โฆ | bc1qโฆ |
| Version byte / format | 0x00, Base58Check | 0x05, Base58Check | witness v0, bech32 |
| Address length | 34 chars | 34 chars | 42 chars |
| scriptPubKey | OP_DUP OP_HASH160 <h> OP_EQUALVERIFY OP_CHECKSIG | OP_HASH160 <h'> OP_EQUAL | OP_0 <h> |
| scriptPubKey size | 25 B | 23 B | 22 B |
| What the address commits to | hash160(pubkey) | hash160(0x0014 โ hash160(pubkey)) | hash160(pubkey) |
| scriptSig when spending | signature + pubkey (โ107 B) | push of the 22-byte redeem script (23 B) | empty |
| Malleability resistant | no | yes | yes |
| Input size | 148 vB | 91 vB | 68 vB |
| Sender must understand bech32 | no | no | yes |
| Typical era | 2009 โ today | 2017 โ 2019 transition | 2017 โ today |
7. Worked example with the demo key
| Step | Value |
|---|---|
| Private key k | 0824c314772b2c2859c889471390a36bf66e53a1ca1642f96f0f2c9307a171ca |
| Compressed public key (33 B) | 02ff812e26116a9aa140abe629e7f8a38401653caf925119def59ed3758c67ee80 |
| hash160 = witness program (20 B) | 21f57b6debcfc5b67182dfb4af1641f0a8189012 |
| Redeem script (22 B) | 001421f57b6debcfc5b67182dfb4af1641f0a8189012 |
| SHA-256 of the redeem script | a78eb2472f4853354a86bd16be63eb2f5c2a3511b74a40073b3e1973135ec2e6 |
| hash160 of the redeem script (20 B) | 823333d5fd23a83661e8e47629552c4a5bfc8b6e |
Payload = 05 โ script hash (21 B) | 05823333d5fd23a83661e8e47629552c4a5bfc8b6e |
| Checksum (4 B) | acbfef44 |
| Encoded 25 bytes | 05823333d5fd23a83661e8e47629552c4a5bfc8b6eacbfef44 |
| P2SH-P2WPKH address | 3DZT76KyKyc5zkzvLugP8umgt4RPY4XPQw |
| scriptPubKey that pays it (23 B) | a914823333d5fd23a83661e8e47629552c4a5bfc8b6e87 |
| Native SegWit sibling from the same key | bc1qy86hkm0telzmvuvzm76279jp7z5p3yqjnaerk6 |
| P2PKH sibling from the same key | 146ZNjH7XTXnMd1ofe3z7CL2i8WM7N2UqT |
Notice that the native and nested siblings share the same 20-byte witness program
21f57b6dโฆ9012, yet produce completely different addresses โ and, from the outside, an unrelated-looking
scriptPubKey. Only the nested one is wrapped in a second hash.
8. What this address is not
- Not a multi-signature address.
3โฆis the P2SH prefix, and multisig wallets use it too. Nothing in the string tells you whether the hidden script is a single-key witness program or a 2-of-3 multisig. - Not automatically cheaper than
bc1qโฆ. It saves against legacy P2PKH only. If the recipient's wallet supports bech32, native is cheaper and simpler for everybody. - Not a way to hide anything. When the coins are spent, the redeem script is published in the scriptSig and the witness program in the witness. The address only delays transparency until the first spend; the blockchain is public forever.
- Not interchangeable with its siblings when restoring. A wallet that only derives
1โฆandbc1qโฆaddresses will not see coins sitting at3โฆ, even with the right seed. Worse, there is no way to guess from the address alone which of the P2SH flavours it is โ the wallet must be told to derive nested SegWit.
The witness program must be the hash of a 33-byte compressed public key. Hashing a 65-byte uncompressed key
and building a 3โฆ address from it produces a valid-looking string that standardness policy will not
let you spend. If you are sweeping a 2009-era key, derive the compressed public key first โ see
the uncompressed page for why that distinction exists.
9. Where this fits in the chain
- Same key, other wrappers: P2PKH compressed, P2PKH uncompressed, native P2WPKH, Taproot P2TR.
- Inspect the wrapper without a private key: Base58Check decoder shows the
0x05version byte and the 20-byte script hash. - Decode the inner program: the bech32 page shows the same 20 bytes as witness v0 in
bc1qโฆform.
10. Security notes
Whoever sees the key can spend from every address derived from it โ the 3โฆ address included,
because the wallet can always reveal the redeem script. This server computes locally in PHP and logs nothing,
but the guarantee ends with the operator. Use an offline tool or a hardware wallet for real funds.
- P2SH hides the spending conditions, not the amounts or the addresses. Privacy comes from using fresh addresses per payment, not from the wrapper.
- The 4-byte Base58Check checksum on a
3โฆaddress catches typos with probability 1 โ 2-32; it is not a signature and cannot protect against a substituted address. - Verify that the wallet you intend to restore from a seed actually derives nested SegWit addresses before you conclude that funds are missing.
11. Common mistakes
- Assuming
3โฆmeans multisig. Since 2017 most3โฆaddresses in the wild are single-key nested SegWit. - Expecting nested SegWit fees to match bech32. The extra 22-byte redeem script and the second hash make it strictly more expensive than native SegWit.
- Using an uncompressed key's hash as the witness program. Valid-looking address, unspendable in practice.
- Restoring a seed into a wallet with the wrong script-type list. BIP49
(
m/49'/0'/0'/0/i) exists precisely so nested addresses are reproducible; a BIP44-only wallet will show zero. - Assuming the redeem script is in the address. It is not โ the address is a hash, and the script only appears when the coins move.
12. Quick reference
| Item | Value |
|---|---|
| Formula | Base58Check(0x05 โ hash160(0x0014 โ hash160(compressed pubkey))) |
| Redeem script | 0x00 0x14 โ 20-byte hash160(pubkey) = 22 bytes |
| Script hash | hash160 of those 22 bytes |
| Version byte | 0x05 mainnet (3โฆ), 0xC4 testnet (2โฆ) |
| Encoded payload | 25 bytes = 1 + 20 + 4 |
| scriptPubKey | a914 <script hash> 87 = 23 bytes |
| Input size when spending | 91 vB (vs 148 P2PKH, 68 P2WPKH) |
| Derivation path convention | BIP49, m/49'/0'/0'/0/i |
| Demo address | 3DZT76KyKyc5zkzvLugP8umgt4RPY4XPQw |
| Malleability resistant | Yes โ the signature is in the witness, not the txid |