Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Seemingly simple question, with enough edge and corner cases that I don't trust my ability to calculate it. What is the exact number of valid IPv4 addresses that could potentially be used as individual destinations? In other words, 2^32 minus reserved blocks, multicast addresses, private networks, etc.

Update: MK's answer is excellent, but... how about an upper bound, assuming maximally efficient use of CIDRs?

share|improve this question
IP adresses for private networks are perfectly valid IPv4 addresses. – VMai May 25 '14 at 14:17
@VMai They aren't really useful for "individual destinations", though, because the same IPv4 address can be used for any number of hosts as long as they aren't on the same network. Case in point: – Michael Kjörling May 25 '14 at 14:18
@VMai The VPN itself forms a private network (after all, that's part of the meaning of the term) but if you were to connect to a different network (via VPN or otherwise) then the same IPv4 address could lead somewhere entirely different. Globally routable addresses don't have that property; a given globally routable IPv4 address (as assigned on the Internet) will always represent one given host on the Internet. That host in turn might be a traffic multiplexer, NAT gateway, load balancer, or something else, but that's irrelevant from an IP perspective. – Michael Kjörling May 25 '14 at 14:25
@VMai Because they have no place in the routing tables in the DFZ? – Michael Kjörling May 25 '14 at 14:35
@MichaelKjörling that isn't true. The same internet address can route to different hosts depending on the starting point. Google DNS does this. – ali1234 May 25 '14 at 15:40
up vote 16 down vote accepted

This would have been easier to answer twenty or so years ago, before CIDR became commonplace.

I assume that by "valid" you mean something that with the common router configuration on the Internet will represent a valid endpoint host. It is perfectly possible to run an IPv4 network that has absolutely nothing to do with the Internet, in which case many assumptions about address space allocation made on the public Internet will not hold.

Some parts of the address space are easy. We have 2^32 possible addresses, and from this we can subtract things like the old Class E (first octet 240-255), RFC 1918 space (10/8, 172.16/12, 192.168/16), ranges reserved for various purposes (100.64/10, 127/8, 169.254/16, ...) and so on. There are also netblocks that you are extremely unlikely to encounter on the public Internet, like AMPRNET (netblock 44/8), but which aren't reserved per se.

However, that doesn't really get us an answer. IPv4 allocation these days is done using CIDR, which means that two adjacent netblocks may have completely different netmasks. It's perfectly possible to have subnets like and sitting right next to each other and belonging to the same upstream allocation, say, 10.0/9. (Yes, that is RFC 1918 space, but that's just so I don't accidentally name someone's real network.)

Ideally packed, 16 adjacent /28 blocks require a grand total of one /24 worth of address space, so you might think that it would allow the same number of hosts as a single /24. But they do not; each /28 has its own network and broadcast address, while the /24 has only one such set. So you are in a sense "wasting" an additional 30 IP addresses (16 network and 16 broadcast addresses, rather than one of each). The set of /28 blocks allow addressing a grand total of 16 × 14 = 224 hosts, whereas the single /24 allows addressing 254 hosts. (For simplicity's sake, I consider the subnet perimeter router to be a host on the subnet, but in real life, it's another required assignment for each subnet.) This effect becomes more pronounced the smaller the subnet allocations made are. The choice whether to slice out a /29, /28, /24 or even a /20 is a business choice made by the upstream ISP, based on the customer's demonstrated needs and likely also the customer's ability and willingness to pay for the address space. I sent in a request for an IPv4 allocation for a company I worked for a little over ten years ago, and even then, getting anything larger than a /28 was not trivial.

What all this boils down to is that there is no way to calculate an exact maximum number of addressable hosts on the Internet, because even if we enumerate and take into account all reserved IP address ranges, we would still need to know the subnet allocation sizes in order to account for the varying amount of losses to network and broadcast addresses. Before CIDR, that was knowable; class A was a /8, class B was a /16 and class C was a /24. With CIDR, no such assumptions can be made.

share|improve this answer
For completeness' sake: is also a special block for the implementation of NAT in ISP networks. RFC6598 – Sander Steffann May 25 '14 at 14:32
@SanderSteffann I specifically didn't mean to enumerate all such ranges, even though I did name a few. The important part of my answer is (supposed to be) the discussion about varying subnet sizes and the impact of those on the maximum number of addressable hosts. Even so, I'll amend the answer to include that range as well. – Michael Kjörling May 25 '14 at 14:34
I started to write my own answer and then yours popped up. You say the same thing, but so much better, that I won't bother with mine. Good job ! – Tonny May 25 '14 at 21:56
@MichaelKjörling I didn't mean to criticise your answer. It is rely good. The 100.64/10 range is an not well known one, but it is becoming more relevant these days. That's why I thought it good to mention it. – Sander Steffann May 26 '14 at 12:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .