<p>Background info: </p>

<ul>
<li><a href="https://bitcoin.stackexchange.com/questions/3059/what-is-a-compressed-bitcoin-key">What is a compressed Bitcoin key?</a></li>
</ul>

<p>Given just the address itself, no, there is no way to tell if it was generated from a compressed or an uncompressed public key. This is calculated from the base58 encoding of the RIPEMD(SHA256(public_key_bytes)). Since the hash isn't reversible, without the public key already in hand, you won't be able to get any more information.</p>

<p>Just look at the base58 decoded data: </p>

<pre><code>$ decodeBase58 12T15tvMGaymMX97X9KxVzyLF323r8v6Hg
000FE302E0D96D9F9AA71738A426A9696EB49AD458679BAFD3

$ decodeBase58 1D8VSXHFAWNhAbruwUMbNp4hsXAnRNkYvX
00850C296420DC9B02CE237ED630B89815E0803EA3BED0F344
</code></pre>

<p>The version byte is 0x00 in both, then there's the 20 bytes of the hash, and a 4 byte checksum. None of this reveals any information about what information was hashed.</p>

CC BY-SA 3.0
2015-05-13T01:39:21.793Z
2015-05-13T02:04:35.087Z
2017-04-13T12:47:34.187Z
morsecoder
<p>An address is the hash of the pubkey (plus checksum and versioning).  Hashes are irreversible and randomly distributed so there is no way to determined the pubkey from the pubkeyhash.</p>

CC BY-SA 3.0
2015-05-15T16:47:52.560Z
2015-05-15T16:47:52.560Z
DeathAndTaxes
<p>As the others mentioned, the short answer is no, but from a WIF(<a href="https://en.bitcoin.it/wiki/Wallet_import_format" rel="nofollow noreferrer">Wallet import format</a>) key you can determine if the address is compressed or not by checking the last byte if it is <code>0x01</code>.</p>

CC BY-SA 4.0
2021-02-18T00:10:25.437Z
2021-02-18T00:10:25.437Z
H Aßdøµ
<p>You cannot determine (from only a base58check address) if the corresponding public key is compressed.</p>

<p>A "normal" pay-to-public-key-hash (P2PKH) is a <a href="https://en.wikipedia.org/wiki/Cryptographic_hash_function">cryptographic hash</a> of either a compressed or an uncompressed public key. Because hashes cannot be feasibly reversed, you cannot tell if the public key, before being hashed, was compressed or uncompressed.</p>

<p>More specifically, a public key in Bitcoin is a pair integers (x,y). For uncompressed public keys, these integers are encoded as 256-bit unsigned <a href="https://en.wikipedia.org/wiki/Endianness">big-endian</a> ints, concatenated together, and then prepended with a single 0x04 byte. The result is 65 bytes long.</p>

<p>For compressed public keys, only the x coordinate is encoded (like above, as 256-bit unsigned big-endian int). It turns out that the y coordinate can only be one of two values, one even and one odd. Instead of prepending a single 0x04 byte, a single 0x02 or 0x03 byte is prepended depending on y's value (0x02 for even, 0x03 for odd). The result is 33 bytes long.</p>

<p>Finally, these bytes (from one of the two paragraphs above) go through the address conversion process described <a href="https://bitcoin.org/en/developer-reference#address-conversion">here in the bitcoin.org Developer Guide</a>, which includes taking an irreversible cryptographic hash (actually, two hashes).</p>

<p>Note that in order to redeem a UTXO associated with a P2PKH address, the redeemer must create a transaction which includes the <em>unhashed</em> public key, either compressed or uncompressed. If such a tx exists in the blockchain, it <em>can</em> be connected to its "normal" base58check address. This is one of the reasons why address reuse is discouraged: once you redeem a UTXO, you "reveal" your public key, which is slightly more sensitive than your bitcoin address.</p>

CC BY-SA 3.0
2015-05-13T01:40:00.340Z
2015-05-13T02:14:41.493Z
2015-05-13T02:14:41.493Z
Christopher Gurnee
<p>I have two bitcoin addresses:</p>

