Web3 Learning

How Is a Bitcoin Address Generated?

By Safeheron Team

A Bitcoin address is generated in three steps: the public key is computed from the private key, the public key or script is hashed, and version information and a checksum are added before the result is encoded into a string of characters. Address types differ in what is hashed and which encoding is used: legacy and P2SH addresses use Base58Check, while SegWit and Taproot addresses use Bech32 and Bech32m. The entire process happens locally, with no internet connection and no registration with any institution required.

Where Does the Public Key Come From?

The private key is a 256-bit random number, and the wallet uses elliptic curve multiplication to compute the public key. Bitcoin typically uses a 33-byte compressed public key. The examples below use the publicly known private key 1, whose compressed public key is 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798. Anyone can spend funds sent to these example addresses, so never use them for real.

How Is a Legacy Address Generated?

The public key is first hashed with SHA-256 and then with RIPEMD-160, producing a 20-byte public key hash. These two steps together are called HASH160, and the result for the example is 751e76e8199196d454941c45d1b3a323f1433bd6. Adding the version byte 0x00 in front and encoding with Base58Check gives an address starting with 1: 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH.

How Is a P2SH Address Generated?

P2SH hashes not a public key but a “redeem script,” which specifies the conditions for spending the funds, such as 2-of-3 multisig. The script is run through HASH160, the version byte 0x05 is added, and a checksum is likewise added before Base58 encoding, so the address starts with 3. When SegWit is wrapped in P2SH, the redeem script is 0x0014 followed by the public key hash, which for the example gives 3JvL6Ymt8MVWiCNHC7oWU6nLeHNJKLZGLN.

How Is a SegWit Address Generated?

Native SegWit addresses use Bech32 encoding and consist of three parts: bc, which indicates mainnet; the separator 1; and the data part. The data part begins with the witness version, where version 0 encodes as the letter q, followed by the witness program and a 6-character checksum.

For a single-signature address, the witness program is simply the 20-byte public key hash, so the same private key gives bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4. Script addresses use the 32-byte SHA-256 hash of the script, which makes the address longer. Bech32 uses only lowercase letters and numbers, and its checksum reliably detects a small number of typing errors.

How Is a Taproot Address Generated?

Taproot addresses no longer hash the public key; instead, they contain a 32-byte public key directly. The wallet takes only the public key’s x-coordinate, then uses the public key itself and an optional script tree to compute a tweak, which is added to the public key to produce the final output public key.

Witness version 1 encodes as p, and the checksum algorithm switches to Bech32m. The example gives bc1pmfr3p9j00pfxjh0zmgp99y8zftmd3s5pmedqhyptwy6lm87hf5sspknck9. This allows the funds to be spent either directly with a key signature or by revealing one of the conditions in the script tree.

Do You Need an Internet Connection to Generate a Bitcoin Address?

No. Addresses are computed entirely locally and can be generated even on an offline device. An HD wallet uses a single seed to generate addresses in bulk following the steps above. As long as private keys are truly random, the probability of two people generating the same address is negligible.

Conclusion

A Bitcoin address is computed step by step from a private key through the public key, hashing, and encoding, and the four address types differ only in what is hashed, the version number, and the encoding. Because this process can be fully recomputed independently, businesses should use it to verify the origin of every address. Safeheron’s MPC Wallet-as-a-Service provides businesses with MPC key management and a policy engine.

Want every business receiving address to come from controlled keys?

Contact Safeheron’s Sales Team to Book a 1:1 Demo

Share

Looking for a secure way to manage digital assets?

Talk to our experts and find the right solution for your business.

Request a Demo