private key is a random number. It is a
256 bit number.
It is used as the source of a
Try it! - Generate Private Key
Decimal (Base 10)
Binary (Base 2)
Never use a private key generated by a website or by someone else. Always generate your own private keys secretly on your own computer.
Generating a Private Key
All you need to generate a private key is a reliable source of randomness.
An easy source of randomness on a Linux computer is
/dev/urandom, which provides random bits of data from your computer. All you need to do is read from it:
# generate 256 bits of random data File.open("/dev/urandom") # urandom is a "file" urandom = 32) # read 32 bytes from it (256 bits) bytes = urandom.read("H*") # the data is binary, so unpack it to hexadecimal privatekey = bytes.unpack( # print the private key puts privatekey
A private key can be almost any 256-bit number.
When you create a public key, your private key is put through a special mathematical function, and this function can only handle numbers up to just below 256 bits. The maximum value is:
max = 115792089237316195423570985008687907852837564279074904382605163141518161494336
This number is
n is the number of points on the elliptic curve used in Bitcoin. So when you generate a 256 bit number, you will want to check that it’s not above this maximum value.
A hexadecimal private key is 32 bytes (64 characters):
If you’re generating private keys for your own personal use, this is all you really need.