<pre><code>1D8VSXHFAWNhAbruwUMbNp4hsXAnRNkYvX
12T15tvMGaymMX97X9KxVzyLF323r8v6Hg
</code></pre>

<p>One is compressed, one is not.</p>

<p>How can I test which is which? (Preferably using python 2.7)</p>

<p>Thanks in advance :)</p>

<address><python>
How can I test if a bitcoin address is compressed or not?
derrend
# How can I test if a bitcoin address is compressed or not?

(Asked by: username_0 on 2015-05-13)

I have two bitcoin addresses:

```
1D8VSXHFAWNhAbruwUMbNp4hsXAnRNkYvX
12T15tvMGaymMX97X9KxVzyLF323r8v6Hg

```

One is compressed, one is not.

How can I test which is which? (Preferably using python 2.7)

Thanks in advance :)

**Tags:** address, python


---

## 4 answers

### Answer by username_4 on 2015-05-13. Score: 11 | Accepted answer

You cannot determine (from only a base58check address) if the corresponding public key is compressed.

A "normal" pay-to-public-key-hash (P2PKH) is a [cryptographic hash](https://en.wikipedia.org/wiki/Cryptographic_hash_function) of either a compressed or an uncompressed public key. Because hashes cannot be feasibly reversed, you cannot tell if the public key, before being hashed, was compressed or uncompressed.

More specifically, a public key in Bitcoin is a pair integers (x,y). For uncompressed public keys, these integers are encoded as 256-bit unsigned [big-endian](https://en.wikipedia.org/wiki/Endianness) ints, concatenated together, and then prepended with a single 0x04 byte. The result is 65 bytes long.

For compressed public keys, only the x coordinate is encoded (like above, as 256-bit unsigned big-endian int). It turns out that the y coordinate can only be one of two values, one even and one odd. Instead of prepending a single 0x04 byte, a single 0x02 or 0x03 byte is prepended depending on y's value (0x02 for even, 0x03 for odd). The result is 33 bytes long.

Finally, these bytes (from one of the two paragraphs above) go through the address conversion process described [here in the bitcoin.org Developer Guide](https://bitcoin.org/en/developer-reference#address-conversion), which includes taking an irreversible cryptographic hash (actually, two hashes).

Note that in order to redeem a UTXO associated with a P2PKH address, the redeemer must create a transaction which includes the *unhashed* public key, either compressed or uncompressed. If such a tx exists in the blockchain, it *can* be connected to its "normal" base58check address. This is one of the reasons why address reuse is discouraged: once you redeem a UTXO, you "reveal" your public key, which is slightly more sensitive than your bitcoin address.


---

### Answer by username_1 on 2015-05-13. Score: 4

Background info:

* [What is a compressed Bitcoin key?](https://bitcoin.stackexchange.com/questions/3059/what-is-a-compressed-bitcoin-key)

Given just the address itself, no, there is no way to tell if it was generated from a compressed or an uncompressed public key. This is calculated from the base58 encoding of the RIPEMD(SHA256(public\_key\_bytes)). Since the hash isn't reversible, without the public key already in hand, you won't be able to get any more information.

Just look at the base58 decoded data:

```
$ decodeBase58 12T15tvMGaymMX97X9KxVzyLF323r8v6Hg
000FE302E0D96D9F9AA71738A426A9696EB49AD458679BAFD3

$ decodeBase58 1D8VSXHFAWNhAbruwUMbNp4hsXAnRNkYvX
00850C296420DC9B02CE237ED630B89815E0803EA3BED0F344

```

The version byte is 0x00 in both, then there's the 20 bytes of the hash, and a 4 byte checksum. None of this reveals any information about what information was hashed.


---

### Answer by username_2 on 2015-05-15. Score: 1

An address is the hash of the pubkey (plus checksum and versioning). Hashes are irreversible and randomly distributed so there is no way to determined the pubkey from the pubkeyhash.


---

### Answer by username_3 on 2021-02-18. Score: 0

As the others mentioned, the short answer is no, but from a WIF([Wallet import format](https://en.bitcoin.it/wiki/Wallet_import_format)) key you can determine if the address is compressed or not by checking the last byte if it is `0x01`.


---

