I have two bitcoin addresses:


One is compressed, one is not.

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

Thanks in advance :)


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 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 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, 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.


Background info:

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

$ decodeBase58 1D8VSXHFAWNhAbruwUMbNp4hsXAnRNkYvX

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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.