Networking

How to Determine What Netmask to Use?

The Internet has become ubiquitous. Devices connected to the internet require an IP address to communicate with other devices on the internet. With the rise of the internet, especially IOT (Internet of things), the available IPv4 space is shrinking. This has created a serious issue for the growth of internetworks. To handle this situation, many solutions like DHCP addressing, CIDR, NAT etc., are introduced.

Need for Subnetting

Managing a network becomes more and more sophisticated as it grows gradually. Network administrators usually use the concept of subnetting to manage a giant computer network. Subnetting is a process of dividing an IP network into smaller sub networks, or subnets. It improves the management and security of a network. Subnetting uses subnet mask or Netmask to specify the number of hosts in a network.

Netmask and subnet mask both work the same way, with the exception that subnet mask takes a portion of bits from the host part of the address (host bits are converted to network bits) to determine a subnet. This is termed as borrowing bits. By taking bits from the host part, we can create more sub networks, or subnets, but these new subnets will have less number of hosts. When we borrow bits from the host part, the subnet mask will be changed.

What Will We Cover?

In this guide, we will see how to determine a netmask or subnet mask. We will also learn to calculate the first and last address, number of addresses using the subnet mask. Before we proceed, let us first understand the difference between Classful and Classless Addressing Scheme.

Classful vs Classless Addressing Scheme

Classful address scheme had a number of limitations. CIDR or Classless Inter-Domain Routing, is more efficient as compared to classful addressing in assigning network addresses.

Consider the number of networks and hosts in classful addressing:

  1. Class A has a subnet mask of 255.0.0.0 with 126 networks (2^7-2) and 16777214 hosts (2^24-2).
  2. Class B has a subnet mask of 255.255.0.0 with 16384 networks (2^14) and 65534 hosts (2^16-2).
  3. Class C has a subnet mask of 255.255.255.0 with 2097152 networks (2^21) and 254 hosts (2^8-2).

We can observe that Class A has a larger number of hosts addresses than required by almost any organization, resulting in wastage of millions of class A addresses. Similarly, Class B also has a larger number of addresses than the requirement of a mid-size organization. In case of Class C, the number of host addresses are very small for most of the organizations. In such a scenario, CIDR or Classless Inter-Domain Routing scheme comes to rescue. CIDR supports masks of arbitrary length like /23, /11, /9 etc.

Determining Netmask or Subnet Mask to Use

To illustrate the CIDR concept, consider an organization that requires 10000 addresses for it’s host devices. If we use classful addressing, then the Class B network is more efficient here as compared to Class A and Class C. But still there are 55534 unusable IP addresses in this case. In case we use the CIDR, the network can be assigned a continuous block of /18 with 16384 hosts. The subnet mask in this case will be 255.255.192.0. The below picture shows a portion of CIDR block prefix and the corresponding number of Host addresses.

CIDR Block Prefix Number of Host Addresses
/27 32
/26 64
/25 128
/24 256
/23 512
/22 1024
/21 2048
/20 4096
/19 8192
/18 16384

In the same way if we need 800 host addresses, Class B will result in the wastage of ~64,700 addresses. If we use Class C addressing, we will need to introduce 4 new routes in the routing tables. On the other hand, if we use the CIDR scheme, we can assign a /22 block and get 1024 (2^10) IP addresses.

Using the Netmask or Subnet Mask

We can use the Netmask or Subnet mask to get the first address, the last address, the number of addresses corresponding to a given IP address.

1. To find the first Address, we need to do an AND operation of the given IP address and the subnet mask. For example, if our IP is 205.16.37.39 i.e. 11001101.00010000.00100101.00100111 and subnet mask is /28 i.e. 11111111 11111111 11111111 11110000, we can find the first address as:

Address:         11001101 00010000 00100101 00100111
Mask:             11111111 11111111 11111111 11110000
First address: 11001101 00010000 00100101 00100000

2. Similarly, last address can be found by OR operation of given IP address and 1’s complement of subnet mask as shown below:

Address:                                    11001101 00010000 00100101 00100111
Subnet mask’s complement:     00000000 00000000 00000000 00001111
Last address:                             11001101 00010000 00100101 00101111

3. To obtain the number of addresses, complement (1’s complement) the subnet mask and convert the result to decimal form and add 1 to it:

Subnet mask’s complement:  00000000 00000000 00000000 00001111 = (15)10

Number of addresses = 15+1 =16

Conclusion

That’s All. In this guide we learned about using Netmask or Subnet Mask and how to calculate first and last address etc. It is very essential for IT professionals to design and efficiently use the available IP space of their organization.

About the author

Ali Imran Nagori

Ali imran is a technical writer and Linux enthusiast who loves to write about Linux system administration and related technologies. You can connect with him on LinkedIn
.