Agree with
odolvlobo and with calculations in bit.
Bitcoin address is Base58 from HEX address, where HEX address is
'00' byte + 160bit encrypted key + 4 bytes checksum.
- prefix '00' byte is always '00' and it is 1 byte, or 8 bit length
- 160bit encrypted key is ripemd160 from sha256 of public key - so it has 160bit length
- check sum is 4 bytes, or 32 bit length.
So, HEX address is 2 + 40 + 8 = 50 hex symbols, or 8 + 160 + 32 = 200 bit length, where first 8 bits always the same, and last 32 bits are just the checksum.
For bit number every symbol has 2 possibilities (1 or 0). But the address is in Base58 formmat, so every symbol of that number could have 58 different options.
Each Base58 address symbol contains Log2(58)/Log2(2) = 5.85798 bits of information.
First symbol of the addreess is always "1" (5.85798 bits of information). However as the first 8 bits are always predefined, so the remaining 2.142 bits influence on the 2nd symbol of the address: 8/5.85798 = 1.3656 symbols are used to store 8 predefined bits of '00' prefix. The last 32 / 5.85798 = 5.4626, actually 5 are also could not be random, and represent the checksum. The residual 0.4626 bits influence the 6th symbol from the last. Total defined number of symbols is 1.3656 + 5.4626 = 6.8282.
Usually legacy bitcoin addresses are 33-34 symbols long, however the maximum possible length is 200 bit / 5.85798 = 34.1414, so 35 symbols (because the 35th symbol will be used to code the remaining 0.1414 bits of information).
Now the total number of addresses where you predefine such symbols could be calculated in the following way:
58 ^ (34.1414 - 6.8282 - x) =
58 ^ (27.3132 - x), where x is the number of your predefined symbols (excluding 1st "1").
zielar, probably this formula will be easier for you if you do not wish to decode Base58 address to bits and calculate in bits. But the results should be the same as in odolvlobo's formula.
P.S. Also very important to add that this total number of possible addresses is calculated just based on the probability of all possible combinations, however no ECDSA rules are used. ECDSA is used only to convert private key (256 bit number) to public key (point on ECDSA curve). The public key later is hashed by SHA256 and RIPEMD160 resulting the 160bit number. We assume that any 160bit number is a valid bitcoin address, but you can not know the private key to that number due to ECDSA security.
Easy example: let's take 160bit number consists of all 0s (so it is 40 hex '0'). We add '00' prefix, and add checksum '94a00911' to the end. After that we convert the received number to Base58 and receive the valid bitcoin address:
1111111111111111111114oLvT2. This address is valid, and we know that zero 160bit hash number was used to create it, but how could find the private key? You need the private key resulting to the public key which RIPEMD160/SHA256 hash is 0. Nobody knows if such private key exist, but continues to send bitcoins to this address