✖

The Bitcoin address, private key and signature

A Bitcoin address is a string of characters like 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH that you can give to anyone so that they can pay you. It works like an account number, except that no bank issued it. You made it yourself from a single secret number, the private key. And here is the catch: in Bitcoin nobody has an account with a name on it. How much anyone has can be seen only in the public ledger of payments: coins “lie” on an address as payments that nobody has spent yet. “Owning bitcoins” therefore means nothing more than knowing the number with which the coins can be spent. Whoever knows that number has the coins, whether they are the owner or a thief.

The whole security of your coins rests on a single mathematical property: from the secret number the address is worked out in a fraction of a second, but nobody can get from the address back to the secret number. What such a one-way street looks like you will see on a small curve, one you can even work out on paper.

A private key is one giant number

A private key is a randomly chosen whole number between 1 and a giant number with 78 digits (roughly 1.16 · 1077). A wallet essentially tosses a coin for it 256 times. Each toss is one bit, a zero or a one, and the zeros and ones are put together into a number as a sum of powers of two, much as 13 = 8 + 4 + 1. There are 2256 possibilities, and that is almost exactly the upper limit. From now on we will simply call the key d.

Forget about guessing somebody else’s key. If each of eight billion people tried a billion keys a second, over the whole lifetime of the universe they would not get through even a tiny fraction of the possibilities. Why blind guessing is so slow is shown by the article on password security. For the same reason, two people will not happen to draw the same key.

The public key is then derived from the private key. It is a point on a so-called elliptic curve and is made by “adding points”.

An elliptic curve and adding points

Bitcoin uses the elliptic curve with the equation

y2=x3+7.

The curve is symmetrical about the x-axis: with every point (x, y), that is, a point with coordinates x and y, its mirror image (x, −y) also lies on it, because y and −y give the same when squared.

Points on the curve can be “added”. Through two points P and Q you draw a line. It meets the curve in one more point. You reflect that point in the x-axis and the point P + Q is born. If you want to add a point to itself, that is, to double it, you take a tangent instead of a line. The result is again a point on the curve, but from the positions of P and Q you cannot tell at a glance where it will land. It is called addition because the rule behaves like addition: it can be repeated and the order does not matter.

The curve y² = x³ + 7 as an arch on the left with branches going up and down to the right. A blue line passes through the blue points P and Q and meets the curve at the top right in an orange point. A dashed vertical segment leads from the orange point down to the red point P + Q. The curve y² = x³ + 7 as an arch on the left with branches going up and down to the right. A blue line passes through the blue points P and Q and meets the curve at the top right in an orange point. A dashed vertical segment leads from the orange point down to the red point P + Q.

Now we choose a fixed point G. Doubling gives G + G = 2G, adding G gives 3G, and so on. These points are called multiples of G. The public key is the multiple d · G, where d is the private key and G is the starting point, the same for everybody. Why points are added exactly like this and how to do it with numbers can be found in the article on elliptic curves.

A one-way route across a grid

A computer, though, does not work with the curve on real numbers but with remainders after division. It needs exact whole numbers with no rounding, and remainders also scatter the points, so nothing can be guessed backwards from the picture. To try it out, a toy will do: the equation stays y2 = x3 + 7, but everything is calculated as a remainder after division by 43. The coordinates are then just whole numbers from 0 to 42, and the curve is left as 30 points on a grid. The symmetry has not gone away: the point (2, 31) goes with (2, 12), because 31 + 12 = 43.

As a start we take G(2, 31), and its multiples come out like this:

G=(2,31),2G=(7,36),3G=(35,22),

4G=(21,25),5G=(12,31),6G=(29,12)

Adam chooses d = 7 as his private key. His public key is

Q=7G=(25,25).

A 43 by 43 grid with thirty points of the curve y² = x³ + 7 calculated with remainders after division by 43. The blue points are scattered all over the area. A dashed route leads from the red point G at the top left through the orange points 2G to 6G to the red point 7G in the middle, jumping back and forth with no direction at all. A 43 by 43 grid with thirty points of the curve y² = x³ + 7 calculated with remainders after division by 43. The blue points are scattered all over the area. A dashed route leads from the red point G at the top left through the orange points 2G to 6G to the red point 7G in the middle, jumping back and forth with no direction at all.

