These questions keep me up at nights.
Get some sleep. These questions aren't worth staying up over.
How many compressed addresses exist?
Assuming you are asking about version 1 legacy addresses (P2PKH addresses that start with a 1), there are effectively 2
160 of them.
How many uncompressed addresses exist?
Assuming you are asking about Base58Check P2PKH addresses that start with a 1, there are effectively also 2
160 of these.
Do we get the same private/address when we use hex value on all implementations? That means every hex can generate 2 private keys and 2 addresses ( legacy ).
Yes, every hex private key has 2 different Base58Check WIF private key representations (a representation starting with a 5 indicating that an uncompressed public key representation should be used, and a representation starting with a K or L indicating that a compressed public key representation should be used). Each of those 2 private key representations for a single private key will result in the same public key X & Y coordinates, and that public key will have 2 different representations:
- the compressed key representation that includes the 256 bit X value and an 8 bit indicator of whether the Y value is odd or even (used if the Base58Check WIF private key representation had the compressed key indicator)
- an uncompressed key representation that includes the full 256 bit X value AND the full 256 bit Y value along with an 8 bit indicator of the fact that this is the uncompressed public key representation (used if the Base58Check WIF private key representation had the uncompressed key indicator)
Each of those 2 different public key representations will have a 160 bit public key hash, and those two hashes will effectively always be different from each other (and therefore the single hex private key will have 2 different P2PKH legacy addresses).
How can we have 2^256 compressed addresses/private keys, and have 2^256 uncompressed addresses and keys?
We don't.
We have approximately 2
256 private keys (with 2 different representations of each of those keys), for a total of approximately 2
257 different Base58Check WIF private key representations.
We also have approximately 2
160 different P2PKH (legacy) addresses.
So, on average, each unique P2PKH bitcoin address has 2
96 different unique private keys, or 2
97 different unique Base58Check WIF private key representations.
And why do I keep seeing 142857 everywhere. Is 7 a constant number or something?
In what context have you seen that number? I'm not familliar with its significance to Bitcoin discussions.