Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Is this a safe assumption regarding IP addresses distribution?
New on LowEndTalk? Please Register and read our Community Rules.

Is this a safe assumption regarding IP addresses distribution?

AdamMAdamM Member


Is it a safe assumption to assume that the last octet section of an IP address is fairly evenly distributed between even and odd values?


  • What?

    Thanked by 2Riz Caster
  • an ipaddress has the form : (or so)

    Is it safe to assume that about half the visitors to a web page will have an ipaddress in which the last .xxx is an even value, and about half where the last .xxx is odd?

    Does that make more sense?

  • AdamM said: Does that make more sense?


    An IP doesn't always have 3 numbers for each octet.

  • Your question doesn't really make sense but I'm going to go with, no, the distribution is not even. You must consider all routable IPv4 addresses. Just because it's the last block that's being allocated, it doesn't mean previous allocated IPv4 addresses do not work.

  • @Ishaq

    you are correct, there are not always three digits, but regardless of the number of digits, is the number represented by the octet half the time even and half the time odd, or is there some other distribution model?

  • AdamM said: other distribution model?

    Each octet has random numbers, depending on what was assigned to the customer by the RIR.

  • perennateperennate Member, Host Rep
    edited January 2016

    AdamM said: you are correct, there are not always three digits, but regardless of the number of digits, is the number represented by the octet half the time even and half the time odd, or is there some other distribution model?

    There are exactly as many IP addresses ending with an even octet as there are ones ending with an odd octet.

    But it's not clear what distribution you're asking about. Like, routable addresses, addresses assigned by hosting companies, residential addresses, etc.?

  • essentially I want to send a computation to be handled by one of two compute server. I want each computer server to handle roughly half of the requests.

    When a request comes in, can I just check to see if the last octet is even or odd, and then send all even ones to one server and the odds to another... would that provide about half load on each compute server?

  • Is this web traffic?

  • JustAMacUserJustAMacUser Member
    edited January 2016

    Well, if you're speaking from a strictly statistical point of view, yeah. Half of .### ends in even and half ends in odd. But from a real life point of view you can't expect an even distribution from visitors.

    None of us know your endgame, but if you're looking to have roughly every other user handled differently for some reason, you're probably better off just using a Unix timestamp for even/odd numbers. (Assuming you're trying to avoid tracking whether a particular page view is even or odd.)

    Edit: I posted this while you were posting your most recent reply. If you're looking to load balance like that and it's web traffic, any web server software can be setup to alternate like that with two backend servers.

  • @Ishaq
    Yes this is web traffic

  • What web server software are you using? Apache, Nginx, etc.?

  • Just use a weighted round robin then.

    Easier than trying to split even and odd IP addresses, as that's not going to work properly in real world usage.

  • @Ishaq

    You are correct, will just round robin it.


    I am using apache tomcat standalone

  • Sounds like a bad idea, but might work well enough. dont you have some log files you could look at? You're not the first person to try and solve this problem. Don't reinvent the wheel, go see what other people do.

  • linuxthefishlinuxthefish Member
    edited January 2016

    EDIT: removed

  • Yes it's true

  • perennateperennate Member, Host Rep

    If your traffic is very large compared to the spikiness of traffic across visitors, then hashing should be fine. Note that there's no reason to route based on even/odd when you can compute a quick hash on the IP address, hashing gives the best distribution.

    If you have just one load balancer then you can do round robin, but if you want multiple load balancers then you can configure it so that visitors hash to the same backend on all the load balancers.

  • @perennate

    Yes, I want repeat visitors to send work to the same compute server, so that is why I was looking originally at using the IP (not just a round robin). A hash on the ip should work.

  • Hashing on incoming IP alone may not get you what you want

    • The distribution of your visitors wont be the same as that of the internet. Even so the top 24 bits from the internet wont have the same traffic distribution. I would expect high bandwidth IP addresses from the US to dominate.
    • Even if your visitors are split evenly on the last octet, requests might bunch up in time. You might get an hour of traffic where all requests are from even octets. Probability distributions only give long term averages. If you want to analyze on shorter time frames you need to add some control theory.
    • Then there is visitor behavior. If some visitors send intensive or long-running requests, then you cant treat each visitor the same, especially with sticky sessions.

    If all visitors do roughly the same thing on your website and stickiness is not an issue, then roundrobin is a good fit.

    For more realistic scenarios, you end up losing scalability by keeping track of server loads and number of connections. Maybe something based around leastconn?

  • emgemg Member

    I would like to address the original question: Are final IPv4 address octets in public IP addresses evenly distributed between odd and even?

    I would like to see real-world data done with careful research. My hypothesis is that it will be close to a 50/50 split, but there will be a statistically measurable bias. My reasoning is that IP address assignments are configured by humans, and people tend to follow standard conventions and other patterns. For example, many routers take ".1" as the gateway and start their DHCP pools at ".2".

    For the practical purpose of dividing a load between two servers, I believe it would be reasonably safe to split them based on whether the last IPv4 address octet is odd or even, but I have no real-world data to back up that assertion. If it takes a lot of time or resources to manage a true load balancing, perhaps the odd/even solution is good enough and may be less resource intensive.

  • lewekleoneklewekleonek Member
    edited January 2016


    I don't believe this is the most efficient way of doing your web app load balancing. There are many other more efficient ways.
    You should never assume that unique_visitor == unique_IP_address
    What if there are few sessions coming from behind a proxy (think corporate firewalls), or for some other reason. But that's just a tip of the iceberg.
    When the users are anonymous, there is really no surefire method of telling if they are unique or not. Yes, of course, you can use session cookies etc. but that's a topic for a rather longer discussion.

    Here is a good read to get you going on the right track.

    Thanked by 1tehdan
Sign In or Register to comment.