IP probability question

uv_h

New Member
#1
hi guys.
as you know, IP is a combination of 4 parts. every part is from 0-255, for example 234.32.135.7.

now, my question is, what is the probability that two IPs will get the exact same first 3 parts. for example 1.2.3.234 and 1.2.3.121.

is it just 256^3?

and what is the chance that out of 1500 IPs, 40 will have the same first 3 parts?

thanks!
 
#2
If you mean the probability of two randomly selected IP addresses having the same first three octets then the answer is 1/256³. However, there are some IP addresses (e.g. 0.0.0.0, 127.0.0.1 and 255.255.255.255) that are reserved for special purposes, and these will need to be taken into account when calculating the probability of two randomly encountered IP addresses having the same first three octets. Also, with DHCP, IP addresses are not uniformly distributed in terms of their usage, and so the task of calculating the desired probability becomes enormously complicated.

The way we come to the aforesaid answer for randomly selected IP addresses is to realise that all IP addresses must abide by the same rules. For a given IP address A, the chances that randomly selected IP address B’s first octet matches that of A is 1/256. The same goes for the second and the third octets. Since all three octets must match simultaneously, the answer is P = (1/256)×(1/256)×(1/256) = 1/256³.
 

uv_h

New Member
#3
Thanks. Now, to calculate the chance that out of 1500 clicks, 40 will have the same first three octates is 1/(256^3) * 40 / 1500?
 
#4
Nope, it’ll be a binomial probability: P = 1500C40 × p^40 × (1-p)^1460 where p is the probability of matching one pair of IP addresses. You’ll need something like Mathematica or Matlab to evaluate this probability exactly but it comes to approximately 8.23E–211, a negligibly small probability.
 

BGM

TS Contributor
#5
I guess Con-Tester solution simplifies the question a little bit. Under this interpretation, the required event will be

"exactly 40 out of 1500 random generated IP will have the same, specific first three octets abc.efg.hij"

OP need to be a little bit more specific:

1. Are all 1500 IPs distinct?

2. Is it exactly 40? or 40 or more?

3. Do you require they have the specific IP? or in general any IP that having the same first three octets?

4. If the IP address is not specific, you may also need to exclude the case where you have more than 1 group of 40 IPs having the same first three octets by inclusion-exclusion principle - if your question is asking like "there is at least 1 group of 40 IPs ...".


Anyway, since the probability is extremely small, Con-tester solution already give a good enough approximation in case you miss the above considerations.
 
#6
@BGM....if I created the IP addresses with the help of random function so I donot know all are distinct or not(in worst case may be)

For Suppose I created 1 Milllion IP addresses with the help of random function.So what is the probability that some IP addresses are same? I have to considered both cases(specific IP address and in general)

How will I calculate the probability of some IP addresses are same among 1 Million IP addresses ?(First 4 octet)
Please let me know.
 
#7
In N randomly selected IP addresses, P(At least one is repeated) = 1 – P(No repeats).

There are U = 2^32 unique IP addresses. The probability of no repeats in N is given by P(No repeats) = U!/((U – N)! × U^N). Compare this with the binomial distribution.

Therefore, P(At least one is repeated) = 1 – U!/((U – N)! × U^N). With U = 2^32 and N = 1,000,000, this works out to about 1 – 2.74e–51 — i.e. it’s almost a certainty that at least one IP address will be repeated.

In 77,163 randomly selected IP addresses, there’s about a 50% chance that at least one of them is repeated. This is a surprisingly small number considering that there are 4,294,967,296 unique IP addresses.