Introduction
Bitcoin addresses are derived from cryptographic key pairs through a series of deterministic steps. This guide explains how private keys, public keys, and Bitcoin addresses are generated using Elliptic Curve Cryptography (ECC) and hashing algorithms.
Key Concepts
Bitcoin Addresses
- Designed for usability, as raw public keys are lengthy (130 or 66 characters).
- Address length: 25 bytes, encoded in Base58 to 34β35 characters.
- Base58 avoids visually ambiguous characters (e.g.,
0
,O
,I
,l
) and includes a 4-byte checksum for error detection. - A single public key can yield two addresses due to compressed/uncompressed formats.
Key Types
All keys use Base58Check encoding for ASCII representation:
- Private Key: 256-bit random number.
- Public Key: Derived from the private key via ECC.
- Address: RIPEMD-160 hash of the public key.
Bitcoin Address Generation Process
Step 1: Generate a Private Key
- A 256-bit random number (32 bytes), often created using a cryptographically secure PRNG.
Example:8F72F6B29E6E225A36B68DFE333C7CE5E55D83249D3D2CD6332671FA445C4DD3
π Learn how to securely store private keys
Step 2: Derive the Public Key
Using the elliptic curve equation K = k * G:
- k: Private key.
- G: Constant generator point (secp256k1 curve).
- K: Public key (uncompressed:
04
prefix + X/Y coordinates; compressed:02
/03
prefix + X coordinate).
Example (Uncompressed):
04
06CCAE7536386DA2C5ADD428B099C7658814CA837F94FADE365D0EC6B1519385
FF83EC5F2C0C8F016A32134589F7B9E97ACBFEFD2EF12A91FA622B38A1449EEB
Step 3: Create the Address
- Hash the public key with SHA-256 β RIPEMD-160 (20-byte hash).
- Prepend the network version byte (
0x00
for mainnet). - Append a 4-byte checksum (first 4 bytes of
SHA-256(SHA-256(version + hash))
). - Encode in Base58.
Example:
- RIPEMD-160 Hash:
0b14f003d63ab31aef5fedde2b504699547dd1f6
- Base58Check Address:
121bWssvSgsA9SKjR4DbYncEAoJjmBFwog
Technical Details
Compressed Public Keys
- Store only the X coordinate + a parity byte (
02
or03
). - Reduces size from 520 bits to 264 bits.
Example:
Private Key: de97fdbdb823a197603e1f2cb8b1bded3824147e88ebd47367ba82d4b5600d73
Compressed Public Key: 037c91259636a5a16538e0603636f06c532dd6f2bb42f8dd33fa0cdb39546cf449
Base58Check Encoding
- Purpose: Improve readability/error detection.
- Process: Adds a 4-byte checksum to the data before Base58 encoding.
Example (Private Key):
Hex: de97fdbdb823a197603e1f2cb8b1bded3824147e88ebd47367ba82d4b5600d73
Base58Check: 5KWKSRnmzxCjUP1NKR4dNyyHhaZWSGRTbGzBnm1vwgwpoe2AVGQ
FAQs
1. Why does a public key generate two addresses?
Bitcoin supports compressed and uncompressed public keys, each yielding a unique address.
π Explore Bitcoin wallet security tips
2. How is a private key securely generated?
Use a CSPRNG with high entropy (e.g., hardware RNG or /dev/urandom
). Avoid simple patterns.
3. Whatβs the difference between Base58 and Base64?
Base58 excludes ambiguous characters (0
, O
, I
, l
, +
, /
) for better human readability.
4. Can two private keys generate the same address?
No. The ECC algorithm ensures a 1:1 mapping between private keys and public keys.