Understanding CIDR Notation and Subnet Masks: A Quick Guide
Steven Wright
Networking & Security Architect | Application Delivery, Networking, Security Solutions
I was recently asked how I calculated the subnet mask for a /25 CIDR notation. While I mostly convert CIDR notation and subnet masks from memory, I thought it might be helpful to explain the process.?
For those involved in network configuration, grasping the principles of IP addressing, including CIDR conversion and subnetting, is critical.
?
IP Addressing Basics: Understanding IP Addresses and Subnet Masks
IP addresses and subnet masks are 32-bit numbers, divided into four sections, or ‘octets’, each ranging from 0 to 255 and usually written in decimal form. Subnet masks are used to divide IP addresses into two parts: a network and a local portion.
For example, if we have a device with an IP address of 192.168.1.1 and a subnet mask of 255.255.255.0 (a /24 in CIDR notation), the network portion is ‘192.168.1’ and the local or host portion ‘.1’. The computer can then use this information to understand which hosts it should be able to directly reach.
?
Binary Basics: Converting IP Addresses and Subnet Masks
While we use decimal notation for ease (reading long binary strings being quite dull), IP addresses are fundamentally binary. ?In binary notation, each '1' or '0' is a "bit." Starting from the left, the first bit in each octet is worth 128, the second bit is worth 64, then 32, 16, 8, 4, 2, and 1.
Here is an IP address in binary for you to try and convert: 11000000.10101000.00000001.00000001
Here is a subnet mask for you to try and convert:
11111111.11111111.11111111.00000000
?
The Bitwise AND Operation
A bitwise “AND” operation takes two binary inputs and produces a single output. If both inputs are ‘1’, the output is also ‘1’, else it is ‘0’.? If we take the IP address and subnet mask above and perform an AND operation, we can determine the “network address” is 11000000.10101000.00000001.00000000 (192.168.1.0).
领英推荐
When your computer needs to determine if a destination IP address is within the same network, it can now perform the same calculation and check if the network addresses match.
?
CIDR Notation: Streamlined Segmentation
CIDR (Classless Inter-Domain Routing) notations, like /24 and /25, are another way of dividing IP addresses into a network and a local portion. In CIDR notation, the number after the slash indicates how many of the 32 bits are used for the network portion, with the remaining bits being used for local addresses within that network.
In CIDR notation, a /25 (255.255.255.128) means that the first 25 binary bits are used for the network portion. The first three octets of the subnet will therefore be comprised of 24 binary bits set to 1, leaving a single further bit to be set, which we will set in the fourth octet.
/25 = 11111111.11111111.11111111.10000000
The first “1” in each of the “11111111” octets is worth 128, the second “1” 64, the third “32”, etc and we can multiply 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 to reach 255.
In the fourth octet, we have a single ‘1’, worth 128. ?
As we can observe, this gives us 255.255.255.128
?
The Role of Subnetting in Network Management
The remaining 7 bits can then be used for device addresses within the local network. Thus, the CIDR notation is converted to a subnet mask and helps dividing the network into smaller parts and managing them effectively.
?
Student JITA
3 个月I've been trying to nail down CIDR notation so I can explain it in a job interview if someone asks. I was already comfortable with its purpose and role, but this helped me improve how to speak about it when asked for details. Thanks.