Look at how the multiples flit about the grid. No direction, no rhythm. After 31 steps the route returns to the start: 32G is G again. So on the toy only d from 1 to 30 makes sense.

Going there is easy. Adam does not have to add G six times in a row; doubling is enough: doubling G gives 2G, doubling 2G gives 4G = (21, 25). And since 7 = 4 + 2 + 1, he then adds 2G and G:

4G+2G=6G=(29,12),

6G+G=7G=(25,25)

Instead of six operations he needed four: two doublings and two additions. For a real key with 78 digits about 256 doublings are enough, and at most as many additions. It is the same trick as fast exponentiation, and a computer manages it in a fraction of a millisecond.

There is no way back. Eva has only the point (25, 25) and wants to find out which multiple of G it is. The grid gives no hint: the point 7G lies in the middle, 6G at the bottom right, 8G = (32, 3) right at the bottom. All that remains is to try the multiples one after another, seven steps on the toy. The best known method cuts the trying down to about the square root of the number of possibilities, and even that is not enough, as the part on searching for a private key shows.

One clarification: one-way does not mean that a fast route back provably does not exist. It means that nobody knows one. Mathematicians have been looking for it in vain for decades, and that is why it is trusted.

The real Bitcoin curve is called secp256k1 and differs from the toy only in size. The equation is the same, y2 = x3 + 7, only we divide not by forty-three but by a prime with 78 digits. There are then exactly as many multiples of G as there are possible private keys. Even with the square root it would be about 2128 steps, and according to the part on security the whole Bitcoin mining network would need about 11 billion years for it.

That is why everyone may see a public key. Whoever knows it cannot read the private key off it, at least until a large enough quantum computer appears, a machine that in theory would solve this problem quickly. The part on the quantum computer looks at that in detail.

How a Bitcoin address is made from a private key

The route from a private key to an address has three steps, and none of them can be walked backwards:

  1. The private key d is multiplied by the point G. The result is the public key, the point d · G.
  2. From the public key a hash is worked out, first with the SHA-256 function and then, on the result, with the RIPEMD-160 function.
  3. The hash is rewritten as letters and digits and a checksum is added.

Imagine a hash as a coffee grinder: you pour any data into it and a short string of characters comes out, the same one every time for the same data. But you cannot stick ground coffee back together into beans, and nobody can find out from a hash what went into the grinder (what would happen if somebody could is discussed in the part on SHA-256). You will find more about it in the part on mining and in the article on hash functions.

Let’s go through it with real numbers. As the private key we substitute the smallest possible one, d = 1. The public key is 1 · G = G, that is, directly the starting point of secp256k1. It is written in short as 33 bytes (a byte is 8 bits) in the hexadecimal system, which besides the digits 0–9 also uses the letters a–f:

0279be667e…16f81798

The 32 bytes after the initial 02 are the x coordinate. Nobody remembers the y coordinate, because it is worked out from the equation. But because of the symmetry there are two of them, y and −y, so the leading byte 02 or 03 says which one it is.

The SHA-256 hash of those 33 bytes is 0f715baf…4b9b0554, and from it the RIPEMD-160 hash has just 20 bytes: 751e76e8…f1433bd6. What remains is to add a checksum and rewrite everything using 58 characters that nobody confuses. They leave out the zero, the capital O, the capital I and the lowercase l. The address comes out as

1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH

A chain of five rectangles from top to bottom joined by arrows. At the top a red d = 1, below it the blue public key 0279be667e…16f81798 of 33 bytes, an arrow SHA-256 to the hash 0f715baf5d…4b9b0554 of 32 bytes, an arrow RIPEMD-160 to the hash 751e76e819…f1433bd6 of 20 bytes and an arrow Base58Check to the green address 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH. A dashed grey arrow from the address back to the key is crossed out with a red cross. A chain of five rectangles from top to bottom joined by arrows. At the top a red d = 1, below it the blue public key 0279be667e…16f81798 of 33 bytes, an arrow SHA-256 to the hash 0f715baf5d…4b9b0554 of 32 bytes, an arrow RIPEMD-160 to the hash 751e76e819…f1433bd6 of 20 bytes and an arrow Base58Check to the green address 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH. A dashed grey arrow from the address back to the key is crossed out with a red cross.

