Private Key Tools

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.

Only the compressed public key derived from this value may be used: a witness program must be the hash of a 33-byte key. Accepts an optional 0x prefix, spaces and upper case; must be in [1, nโˆ’1].
No input yet

Enter a value above and press Convert. Not sure what to type? Press โ€œUse exampleโ€ to load the sample from the placeholder.

How it works

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:

address = Base58Check( 0x05 โ€– hash160( 0x0014 โ€– hash160(pubkey_compressed) ) )
private key kโ†’ 33-byte compressed pubkeyโ†’ hash160 = witness programโ†’ 0x0014 โ€– program = redeem scriptโ†’ hash160(redeem script) = script hashโ†’ 0x05 โ€– script hash โ€– checksumโ†’ 3โ€ฆ address

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:

Legacy "pay to the script"P2SH
Where the conditions livein the sender's output, in fullonly their hash; the script appears at spend time
scriptPubKey size for a 3-of-3 multisigโ‰ˆ 105 bytes23 bytes, always
Who pays for the large scriptthe sender (at receive time)the spender (at spend time)
Address prefix, mainnetโ€”3โ€ฆ (version byte 0x05)
The "last push is a witness program" rule

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 SegWitAfter SegWit
Signatures live inside the input's scriptSig, which is part of the txid hashSignatures 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 spaceTwo units: base bytes cost 4 weight units, witness bytes cost 1
1 MB block limit4 000 000 weight limit = up to ~4ร— more transactions
Script hash inside the scriptSigWitness 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):

weight = 4 ร— (base bytes) + 1 ร— (witness bytes)   ยท   vB = weight รท 4

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".

SegWit is a soft fork, and witness rules are strict

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:

Nested SegWit was the bridge, not the destination

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:

OffsetLengthBytesMeaning
01 byte0x00OP_0 โ€” pushes an empty array, which doubles as witness version 0
11 byte0x14push the next 0x14 = 20 bytes
2 โ€“ 2120 bytes21f57b6dโ€ฆ9012the witness program: hash160 of the compressed public key
โ€”22 bytes total001421f57b6debcfc5b67182dfb4af1641f0a8189012what 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.

LayerInputOutputDemo value
Hash 133-byte compressed pubkey20-byte witness program21f57b6debcfc5b67182dfb4af1641f0a8189012
Script0x0014 โ€– program22-byte redeem script001421f57b6debcfc5b67182dfb4af1641f0a8189012
Hash 2the 22-byte redeem script20-byte script hash823333d5fd23a83661e8e47629552c4a5bfc8b6e
Encode0x05 โ€– script hash โ€– checksum25 bytes โ†’ Base58Check3DZT76KyKyc5zkzvLugP8umgt4RPY4XPQw

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:

P2SH-P2WPKH input = 41 base bytes + 23 scriptSig bytes โ†’ weight 4ร—64 + 108 = 364 WU = 91 vB
Input typeBase bytesscriptSigWitness bytesWeight (WU)Size (vB)Fee at 10 sat/vB
P2PKH (legacy)36 + 1 + 4 = 4110705921481480 sat
P2SH-P2WPKH (this page)36 + 1 + 4 = 412310836491910 sat
P2WPKH (native)36 + 1 + 4 = 41010827268680 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

P2PKHP2SH-P2WPKHP2WPKH
Mainnet address1โ€ฆ3โ€ฆbc1qโ€ฆ
Version byte / format0x00, Base58Check0x05, Base58Checkwitness v0, bech32
Address length34 chars34 chars42 chars
scriptPubKeyOP_DUP OP_HASH160 <h> OP_EQUALVERIFY OP_CHECKSIGOP_HASH160 <h'> OP_EQUALOP_0 <h>
scriptPubKey size25 B23 B22 B
What the address commits tohash160(pubkey)hash160(0x0014 โ€– hash160(pubkey))hash160(pubkey)
scriptSig when spendingsignature + pubkey (โ‰ˆ107 B)push of the 22-byte redeem script (23 B)empty
Malleability resistantnoyesyes
Input size148 vB91 vB68 vB
Sender must understand bech32nonoyes
Typical era2009 โ€“ today2017 โ€“ 2019 transition2017 โ€“ today

7. Worked example with the demo key

StepValue
Private key k0824c314772b2c2859c889471390a36bf66e53a1ca1642f96f0f2c9307a171ca
Compressed public key (33 B)02ff812e26116a9aa140abe629e7f8a38401653caf925119def59ed3758c67ee80
hash160 = witness program (20 B)21f57b6debcfc5b67182dfb4af1641f0a8189012
Redeem script (22 B)001421f57b6debcfc5b67182dfb4af1641f0a8189012
SHA-256 of the redeem scripta78eb2472f4853354a86bd16be63eb2f5c2a3511b74a40073b3e1973135ec2e6
hash160 of the redeem script (20 B)823333d5fd23a83661e8e47629552c4a5bfc8b6e
Payload = 05 โ€– script hash (21 B)05823333d5fd23a83661e8e47629552c4a5bfc8b6e
Checksum (4 B)acbfef44
Encoded 25 bytes05823333d5fd23a83661e8e47629552c4a5bfc8b6eacbfef44
P2SH-P2WPKH address3DZT76KyKyc5zkzvLugP8umgt4RPY4XPQw
scriptPubKey that pays it (23 B)a914823333d5fd23a83661e8e47629552c4a5bfc8b6e87
Native SegWit sibling from the same keybc1qy86hkm0telzmvuvzm76279jp7z5p3yqjnaerk6
P2PKH sibling from the same key146ZNjH7XTXnMd1ofe3z7CL2i8WM7N2UqT

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

SegWit addresses require compressed keys

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

private key โ†’ compressed pubkeyโ†’ pubkey โ†’ hash160โ†’ 0x0014 โ€– programโ†’ hash160 of the scriptโ†’ Base58Checkโ†’ 3โ€ฆ address

10. Security notes

Never paste a real private key into a page you do not control

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.

11. Common mistakes

12. Quick reference

ItemValue
FormulaBase58Check(0x05 โ€– hash160(0x0014 โ€– hash160(compressed pubkey)))
Redeem script0x00 0x14 โ€– 20-byte hash160(pubkey) = 22 bytes
Script hashhash160 of those 22 bytes
Version byte0x05 mainnet (3โ€ฆ), 0xC4 testnet (2โ€ฆ)
Encoded payload25 bytes = 1 + 20 + 4
scriptPubKeya914 <script hash> 87 = 23 bytes
Input size when spending91 vB (vs 148 P2PKH, 68 P2WPKH)
Derivation path conventionBIP49, m/49'/0'/0'/0/i
Demo address3DZT76KyKyc5zkzvLugP8umgt4RPY4XPQw
Malleability resistantYes โ€” the signature is in the witness, not the txid