CIDR (Classless Inter-Domain Routing) is the Internet addressing scheme used to identify networks, and subnet masks, which divide large networks into smaller networks, are an integral part of CIDR.

In my daily work, sometimes I do need to find out all these but as I am not really a network guy therefore will need to find some easy ways to calculate all this information

In this blog post, we’ll look at how to calculate the subnet masks from CIDR. Let’s get started!


What is a subnet mask?

In IPv4, a subnet mask is a 32-bit number consisting of four octets (groups of eight bits) written in number form (e.g. 255.255.255.0). The bits set to 1 in the mask indicate which part of the IP address is the network portion and which part is the host portion.

For instance, if an IP address is 192.168.1.1 and the subnet mask is 255.255.255.0, then the first three octets (192.168.1) represent the network portion, while the final octet (1) represents the host portion. This means that any device with an IP address in the range of 192.168.1.1 to 192.168.1.255 belongs to the same network.

Subnetting allows multiple networks to be created within a larger network, improving its performance and security.


How to calculate a subnet mask from CIDR notation?

In order to calculate a subnet mask from CIDR notation, follow these steps:

  1. Convert the CIDR notation to a subnet mask in binary form:
    • For example, for a CIDR notation of /24, the binary equivalent would be 11111111.11111111.11111111.00000000.
  2. Convert the binary subnet mask to IPv4 format:
    • Translate the binary representation 11111111.11111111.11111111.00000000 to its IPv4 format equivalent of 255.255.255.0. This subnet mask in decimal form is 255.255.255.0.

In binary, 11111111 refers to 255 and 00000000 refers to 0.

Table for CIDR Notation to Subnet Mask (Cheat Sheet)

Alternatively, you can refer the a full table for converting CIDR notation to subnet mask:

CIDR NotationSubnet Mask
/00.0.0.0
/1128.0.0.0
/2192.0.0.0
/3224.0.0.0
/4240.0.0.0
/5248.0.0.0
/6252.0.0.0
/7254.0.0.0
/8255.0.0.0
/9255.128.0.0
/10255.192.0.0
/11255.224.0.0
/12255.240.0.0
/13255.248.0.0
/14255.252.0.0
/15255.254.0.0
/16255.255.0.0
/17255.255.128.0
/18255.255.192.0
/19255.255.224.0
/20255.255.240.0
/21255.255.248.0
/22255.255.252.0
/23255.255.254.0
/24255.255.255.0
/25255.255.255.128
/26255.255.255.192
/27255.255.255.224
/28255.255.255.240
/29255.255.255.248
/30255.255.255.252
/31255.255.255.254
/32255.255.255.255

CIDR notation is used to indicate how many bits of an IP address are used for the network portion.

This is done by setting the corresponding number of bits to 1 in the subnet mask. Hence, the subnet mask determines which portion of the IP address is used for the network and which portion is used for the host.


How To calculate subnet masks correctly – Using Network Subnet Calculator

Maybe the easiest, fastest, and more accurate way will be using the network subnet calculator to help you get the info you needed.

I actually used ChatGPT to come out with a simple web calculator for subnet:

For example, I need to find out information about the subnet mask and other info for 192.168.246.20/24. I can just simply input this in and hit the Calculate button

Network Subnet Calculator

It will be based on the IP address given and provide me the information like the subnet mask which is 255.255.255.0 and other useful information like the broadcast address, number of hosts, and first and last host IP.

How To calculate subnet masks correctly - Using Network Subnet Calculator

Conclusion

In this blog post, I have briefly shared d how to calculate subnet masks from CIDR easily using the calculator.

Also, provide you with more info about network subnetting and a full table for you to reference based on CIDR notation and subnet masks.

I hope you found the information helpful. If you have any questions or want more information about specific products, please leave a comment below – I look forward to hearing from you!

Categorized in: