62

Yes, I am needing to know what the total number possible IPs in the public IPv4 space.

I'm not sure where to even get a neat list of all the IP address ranges, so could someone point me to a resource to calculate this myself or calculate the total number of IPs for me?

Also, by Public IPs I mean not counting reserved or private-range IP addresses.. Only the ones that can be access through the internet.

Earlz
  • 62,085
  • 98
  • 303
  • 499

5 Answers5

114

According to Reserved IP addresses there are 588,514,304 reserved addresses and since there are 4,294,967,296 (2^32) IPv4 addressess in total, there are 3,706,452,992 public addresses.

And too many addresses in this post.

mjv
  • 73,152
  • 14
  • 113
  • 156
Marko
  • 3,499
  • 3
  • 24
  • 22
  • 29
    Ipv4 addresses address the addressing problem, but nobody addresses the /addresses/ problem. – Lodewijk Aug 02 '14 at 16:19
  • 7
    This has been since updated to 592, 708, 864 reserved addresses due to RFC 6598, resulting in 3,702,258,432 public addresses – wi1 Jul 04 '16 at 22:26
  • 1
    you said there are 4,294,967,296 "IP addressess ... in total" ... rather, there are 4,294,967,296 "possible combinations." 2^32 is correct per multiplication rule, answer correct, just used the slang description. "IP addresses" refers to possible and existing addresses, not just mathematical combinations that are theoretically possible. unless I am wrong? aren't some banned? (see below) @Marko – oemb1905 May 11 '17 at 02:16
  • 4
    Here is a point to ponder: 16 million of these addresses are allocated to the loopback. That is, we have 16 million ways to address localhost. Starting from 127.0.0.1, 127.0.0.2 and up to 127.255.255.254. I've been googling trying to find why, and so far I have not read a compelling use case for this phenomenal waste! – daparic Jan 27 '18 at 08:25
  • @ifelsemonkey I have `127.0.0.1`, `127.0.0.2`, `127.0.0.3`, and sometimes `127.0.0.4` in use on my debian box, various web servers all listening on the same ports. I think it also uses `127.0.1.1` for something. – ctrl-alt-delor Feb 20 '18 at 18:19
  • we have to remove some, because of sub-netting. Each subnet looses 2 addresses. – ctrl-alt-delor Feb 20 '18 at 18:20
  • Please edit your post to write out the numbers phonetically – Andy Ray Apr 19 '20 at 02:42
  • IPv6 solves the limited addressing problem by adding more addresses to the address space, resulting in more addresses overall. This addresses your address size question. – seeg Nov 24 '22 at 10:13
34

https://www.ripe.net/internet-coordination/press-centre/understanding-ip-addressing

For IPv4, this pool is 32-bits (2³²) in size and contains 4,294,967,296 IPv4 addresses.

In case of IPv6

The IPv6 address space is 128-bits (2¹²⁸) in size, containing 340,282,366,920,938,463,463,374,607,431,768,211,456 IPv6 addresses.

inclusive of RESERVED IP

 Reserved address blocks
 Range  Description Reference

 0.0.0.0/8  Current network (only valid as source address)  RFC 6890
 10.0.0.0/8 Private network RFC 1918
 100.64.0.0/10  Shared Address Space    RFC 6598
 127.0.0.0/8    Loopback    RFC 6890
 169.254.0.0/16 Link-local  RFC 3927
 172.16.0.0/12  Private network RFC 1918
 192.0.0.0/24   IETF Protocol Assignments   RFC 6890
 192.0.2.0/24   TEST-NET-1, documentation and examples  RFC 5737
 192.88.99.0/24 IPv6 to IPv4 relay (includes 2002::/16) RFC 3068
 192.168.0.0/16 Private network RFC 1918
 198.18.0.0/15  Network benchmark tests RFC 2544
 198.51.100.0/24    TEST-NET-2, documentation and examples  RFC 5737
 203.0.113.0/24 TEST-NET-3, documentation and examples  RFC 5737
 224.0.0.0/4    IP multicast (former Class D network)   RFC 5771
 240.0.0.0/4    Reserved (former Class E network)   RFC 1700
 255.255.255.255    Broadcast   RFC 919

wiki has full details and this has details of IPv6.

Andriy K
  • 3,302
  • 31
  • 42
