TeachMeBitcoin

Compressed vs. Uncompressed Public Keys

From TeachMeBitcoin, the free encyclopedia ⏱️ 3 min read

Compressed vs. Uncompressed Public Keys

On the blockchain, every byte costs money. To optimize transaction weights and lower mining fees, Bitcoin developers transitioned from using large uncompressed public keys to highly efficient compressed public keys.

Understanding compression requires looking at the algebraic symmetry of elliptic curves.


🔵 What is an Uncompressed Public Key?

A raw public key point $(K)$ on the secp256k1 curve consists of an $x$-coordinate and a $y$-coordinate. Both coordinates are 256-bit (32-byte) integers.

In early versions of Bitcoin, public keys were serialized and stored on the blockchain in their full, uncompressed format:

$$\text{Uncompressed Public Key} = \text{0x04} \parallel x \parallel y$$


📐 The Mathematics of Compression

Because the elliptic curve equation is symmetric across the x-axis, we do not actually need to transmit the entire $y$-coordinate.

The secp256k1 curve is defined as:

$$y^2 = x^3 + 7 \pmod p$$

If we know the $x$-coordinate, we can solve for $y$ using a modular square root:

$$y = \pm \sqrt{x^3 + 7} \pmod p$$

In modular arithmetic over our prime field $p$, solving this equation yields exactly two values for $y$: 1. One coordinate is even ($y \pmod 2 = 0$). 2. One coordinate is odd ($y \pmod 2 \neq 0$).

Therefore, as long as we know the $x$-coordinate, we only need 1 bit of extra information (whether $y$ is even or odd) to reconstruct the exact coordinate of the $y$-point.


🟢 What is a Compressed Public Key?

A compressed public key stores only the $x$-coordinate and a single prefix byte representing the parity (evenness) of the $y$-coordinate:

$$\text{Compressed Public Key} = \text{Prefix} \parallel x$$

Where the prefix byte is: * 0x02 if the $y$-coordinate is even. * 0x03 if the $y$-coordinate is odd.

             PUBLIC KEY BYTE OVERHEAD COMPARISON
┌────────────────────────────────────────────────────────┐
│  UNCOMPRESSED (65 Bytes)                               │
├─────┬────────────────────────────────┬─────────────────┤
│0x04 │        x (32 Bytes)            │   y (32 Bytes)  │
└─────┴────────────────────────────────┴─────────────────┘
                                       ▲
                                       └── [Discarded in Compression]
┌──────────────────────────────────────┐
│  COMPRESSED (33 Bytes)               │
├─────┬────────────────────────────────┤
│0x02 │        x (32 Bytes)            │ (Reconstructs y algebraically)
└─────┴────────────────────────────────┘

📈 Real-World Performance Benefits

By transitioning to compressed public keys, the byte footprint of a public key is nearly cut in half:

$$\text{Data Savings} = 65 \text{ bytes} - 33 \text{ bytes} = \mathbf{32 \text{ bytes}}$$

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!