1

I would like to explain with an example.

If I am right, the IP range of 20.0.0.0/24 is as follows:

  • CIDR Range: 20.0.0.0/24
  • Netmask: 255.255.255.0
  • Wildcard Bits: 0.0.0.255
  • First IP: 20.0.0.0
  • Last IP: 20.0.0.255
  • Total Host: 256

Also if I am right, we can assign any IP between 20.0.0.0 and 20.0.0.255 to a host or a host can get any IP between 20.0.0.0 and 20.0.0.255.

If I want address spaces and CIDR for limited hosts e.g. between 10-12 hosts, can I calculate Address Spaces/ CIDR for such requirements? If yes, how to calculate?

melpomene
  • 84,125
  • 8
  • 85
  • 148
TekQ
  • 25
  • 7
  • 2
    You can find many CIDR calculators online, such as http://cidr.xyz – P Varga Mar 01 '19 at 21:52
  • The link http://cidr.xyz/ is helpful to find IP range of a CIDR format. The example I explained says, total number of host is 256. I am looking for a calculation or a link so that I can find a CIDR having total number of host is 15 in its IP range. I hope I explained well. – TekQ Mar 01 '19 at 22:52
  • But the number of hosts can only be a power of 2 – P Varga Mar 01 '19 at 22:53
  • Okay. For 256 hosts, I believe, its 2⁸ = 2×2×2×2×2×2×2×2 = 256. Ignore 15 hosts. For 16 hosts, I believe, it should be 2⁴ = 2×2×2×2 = 16. Now how to calculate CIDR format for total hosts for 2⁴? – TekQ Mar 01 '19 at 23:13
  • This one can be helpful for quick tests if you want to convert cidr to Ip and have info such as nr of hosts, and then back from IPs to CIDR 20.0.0.0/24 https://www.ipconvertertools.com – Pikk Mar 02 '19 at 20:33

1 Answers1

0

To get the CIDR containing N number of hosts, use 2⁵ - log₂N. I wrote a quick calculator [Run it]:

document.querySelector('input').addEventListener('input', ({target: {value}}) => {
  document.querySelector('output').textContent =
    2**5 - Math.log2(Number(value));
});
Hosts: <input type="number" />
CIDR: /<output></output>
P Varga
  • 19,174
  • 12
  • 70
  • 108