Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 41 ยท Cryptography Foundations

Keys, Addresses and Wallets

Follow a blockchain identity from private key to public key to address, learn Base58Check checksums, seed phrases and HD wallets, and why custody matters.

When you "have a wallet", what do you actually have? Not coins: coins exist only as entries on the shared ledger. A wallet is software or hardware that holds your private keys, builds transactions and signs them. Everything else, from your address to your balance display, is derived from those keys or read from the chain.

This lesson follows the full path from a secret number to the string you paste into an exchange to receive funds: private key, public key, address. Along the way you will see why addresses carry a checksum, why most wallets show a list of words instead of a raw key, and how one phrase can generate an endless family of addresses. Everything is built live with the tools from the last few lessons: hashing and the secp256k1 curve. The code here is a teaching version. It mirrors the real structure but swaps some real ingredients for simpler ones, and each swap is labeled.

The derivation chain

flowchart LR
    R["Randomness<br/>(256 bits)"] --> K["Private key d"]
    K -->|"d x G on the curve"| Q["Public key Q"]
    Q -->|"hash"| H["Public key hash"]
    H -->|"version + checksum<br/>+ Base58"| A["Address"]

Each arrow is a one-way step: you can always go left to right, but never recover the previous item from the next.

  1. The private key is a random number between 1 and the curve order n.
  2. The public key is the curve point Q = d * G.
  3. The address is a shorter, safer-to-handle fingerprint of the public key. Hashing shrinks it to a fixed size and also hides the public key itself until you spend, which gives a small extra layer of protection.

Each step only goes forward. Seeing an address never reveals the key behind it.

From private key to address

In Bitcoin the common address format is built like this: take the compressed public key (33 bytes: a prefix byte 02 or 03 that records whether y is even or odd, followed by the 32-byte x), compute RIPEMD-160(SHA-256(pubkey)) to get a 20-byte hash, put a version byte in front, append a 4-byte checksum, and encode the result in Base58.

The example below follows exactly that structure. The one change: Python's hashlib in the browser may not include RIPEMD-160, so the "hash160" step here uses the first 20 bytes of SHA-256 instead. The resulting address is therefore not a real Bitcoin address, but every other step is the genuine process.

Python Private key to public key to address

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The private key can be converted into the public key and address at any time. Nothing travels backward. Ethereum follows the same shape with different ingredients: the address is the last 20 bytes of the Keccak-256 hash of the uncompressed public key, written in hexadecimal, usually with a 0x prefix. (Keccak-256 is the original submission for the SHA-3 competition, and it differs from the final standardized SHA-3 in padding, so Python's hashlib.sha3_256 does not produce Ethereum addresses.)

Hex versus Base58, and why checksums matter

The same 25 bytes can be written in different ways. Hexadecimal is simple and common (Ethereum uses it). Base58 was designed by Bitcoin's creator for human use: it drops the characters that are easy to confuse (0 zero, O capital o, I capital i, l lowercase L) and the symbols + and /, so the text survives being read aloud, typed and double-clicked.

Money addresses also need error detection. One mistyped character could send funds to nowhere. Base58Check appends the first four bytes of a double SHA-256 hash of the payload. A single wrong character changes the recomputed checksum, so wallets reject the address before a transaction exists. The chance that a random typo still passes is about one in four billion.

Python Base58 and checksum error detection

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Not every format has one built in. Ethereum originally had none, so a mixed-case convention (EIP-55) was added in which the upper and lower case letters of the hex address encode a checksum.

Seed phrases: one backup for many keys

Raw 256-bit numbers are terrible for humans to write down. A seed phrase (also called a recovery phrase or mnemonic) encodes random bytes as ordinary words. The widely used standard, BIP-39, maps 128 bits of randomness plus a 4-bit checksum onto 12 words chosen from a fixed list of 2,048 words (11 bits per word). A 24-word phrase carries 256 bits. The phrase is then stretched into a binary seed with a deliberately slow hash.

To keep the code short and runnable, the next example uses a 16-word list (4 bits per word), a simple one-word checksum and a plain SHA-512 for the seed. The proportions are different, but the mechanics are the same: random bytes in, words out, last word acts as a checksum.

HD wallets: one seed, endless addresses

Using one address forever hurts privacy, since everyone can see all your activity. Creating a new key for each payment would be safer but impossible to back up one by one. Hierarchical deterministic (HD) wallets, specified in BIP-32, solve this. A single seed feeds a one-way keyed hash (HMAC-SHA512) that outputs a master key and a chain code. Each child key comes from the parent's key, the chain code and an index number. The same seed always regenerates the same tree, so one phrase backs up every address you will ever use.

flowchart TD
    W["Seed phrase<br/>(words)"] --> S["Seed"]
    S --> M["Master key + chain code"]
    M --> C0["Child 0<br/>-> address 0"]
    M --> C1["Child 1<br/>-> address 1"]
    M --> C2["Child 2<br/>-> address 2"]

A single seed deterministically generates a tree of keys and addresses, so one backup restores them all.

Python Seed words and a toy HD wallet

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Real BIP-32 improves on this toy in an important way. With normal (non-hardened) derivation, the public key and chain code alone can generate child public keys. A web shop can therefore show a fresh receiving address per order without holding any private key. Real BIP-39 also uses PBKDF2 with 2,048 rounds to turn the words into the seed, which slows brute-force guessing of weak phrases.

Custody: who holds the key?

The phrase "not your keys, not your coins" summarizes the central trade-off.

Model Who holds the private key Strength Risk
Self-custody, software wallet You, on a phone or computer Full control Malware, phishing, lost device
Self-custody, hardware wallet You, inside a signing device that never exports the key Strong protection from malware Lost seed phrase, physical theft
Custodial (exchange) A company Easy recovery, support Company failure, hacks, freezes
Multisignature Several keys, a threshold must sign No single point of failure More complex setup

Warning: anyone who sees your seed phrase controls every address derived from it. Never type it into a website, never photograph it, and never share it with "support". Real wallets will never ask for it except during a recovery you started yourself. The words in this lesson are toy examples that must never hold funds.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which statement about the chain from private key to public key to address is correct?

    The private key produces the public key, which is hashed into the address. Each step is one-way, so an address reveals nothing usable about the key.
  2. 2. What is the purpose of the checksum in Base58Check?

    The checksum is the first four bytes of a double SHA-256 of the payload. A typo almost always breaks the match, so wallets can reject a bad address.
  3. 3. Why does a 12-word seed phrase help with backups?

    An HD wallet derives every key from the seed, so writing down the words once lets you restore all current and future addresses.
  4. 4. Why does Base58 omit characters such as 0, O, I and l?

    Dropping look-alike characters reduces human transcription errors, which matters when a single wrong character could send funds to the wrong place.
  5. 5. Who can spend funds in a custodial exchange account?

    In custodial storage the company controls the private keys. You trust it to honor your balance, which is convenient but removes your direct control.

Summary

  • A wallet holds private keys and signs transactions; coins themselves live on the ledger.
  • The chain is private key, then public key (d * G), then address (hashed, versioned, checksummed and encoded); every step is one-way.
  • Base58Check removes look-alike characters and appends a four-byte checksum to catch typos; Ethereum uses hex with an optional case-based checksum.
  • A seed phrase encodes random bytes as words, and an HD wallet derives an unlimited tree of keys from one seed with HMAC-SHA512.
  • Custody decides who really controls funds: whoever holds the key (or the phrase) holds the money.

Next: Designing a Block