ganesh
  • 780
  • 7
  • 19
18

Just a small correction for Marko's answer: exact number can't be produced out of some general calculations straight forward due to the next fact: Valid IP addresses should also not end with binary 0 or 1 sequences that have same length as zero sequence in subnet mask. So the final answer really depends on the total number of subnets (Marko's answer - 2 * total subnet count).

Andriy K
  • 3,302
  • 31
  • 42
  • 3
    From anonymous: Actually Marko's answer was correct for the question asked. You are answering a question which was not asked. The original question did not mention valid IP addresses. Addresses ending in 0 are valid addresses for a Network address. Addresses ending in 1 are valid host address. Addresses ending in 255 are valid broadcast addresses but not valid host address. You will be surprised that while most TCP/IP implementation will throw up an error if you try to add a broadcast or network address to IP host, there is at one vendor who will let you do it. I never figured out why. – Andriy K Jan 05 '15 at 19:24
  • 1
    addresses that end in 255 are not always valid broadcast addresses, also host addresses can end in 255. It all depends on your network mask – Gizmo Mar 10 '17 at 17:41
  • @AndriyK “Also, by Public IPs I mean not counting reserved…Only the ones that can be access through the internet. ” so this answer is correct. – ctrl-alt-delor Feb 20 '18 at 18:24
  • This is totally wrong. There's no requirement for a public network to even have a network or a broadcast address. I've successfully run services on a .0 of a public IPv4 network. – ximaera Oct 08 '19 at 14:24
3

Public IP Addresses

https://github.com/stephenlb/geo-ip will generate a list of Valid IP Public Addresses including Localities.

'1.0.0.0/8' to '191.0.0.0/8' are the valid public IP Address range exclusive of the reserved Private IP Addresses as follows:

import iptools
## Private IP Addresses
private_ips = iptools.IpRangeList(
    '0.0.0.0/8',      '10.0.0.0/8',     '100.64.0.0/10', '127.0.0.0/8',
    '169.254.0.0/16', '172.16.0.0/12',  '192.0.0.0/24',  '192.0.2.0/24',
    '192.88.99.0/24', '192.168.0.0/16', '198.18.0.0/15', '198.51.100.0/24',
    '203.0.113.0/24', '224.0.0.0/4',    '240.0.0.0/4',   '255.255.255.255/32'
)

IP Generator

Generates a JSON dump of IP Addresses and associated Geo information. Note that the valid public IP Address range is from '1.0.0.0/8' to '191.0.0.0/8' excluding the reserved Private IP Address ranges shown lower down in this readme.

docker build -t geo-ip .
docker run -e IPRANGE='54.0.0.0/30' geo-ip               ## a few IPs
docker run -e IPRANGE='54.0.0.0/26' geo-ip               ## a few more IPs
docker run -e IPRANGE='54.0.0.0/16' geo-ip               ## a lot more IPs
docker run -e IPRANGE='0.0.0.0/0'   geo-ip               ## ALL IPs ( slooooowwwwww )
docker run -e IPRANGE='0.0.0.0/0'   geo-ip > geo-ip.json ## ALL IPs saved to JSON File
docker run geo-ip 

A little faster option for scanning all valid public addresses:

for i in $(seq 1 191); do \
    docker run -e IPRANGE="$i.0.0.0/8" geo-ip; \
    sleep 1; \ 
done

This prints less than 4,228,250,625 JSON lines to STDOUT. Here is an example of one of the lines:

{"city": "Palo Alto", "ip": "0.0.0.0", "longitude": -122.1274,
 "continent": "North America", "continent_code": "NA",
 "state": "California", "country": "United States", "latitude": 37.418,
 "iso_code": "US", "state_code": "CA", "aso": "PubNub",
 "asn": "11404", "zip_code": "94107"}

Private and Reserved IP Range

The dockerfile in the repo above will exclude non-usable IP addresses following the guide from the wikipedia article: https://en.wikipedia.org/wiki/Reserved_IP_addresses

MaxMind Geo IP

The dockerfile imports a free public Database provided by https://www.maxmind.com/en/home

Stephen Blum
  • 6,498
  • 2
  • 34
  • 46
0

3.681 billion is the current total in the year 2020.

Source: https://blog.apnic.net/2020/01/21/addressing-2019/

cnd
  • 1,689
  • 16
  • 14