
Sequentia Explores: The Mathematics of Crypto
Part VI: Building a Blockchain – The Math of a Distributed Ledger
Lecture 40: How a Bitcoin Address is Really Made (From Private Key to Public Address)
In the world of cryptocurrency, your “address” is like your bank account number. It’s the public information you share with others to receive funds. A typical legacy Bitcoin address looks something like this: 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa.
But where does this seemingly random string of letters and numbers come from? Is it just a random number itself? The answer is no. A Bitcoin address is the final product of a one-way cryptographic pipeline that starts with the only thing that truly matters: your private key.
Today, we’re going to walk through this entire process, step-by-step, and see how our mathematical tools—elliptic curves and hash functions—are used to transform a secret number into a public address.
Step 1: The Private Key (The Ultimate Secret)
Everything begins with the private key.
- What it is: A private key is simply a very large, 256-bit random number. That’s it. Your wallet software generates this number using a cryptographically secure random number generator.
- Analogy: This is the master key to your digital vault. It must be kept absolutely secret. Anyone who knows this number has complete control over your funds.
- Example (in hex): 0xC0FFEE… (a 64-character hexadecimal string)
Step 2: Deriving the Public Key (The ECC Magic)
Next, we use Elliptic Curve Cryptography (ECC) to derive a corresponding public key. As we learned in Lecture 27, this is a one-way process.
- What happens: We take the private key (our large random number, k) and perform point multiplication on the specific elliptic curve used by Bitcoin (called secp256k1). We multiply a special, pre-defined starting point on the curve, called the Generator Point G, by our private key k.
- Public Key (P) = Private Key (k) × Generator Point (G)
- The Result: The result, P, is a new point on the elliptic curve, defined by its (x, y) coordinates. This point is your public key.
- The Trapdoor: It’s easy to calculate P from k, but impossible to calculate k from P (the Elliptic Curve Discrete Logarithm Problem).
Step 3: The Hashing Pipeline (Creating a Fingerprint of the Public Key)
You might think the public key is the address, but it’s not. For added security and to create a shorter, more convenient address, the public key is put through a series of one-way hash functions.
- A) SHA-256 Hash: First, the public key P is run through the SHA-256 hash function.
- Hash_A = SHA-256(Public Key)
- B) RIPEMD-160 Hash: Next, the result of that hash (Hash_A) is run through a different hash function called RIPEMD-160. This function produces a shorter, 160-bit hash.
- Hash_B (Public Key Hash) = RIPEMD-160(Hash_A)
This Hash_B is known as the Public Key Hash (PKH). This is the core fingerprint of your public key. Using two different hash functions adds an extra layer of security; if a weakness were ever found in one, the other would still provide protection.
Step 4: Adding a Version Byte
To the front of our Public Key Hash, we add a version byte. This byte indicates what type of address it is (e.g., a standard public key address, a multi-signature script address, a testnet address). For a standard, legacy Bitcoin address (one that starts with a ‘1’), the version byte is 0x00.
- Payload = Version Byte (0x00) + Public Key Hash
Step 5: The Checksum (A Self-Correcting Mechanism)
How does your wallet know if you’ve made a typo when entering a Bitcoin address? It uses a checksum. This is a short, 4-byte hash that is added to the end of the address to validate its integrity.
- A) Double Hash: The Payload from the previous step is hashed twice with SHA-256.
- Checksum_Hash = SHA-256(SHA-256(Payload))
- B) Take the First 4 Bytes: The first 4 bytes (8 hexadecimal characters) of this final hash are taken as the checksum.
Step 6: The Final Assembly and Base58Check Encoding
We’re almost there! We now assemble the final binary address:
- Final Address (Binary) = Payload + Checksum
(This is the Version Byte + PKH + first 4 bytes of the double-hash)
This long binary number is still not human-friendly. The final step is to encode it using a special encoding called Base58Check.
- What is Base58? It’s similar to the Base-64 encoding used in some data formats, but it omits characters that might be confused with each other. It removes:
- 0 (zero) and O (capital o)
- I (capital i) and l (lowercase L)
- + and /
- This encoding turns the long binary string into the familiar alphanumeric address format that is easier to read, copy, and share, while minimizing the risk of typos. It’s also case-sensitive.
The result of this Base58Check encoding is the legacy Bitcoin address that starts with a ‘1’. (Newer address formats like SegWit/Bech32 that start with bc1 use a similar but more efficient process and encoding).
Summary of the One-Way Street
Private Key -> Public Key -> SHA-256 -> RIPEMD-160 -> Add Version -> Double-Hash for Checksum -> Base58Check Encode -> Public Address
This entire pipeline is a one-way street. It’s easy to go from private key to public address. However, it is impossible to reverse any of these steps. You can’t get the public key from the address (due to one-way hashing), and you certainly can’t get the private key from the public key (due to the ECDLP).
This is why you can safely share your public address with anyone in the world. It reveals no information about your private key, the ultimate secret that grants control over your funds.