An IP address is made of 32 bits, "8" bits for each part of the address.
For example for an address like "192.168.0.1", we would have "8" bits representing "192", "8" bits representing "168" and so on.
Below is an "8" bits portion of an IP address:
For the number "192", we would have the below "8" bits:
When we apply a netmask to an IP address, we have the following:
- The "1" bits in the netmask means that the corresponding bit in the IP address belongs to the network part.
- The "0" bits in the netmask means that the corresponding bit in the IP address belongs to the host part.
Instead of buying separate IP address ranges for different departments in a company, we could buy for example a C class address, then we could divide it into smaller subnets.
A C class address is usually used for networks that have a limited number of machines.
A C class could have IP addresses that go from "192.0.0.0" to "18.104.22.168".
A C class address has a network mask of "/24", since "24" bits from the whole address are assigned to the network part:
For example, if we have the network IP address "22.214.171.124/24", the default "/24" netmask gives us access to "1" network of 254 hosts.
We could take some bits from the host part of the IP address and assign then to the network .
We would have more subnets but less hosts, since we have used bits from the host part in the network part of the address.
If we use the netmask "/26" for example, we take two bits from the host part and assign them to the network part.
We are left with "6" bits for the hosts.
We get the number of possible subnets using the below formula:
we would have "4" subnets, because we took "2" bits from the host part.
- ** : means to the power of.
To get the number of hosts we use the below formula:
We substract "2", since we have two IP addresses "xxx.xxx.xxx.0" and "xxx.xxx.xxx.255", they represent the network address and the broadcast address respectively.
These IP addresses can't be assigned to hosts.
We get the below number of IP addresses that can be assigned to hosts for each subnet: