Private keys
A bitcoin private key is a random 256-bit number that controls your coins. Learn how it is made, why it must be random and how to keep it safe.
By Dimitar Zurnov · Updated 4 Nov 2026
Adapted from Learn Me a Bitcoin by Greg Walker.
A bitcoin private key is a very large random number, and it is the secret that controls your coins. Whoever holds the private key can sign for the coins locked to its address, so you must keep it secret and back it up carefully. Every public key, address and signature you create comes from this one number.
What is a private key made of?
A bit is the smallest unit of data that a computer stores, and it can hold only one of two values: 0 or 1. Put eight bits in a row, and they can write much bigger numbers. Eight bits set to 1 read 11111111 in binary, which is 255 in everyday decimal numbers, and ff in hexadecimal.
A private key is made of 256 bits in a row, which is the same as 32 bytes. Every different pattern of 256 bits is a different number, so there are 2^256 possible keys. That is about 10^77, which is far more than the number of grains of sand on Earth, and it is why guessing a key is hopeless.
The largest 256-bit number is one less than 2^256:
115792089237316195423570985008687907853269984665640564039457584007913129639935
How is a private key made?
Most people never make a private key by hand. A wallet does it for them, by drawing 256 random bits and turning them into a number. You can make one yourself too, as long as the bits are truly random. There are three common ways to do it.
- Flip a coin 256 times. Write heads as 1 and tails as 0. The 256 results together form a private key. It is slow, but it needs nothing but a coin.
- Use a random number generator in a programming language. Use one that is described as cryptographically secure, such as Python's
secretsmodule. The basic random function in most languages is fast, but it is predictable, so it is unsafe for keys. - Hash random data with SHA-256. SHA-256 turns any input into a 32-byte result, which is 256 bits. Hash data that is large and random. Hashing a word such as "bitcoin" gives a key that anyone can guess, so the coins are not safe.
Most tools show a private key in hexadecimal, which is a 64-digit form of the same number. The example below is for illustration only. It is published on this page, so do not use it with real coins:
ef235aacf90d9f4aadd8c92e4b2562e1d9eb97f0df9ba3b508258739cb013db2
What range of numbers is valid?
A valid private key is any whole number from 1 up to n minus 1. Here n is the order of the curve that Bitcoin uses, a number just under 2^256. Zero is not valid, because it cannot produce a public key.
Wallets always choose numbers inside the valid range, so you rarely need to check it yourself. If you make a key with your own code, check the range anyway. A random number almost never falls outside it. The private key page gives the exact value of n for developers.
Why does randomness matter?
If someone can predict your random numbers, they can rebuild your key without ever touching your computer. This is why a key must come from a random source that is built for secrets.
The risk is real. In 2023, a flaw in the bx seed command of the Libbitcoin Explorer tool, known as Milk Sad, let attackers guess the seeds of over 2,600 wallets. The command used only 32 bits of randomness, so attackers could try every possibility and steal the coins. The lesson is simple: a key is only as safe as the randomness behind it.
Why can't someone else make the same key?
Anyone can create their own "account" by generating a random 256-bit number. No one has to issue it, and no one can stop you. That is an important feature of Bitcoin.
It also means two people could, in theory, generate the same key. In practice, the odds are negligible. Even if a billion computers each made a billion keys every second, finding a key that someone else already holds would take far longer than the age of the universe. As long as your key is random, you can treat it as yours alone.
Where should you make a private key?
Make your keys on your own device. A website can keep a copy of any key you enter into it, so never create or type a key on one. Most people are better off using a wallet, which creates and backs up keys for them without any extra steps.
How do you keep a private key safe?
- Never type it into a website, a chat, or a form.
- Never store it in a plain text file, a screenshot, or a cloud note.
- Never share it to get help. Share a transaction ID instead, because it reveals nothing secret.
- Keep a backup offline, in a place that only you can reach.
Anyone who holds the private key can spend the coins behind it, whether or not they have access to your wallet app. Treat it the way you would treat cash, and guard it as carefully as you would guard a safe.
Next, public keys explains how the public key is calculated from your private key, and why it is safe to share.
In this section: Beginners
Something look wrong? Tell us