• Hash256
  • Hash160
  • Reverse Bytes
  • Hexadecimal
  • Satoshis

Private Key

A large randomly generated number.

A private key is a random number. It is a 256 bit number.

It is used as the source of a public key.

Try it! - Generate Private Key

32 bytes (64 characters)
Hexadecimal (Base 16)
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
urandom = File.open("/dev/urandom")    # urandom is a "file"
bytes = urandom.read(32)               # read 32 bytes from it (256 bits)
privatekey = bytes.unpack("H*")[0]     # the data is binary, so unpack it to hexadecimal

# 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 = 115792089237316195423570985008687907852837564279074904382605163141518161494337

So when you generate a 256 bit number, you will want to check that it’s below 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.

Wallet Import Format

However, you can convert your private key to a WIF Private Key, which basically makes it easier to copy and import in to wallets.

By Greg Walker,

Last Updated: 19 Apr 2020
  • 19 Apr 2020: added ajax-loading html and disabled ajax buttons when making ajax requests
  • 15 Apr 2020: updated latest tools for consistency
  • 13 Apr 2020: tooltip css class updates and /guide/address calculator from hash160
  • 08 Apr 2020: added warning about using private keys from websites
  • 08 Apr 2020: added private key generator tool
  • 02 Apr 2020: added grades
  • 28 Mar 2020: updated html for h1 headers and subheadings - now dynamic from yaml
  • 28 Mar 2020: updated html for h1 headers and subheadings
  • 22 Mar 2020: /guide/extended-keys - first draft
  • 09 Oct 2019: renamed browser to explorer, glossary to guide, and guide to beginners
Back to Top

Hey there, it's Greg.

I'll let you know about cool website updates, or if something seriously interesting happens in bitcoin.

Don't worry, it doesn't happen very often.