<p>Private keys are 256 bit numbers</p>
<p>Public keys are a pair of X,Y coordinates.  Each coordinate is a 256 bit number.  BUT for every X coordinate there are only two possible Y coordinates (one positive, one negative) so you can store a public key as just the X coordinate (256 bits) and the sign of the Y coordinate (1 bit) and the proper Y coordinate can then be calculated from the X coordinate and the sign.</p>
<p>So private key = 256 bits, public key = 2*256=512 bits OR 256+1=257 bits</p>
<p>Then there is a small amount of formatting overhead of a few bits.</p>
<p>Then these are encoded.</p>

CC BY-SA 4.0
2013-11-23T16:52:38.527Z
2021-10-22T18:21:33.960Z
2021-10-22T18:21:33.960Z
BurtW
<p>The length of a <em>key</em> doesn't vary. Private keys are always 32 bytes, and public keys are always 65 bytes (or 33 bytes for a compressed public key). Public key hashes are always 20 bytes.</p>

<p>The length of addresses vary because in Bitcoin's base58 encoding, leading zero bytes are expressed as a single "1". Other bytes require more than one character in order to be expressed in base58.</p>

CC BY-SA 3.0
2017-12-26T09:44:58.533Z
I have seen examples of private keys larger than 32 bytes. How does qt truncate them? As an example: https://bitcoin.stackexchange.com/a/22881/2075. I could not get any test vectors to pass. The op claims to have used QT in the tests. Can you explain how QT would work with larger than 32 bytes keys?
Jus12
CC BY-SA 3.0
2011-11-20T19:34:50.870Z
Do you have private keys and public keys reversed in the above answer?  It seems to me that private keys are longer.
shoeless joe
CC BY-SA 3.0
2011-11-21T01:33:51.100Z
@shoelessjoe I don't think so. Public keys are definitely 64 bytes plus the leading 0x04 byte, and I assume that the 256 in "secp256k1" refers to the size of the private key in bits.
theymos
CC BY-SA 3.0
2011-11-29T18:13:12.373Z
You said "Private keys are always 32 bytes, and public keys are always 65 bytes."  That makes public keys longer than private keys?
shoeless joe
CC BY-SA 3.0
2011-11-30T22:12:52.090Z
@shoelessjoe Yes. I think this is the case with all public-key crypto, actually.
theymos
CC BY-SA 3.0
2011-12-04T14:56:33.387Z
In fact, we could move to compressed public keys, which are 257 bits long (33 bytes). Slightly longer than the private key indeed, but almost nothing.
Pieter Wuille
CC BY-SA 3.0
2012-03-03T01:17:08.227Z
As of 0.6.0, compressed public key will be enabled.
Pieter Wuille
CC BY-SA 3.0
2011-11-18T07:35:02.093Z
2012-03-03T01:33:15.247Z
2012-03-03T01:33:15.247Z
theymos
<p>Why does the length of a bitcoin key vary?  Why aren't they all the same length?</p>

CC BY-SA 3.0
2014-11-11T12:45:39.693Z
some interesting bitcoin trivia - the first time a compressed public key is used to spend on the blockchain is in tx [94af4607627535f9b2968bd1fbbf67be101971d682023d6a3b64d8caeb448870](http://blockexplorer.com/tx/94af4607627535f9b2968bd1fbbf67be101971d682023d6a3b64d8caeb448870), which spends 0.01337 btc. clearly someone was showing off lol
mulllhausen
CC BY-SA 3.0
2014-11-11T12:55:28.693Z
the compressed pubkey was 0271f1e54016d623897fa9b973c2f084376ff61651ee5b71eef0d98a8be56a75cc btw
mulllhausen
<public-key>
Why does the length of a bitcoin key vary?
shoeless joe
# Why does the length of a bitcoin key vary?

(Asked by: username_0 on 2011-11-18)

Why does the length of a bitcoin key vary? Why aren't they all the same length?

**Tags:** public-key

> **Comments:**
> **username_1**: some interesting bitcoin trivia - the first time a compressed public key is used to spend on the blockchain is in tx [94af4607627535f9b2968bd1fbbf67be101971d682023d6a3b64d8caeb448870](http://blockexplorer.com/tx/94af4607627535f9b2968bd1fbbf67be101971d682023d6a3b64d8caeb448870), which spends 0.01337 btc. clearly someone was showing off lol  
> **username_1**: the compressed pubkey was 0271f1e54016d623897fa9b973c2f084376ff61651ee5b71eef0d98a8be56a75cc btw  

---

## 2 answers

### Answer by username_3 on 2011-11-18. Score: 30 | Accepted answer

The length of a *key* doesn't vary. Private keys are always 32 bytes, and public keys are always 65 bytes (or 33 bytes for a compressed public key). Public key hashes are always 20 bytes.

The length of addresses vary because in Bitcoin's base58 encoding, leading zero bytes are expressed as a single "1". Other bytes require more than one character in order to be expressed in base58.

> **Comments:**
> **username_0**: Do you have private keys and public keys reversed in the above answer?  It seems to me that private keys are longer.  
> **username_3**: @username_0 I don't think so. Public keys are definitely 64 bytes plus the leading 0x04 byte, and I assume that the 256 in "secp256k1" refers to the size of the private key in bits.  
> **username_0**: You said "Private keys are always 32 bytes, and public keys are always 65 bytes."  That makes public keys longer than private keys?  
> **username_3**: @username_0 Yes. I think this is the case with all public-key crypto, actually.  
> **username_5**: In fact, we could move to compressed public keys, which are 257 bits long (33 bytes). Slightly longer than the private key indeed, but almost nothing.  
> **username_5**: As of 0.6.0, compressed public key will be enabled.  
> **username_4**: I have seen examples of private keys larger than 32 bytes. How does qt truncate them? As an example: https://bitcoin.stackexchange.com/a/22881/2075. I could not get any test vectors to pass. The op claims to have used QT in the tests. Can you explain how QT would work with larger than 32 bytes keys?  

---

### Answer by username_2 on 2013-11-23. Score: 10

Private keys are 256 bit numbers

Public keys are a pair of X,Y coordinates. Each coordinate is a 256 bit number. BUT for every X coordinate there are only two possible Y coordinates (one positive, one negative) so you can store a public key as just the X coordinate (256 bits) and the sign of the Y coordinate (1 bit) and the proper Y coordinate can then be calculated from the X coordinate and the sign.

So private key = 256 bits, public key = 2\*256=512 bits OR 256+1=257 bits

Then there is a small amount of formatting overhead of a few bits.

Then these are encoded.


---