From the same 20 bytes an address in the newer format can be written too: bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4.

But never use key 1: everybody who has read this far knows it. According to mempool.space, coins had arrived at the address 1BgGZ… 101 times by December 2026, and every time somebody sent them on. That is why you should never show your private key to anyone.

And why isn’t the public key taken as the address directly? The hash is shorter, 20 bytes instead of 33, the address has a checksum and, above all, the public key stays hidden until you pay from the address for the first time. Why that matters is explained in the section on addresses at risk.

A typo in an address

When you copy and retype addresses, a moment of inattention is enough for one character to be wrong. If that produced a different valid address, the money would go off to who knows where. That is why an address has a checksum at the end, just like the Czech birth number (rodné číslo) or an IBAN.

For an address that begins with a one it is 4 bytes: the beginning of the hash of a hash, that is, SHA-256 calculated twice in a row on everything before them. The wallet recalculates the sum itself and compares. Let’s change a single character in our address, 1BgGZatcN… instead of 1BgGZ9tcN…. The checksum no longer matches and the wallet rejects the address. A random typo gets through only if it also happens to hit the 4 bytes, that is, the 32 bits, of the checksum. That happens with probability

1232≈14.3⋅109,

so roughly once in four billion typos. Addresses beginning with bc1 have an even cleverer checksum: it is guaranteed to catch any mistake in up to four characters.

Types of address

You can tell the type of an address from how it begins. An address starting with 1 is the oldest common type, as in our example; one starting with 3 holds the hash of a whole spending rule, for example “the coins are unlocked by two signatures out of three”. Addresses starting with bc1q hold the same in a newer notation, and addresses starting with bc1p (Taproot, since 2021) hold the key itself instead of a hash. But they all work the same way: on the address there is a hash or a key, and the coins can be spent only by someone who attaches a signature. That other types may appear is described in the part on post-quantum Bitcoin.

A signature proves that you know the key

But how do you pay from an address when you will not show the private key to anybody? With a signature. A payment says roughly “I am sending these coins from my address to Bára’s address”, and with it go the public key and a signature. Anyone can work out a hash from the key shown and compare it with the address. That is how it is verified that the key belongs to the address.

A signature behaves like a lock that only the owner can lock, while anybody can check it. From the private key d, from the message and from a new random number the owner works out a pair of numbers. The verifier uses the public key and the message to work out whether the pair fits, and does not need d for it. Signatures in general are explained in the article on digital signatures.

If Eva changed the message on the way, say by replacing Bára’s address with her own, the signature would stop matching and the whole network would reject the payment. And Eva cannot produce a new signature, because that needs d, and she cannot get that from the public key.

That random number is chosen anew for every signature and has to stay as secret as d. Anyone who uses the same number twice gives away their private key from the two signatures. This is exactly what cost Sony dearly with one of its games consoles, as the section Signatures on elliptic curves describes.

Since its start in 2009 Bitcoin has used the ECDSA signature, and since 2021 for addresses starting bc1p also the Schnorr signature. Both rest on the same one-wayness, but Schnorr signatures can be added together, so a wallet shared by several people looks on the blockchain like an ordinary payment from one person.

What if somebody steals your key

Then your coins belong to them. A signature cannot be cancelled and nobody will reverse a payment written into the blockchain, because there is no bank and no complaints department. And if you lose the key, the coins stay on the address for ever and nobody can spend them any more, not even you. That is why most wallets do not store the key as a 78-digit number but as a list of ordinary words, from which the keys can be worked out again at any time. How that works is covered by the part of the series on the seed phrase.

See also

Chapters: Bitcoin: what it is and how it works, The Bitcoin halving: why there are only 21 million bitcoins, Bitcoin mining: how proof of work works, Blockchain and the Merkle tree: how it works and why history cannot be rewritten, The Bitcoin address, private key and signature, Seed phrase: why nobody can guess the 12 words of a wallet, Ethereum: smart contracts and proof of stake, Is Bitcoin secure? What its cryptography rests on, The 51% attack: can Bitcoin be spent twice?, Quantum computers and Bitcoin: what if elliptic curves fell, Bitcoin and SHA-256: what if the hash function fell, Post-quantum Bitcoin: how Bitcoin would defend itself against quantum computers