Bitcoin Address Generation: From Secret to Public Identifier
A Bitcoin address is a cryptographic fingerprint of an elliptic curve public key paired with a four-byte error-checking checksum. Rather than publishing raw 65-byte public keys on the blockchain, Bitcoin routes funds through double hashes (SHA-256 followed by RIPEMD-160) to keep transactions compact and safeguard quantum privacy until funds are spent.
Your private key derives a public point on the secp256k1 curve, which is double-hashed into a 20-byte public key hash (HASH160). Appending a version byte and a 4-byte double-SHA-256 checksum prevents typing mistakes before Base58 encoding formats it into an address starting with "1".
01. The Plain-Language Analogy: The Postal Drop Box
Think of your private key as the physical brass key in your pocket. Your public key is the internal locking cylinder installed inside the box. Your Bitcoin address is the mailbox slot on the street with your address number stenciled on the front.
Anyone walking down the street can drop a letter or cash envelope through the mailbox slot. If someone tries to send a letter with a botched zip code, the postal sorting scanner rejects it before it leaves the origin facility - that is the address checksum in action. But no matter how many envelopes pile up inside the slot, only the person with the physical brass key can open the back door and retrieve the contents.
02. Step-by-Step Mechanics: The 7-Stage Pipeline
Every standard legacy Pay-to-Public-Key-Hash (P2PKH) Bitcoin address follows an exact mathematical pipeline:
A cryptographically secure random number between 1 and 1.15 × 1077 (2^256 - 1). This secret must never be exposed or generated using predictable seeds.
Multiply the private key scalar by the curve generator point G using elliptic curve point multiplication: K = k × G. In modern wallets, compressed public keys (33 bytes) store the 32-byte x-coordinate prefixed with 02 (if y is even) or 03 (if y is odd).
Hash the 33-byte public key using SHA-256, returning a 32-byte (256-bit) digest.
Hash the 32-byte SHA-256 result with RIPEMD-160. This produces a compact 20-byte (160-bit) hash. Known in Bitcoin Script as HASH160, this dual-hash layer provides defense-in-depth against potential vulnerabilities in either single algorithm.
Add byte 0x00 to the front for Bitcoin Mainnet P2PKH addresses (or 0x05 for P2SH script addresses, 0x6F for Testnet). The payload is now 21 bytes.
Compute SHA-256(SHA-256(versionedPayload)) and take the first 4 bytes. Append these 4 bytes to the 21-byte payload, producing a 25-byte serialized structure.
Encode the 25-byte structure into Base58 characters. The Base58 alphabet excludes characters that look identical in common fonts (0, O, I, l). The result is the final address string (26–35 characters).
import crypto from 'node:crypto';
// 1. Given a compressed public key (33 bytes hex)
const pubKeyHex = '0250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352';
const pubKeyBytes = Buffer.from(pubKeyHex, 'hex');
// 2. SHA-256 hash
const sha256Hash = crypto.createHash('sha256').update(pubKeyBytes).digest();
// 3. RIPEMD-160 hash (HASH160)
const ripemd160Hash = crypto.createHash('ripemd160').update(sha256Hash).digest();
// 4. Prepend Mainnet Version Byte (0x00 for P2PKH)
const versionedPayload = Buffer.concat([Buffer.from([0x00]), ripemd160Hash]);
// 5. Compute 4-byte checksum via Double SHA-256
const firstSHA = crypto.createHash('sha256').update(versionedPayload).digest();
const secondSHA = crypto.createHash('sha256').update(firstSHA).digest();
const checksum = secondSHA.subarray(0, 4);
// 6. Append checksum to versioned payload (25 bytes total)
const binaryAddress = Buffer.concat([versionedPayload, checksum]);
console.log('HASH160:', ripemd160Hash.toString('hex'));
console.log('Checksum:', checksum.toString('hex'));
console.log('25-byte payload ready for Base58 encoding:', binaryAddress.toString('hex')); 03. Worked Example: Hal Finney's Address (Block #170)
This is the actual address belonging to computer scientist Hal Finney that received the 10 BTC transaction from Satoshi Nakamoto on January 12, 2009:
1Q2TWHE3GMdB6BZKafqwxXtWAWgFt5Jvm3 a4325c9cc598000bc14f5fb24446b7db091c7c95 f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16 You can inspect this address on any block explorer to see every satoshi ever sent or spent from it since 2009.
04. Common Misconceptions Corrected
Reality: A Bitcoin address is not a public key; it is a double-hash of the public key with version and checksum metadata. The raw public key is never published to the blockchain until the address spends coins for the first time.
Reality: Base58Check contains an embedded 4-byte double-SHA-256 checksum. The probability of an accidental typo yielding a valid checksum is 1 in 4,294,967,296 (~0.00000002%). Any standard wallet immediately rejects the typo before the transaction can be created.
Reality: Addresses do not exist on the network prior to receiving funds. Any computer offline with zero internet access can generate billions of addresses right now; the blockchain only records an address when a transaction sends funds to its hash.
05. Modern Bitcoin Address Formats
Original 2009 format. Encodes public key hash via Base58Check.
1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa Introduced in BIP 16. Encodes redeem script hash for multisig and SegWit.
3J98t1WpEZ73CNmYviecrnyiWrnqRhWNLy BIP 173. All lowercase, 30–40% lower miner fees, error-correcting BCH codes.
bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 BIP 341 / BIP 350. Schnorr signatures, enhanced privacy, complex contracts.
bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr