Bitcoin is often described as digital cash, but few users truly understand how ownership and control work under the hood. Behind every transaction lies a cryptographic lockbox system governed by scripts, addresses, and private keys—not accounts in the traditional sense. This article dives deep into the mechanics of Bitcoin addresses, transaction types like P2PKH, P2SH, and SegWit, and reveals how a simple coding error can permanently lock away funds.
Understanding these principles isn’t just for developers—it’s essential for anyone who wants to securely manage their Bitcoin.
The Three Types of Bitcoin Addresses
Bitcoin supports multiple address formats, each indicating a different type of locking mechanism:
- 1-address (P2PKH): Begins with "1", derived from a public key hash. Most common for basic transactions.
- 3-address (P2SH): Starts with "3", represents a hash of a redeem script. Enables advanced features like multisig.
- bc1-address (Bech32): Native SegWit format starting with "bc1". Offers lower fees and better scalability.
Each address type corresponds to a different kind of "digital safe" on the blockchain—each requiring a unique unlocking method.
👉 Discover how modern wallets securely generate these addresses without risking asset loss.
Bitcoin Doesn’t Transfer Value—It Locks It
One of the most misunderstood aspects of Bitcoin is that there is no actual transfer of coins. Instead, Bitcoin uses an Unspent Transaction Output (UTXO) model where value is locked into script-based conditions.
Think of it this way: when Alice sends BTC to Bob, she doesn’t “send” anything. She creates a new UTXO—like placing funds into a tamper-proof safe—and sets the unlocking condition. Only someone who can satisfy that condition (Bob, with his private key) can spend it later.
Until Bob spends it, the BTC isn’t actively “his” in a legal sense—it’s simply locked in a safe he should be able to open. If he loses his key, the BTC remains locked forever.
This model explains why ownership equals control: whoever holds the private key (or knows the required script) controls the funds.
P2PKH: Pay to Public Key Hash — The Foundation of Bitcoin
The most basic form of locking funds is Pay to Public Key Hash (P2PKH), used by 1-addresses.
Here's how it works:
- Bob shares his 1-address (a Base58-encoded version of
Hash160(public_key)). Alice constructs a locking script:
OP_DUP OP_HASH160 <PubKeyHash> OP_EQUALVERIFY OP_CHECKSIGThis means: “Only someone who can prove ownership of the private key matching this public key hash may unlock.”
When Bob wants to spend, he provides:
- His public key
- A digital signature of the transaction
The network verifies that:
- The public key hashes to the expected value
- The signature matches the public key
This ensures only Bob can spend the funds.
⚠️ Front-running risk? Since the public key is revealed when spending, could miners copy it and steal the funds? No—because the signature covers the entire new transaction, including the output. A copied signature would fail if redirected elsewhere.
P2SH: Pay to Script Hash — Unlocking Advanced Functionality
While P2PKH works for simple payments, P2SH (Pay to Script Hash) allows complex spending conditions while keeping transaction data small.
A 3-address doesn't point to a public key—it points to a redeem script hash. To spend from such an address, you must provide:
- A script whose hash matches the address
- Inputs that make that script evaluate to true
For example, you could create a multisignature wallet requiring 2-of-3 keys to sign off. Or build time-locked contracts.
Why P2SH Was Revolutionary
- Smaller transactions: Senders only reference the script hash, not the full script.
- Privacy: The actual logic stays hidden until spending.
- Flexibility: Supports smart contract-like functionality on Bitcoin.
👉 Learn how secure wallet architectures prevent misused scripts from locking funds permanently.
The PyWallet Bug: When a Typo Locks Your Coins Forever
A real-world case illustrates how fragile this system can be.
The open-source library pywallet, used in some Bitcoin wallets, had a critical flaw: it swapped the prefixes for 1-addresses and 3-addresses.
- Intended 1-address (
0x00prefix) → mistakenly generated as 3-address (0x05) - Result: Funds sent to what appeared to be a standard address were actually locked under P2SH rules
Users tried to unlock them using private keys (P2PKH method), but the network expected a valid redeem script (P2SH). Since no such script existed, the assets were irreversibly locked.
This wasn't a hack—it was a semantic mismatch between expectation and reality.
Can These Funds Be Recovered?
Technically? Only if someone discovers a redeem script that:
- Hashes to the target address
- Executes successfully when run
Given the cryptographic strength of SHA-256 and RIPEMD-160, this is computationally impossible.
Once funds are sent to an invalid or misconfigured 3-address with no known redeem script, they are gone forever.
SegWit: Solving Malleability and Scaling Issues
In 2017, Bitcoin activated Segregated Witness (SegWit) via soft fork—a major upgrade addressing transaction malleability and block space inefficiency.
How SegWit Works
Previously, signatures (the "witness" data) were embedded within transactions, contributing to size and allowing minor alterations (malleability).
SegWit separates witness data from the main transaction, storing it separately. Benefits include:
- Lower fees (witness data counts at ¼ cost)
- Larger effective block capacity
- Elimination of transaction ID malleability
- Foundation for Lightning Network
Address Formats: P2WPKH and P2WSH
Native SegWit uses bech32 addresses (bc1...):
- P2WPKH: Pay to Witness Public Key Hash
- P2WSH: Pay to Witness Script Hash
To maintain backward compatibility, P2SH-wrapped SegWit was introduced:
- A 3-address that actually contains a SegWit-compatible script hash
- Allows older wallets to send to newer formats safely
However, wrapped formats are suboptimal—they don’t fully reduce malleability or maximize fee savings.
zer0to0ne notes:
“If Bitcoin fully adopts native bc1 addresses, we can eliminate P2SH wrapping and achieve maximum efficiency.”
Who Really Owns Your Bitcoin?
Back to our original question: Who controls your Bitcoin—you or your wallet?
The answer depends on the address type:
For 1-Addresses (P2PKH)
You control the funds if you hold the private key. As long as you keep your seed phrase secure and don’t expose your key, you’re in full control.
For 3-Addresses (P2SH)
Control shifts to whoever knows the redeem script. Even if you have the private key(s), without the correct script, you cannot spend.
Many users unknowingly surrender control by:
- Using third-party hosted multisig services
- Relying on wallets that generate scripts behind the scenes
- Losing access to script backups
In short:
🔐 Private key = access
📄 Script = authority
If you don’t know both, you don’t truly own the funds.
Frequently Asked Questions
Q: What happens if I send BTC to a mistyped address?
A: If it’s a valid address (even if not yours), the funds are likely lost forever. Bitcoin has no recovery mechanism.
Q: Can I recover BTC stuck due to a pywallet-like error?
A: No. Without the correct redeem script matching the hash, recovery is cryptographically impossible.
Q: Are 3-addresses less secure than 1-addresses?
A: Not inherently—but they add complexity. Misconfigured scripts or lost scripts lead to permanent loss.
Q: Should I use bc1 addresses?
A: Yes. Native SegWit (bc1) offers lower fees, better security, and future-proofing. Just ensure your wallet supports it fully.
Q: Is my wallet safe if it uses open-source libraries?
A: Open source helps transparency, but audits matter. Libraries like pywallet show that unreviewed code can cause irreversible damage.
Q: How do I verify my wallet generates correct addresses?
A: Use offline tools or trusted explorers to cross-check address types and derivation paths. Never rely solely on one software.
Final Thoughts
Bitcoin’s brilliance lies in its simplicity—but also its opacity. What looks like a simple transfer is actually a sophisticated dance of scripts, hashes, and cryptographic proofs.
The pywallet incident teaches us a vital lesson: software bugs in wallet infrastructure can result in permanent financial loss. Users must understand not just how to use wallets—but how they work.
As Bitcoin evolves with Taproot, Schnorr signatures, and further layer-two innovations, staying informed becomes even more critical.
Remember:
In Bitcoin, you don't own your coins—you own the ability to unlock them.
Keep your keys safe. Know your scripts. And never assume control without verification.