3

I have two ips:

1. 1.1.1.1
2. 4.4.4.4

obviously this is just an example, this is a dynamic calculator

how do i calculate number of hosts between said ips if subnet mask is irrelevant?

Mickey Perlstein
  • 1,894
  • 2
  • 23
  • 31

2 Answers2

7

To calculate the number of (theoretical) IP addresses you would convert each IP address to it's 32 bit integer format (which is actually what it really is), then it's just a matter of simple subtraction:

1.1.1.1 = 0x01010101 = 16843009
4.4.4.4 = 0x04040404 = 67372036

Number of addresses excluding the start and end address:

67372036 - 16843009 - 1 = 50529026

Number of addresses including the start and end address:

67372036 - 16843009 + 1 = 50529028

The number of actual usable addresses would be somewhat lower. Normally a few addresses in each C range is reserved for things like the gateway (router).

Guffa
  • 640,220
  • 96
  • 678
  • 956
  • Shouldn't you use `+2`/`-2` instead of `1`? – CustomX Nov 26 '14 at 15:44
  • @CustomX: No. Look for example at the numbers between 5 and 7; there are 3 numbers including the start and end (5,6,7) and 1 number excluding the start and end (6). The difference between 5 and 7 is 2, so the number of numbers including start and end is 2 + 1 and the number of numbers excluding start and end is 2 - 1. – Guffa Nov 26 '14 at 15:48
1

IPv4 address can be represented by an integer (4 bytes, 32 bits)

To simplify the question, assuming

  • All IP addresses are usable
  • One host per IP address

Then, converting both IP addresses to integer and work out the difference would be the number of hosts available.

Community
  • 1
  • 1
Neverever
  • 13,862
  • 3
  • 28
  • 47