CCNA | P4: IPv4 Addressing | C3: Analyzing Subnet Masks
Subnet masks are an essential part of IP addressing and are used to divide IP addresses into network and host portions. Analyzing subnet masks is an important skill for network administrators.
Lesson Contents
- What are Subnet Masks?
- Types of Subnet Masks
- How does a subnet mask work?
- Subnet Calculation By Hand
- Calculating hosts or subnets based on the subnet mask
- Conclusion
What are Subnet Masks?
Subnet masks use the 32-bit structure of the IP address to divide it into two parts: the network ID and the host ID. The subnet mask tells us which bits are for the network ID and which bits are for the host ID.
When the subnet mask bit is set to one, this means it is part of the network. A bit marked as zero is part of the host ID.
Types of Subnet Masks
There are three different notations for subnet masks:
- Binary
- Dotted-Decimal Notation (DDN)
- Prefix or CIDR Notation.
In this blog post, we will discuss how to analyze subnet masks in each of these notations.
1.Binary Notation
The binary notation for subnet masks represents the mask as a 32-bit binary number.
The mask divides the IP address into two parts: the network part and the host part.
The network part is represented by the 1s in the mask, and the host part is represented by the 0s.
For example, the subnet mask 11111111 11111111 11111111 00000000
represents a network with 24 bits for the network part and 8 bits for the host part.
2.Dotted-Decimal Notation
The dotted-decimal notation (DDN) for subnet masks is the most commonly used notation.
It represents the mask as four decimal numbers separated by dots. Each decimal number represents 8 bits of the mask.
For example, the subnet mask 11111111 11111111 11111111 00000000
in DDN is 255.255.255.0
.
3.Prefix or CIDR Notation
The prefix or CIDR notation for subnet masks is a compact representation of the mask.
It represents the mask as a number followed by a slash (/) and the number of bits in the mask.
For example, the subnet mask 11111111 11111111 11111111 00000000
in prefix notation is /24
.
How does a subnet mask work?
A subnet mask works like a filter, helping to route traffic inside a subnet.
The subnet mask tells the router which numbers it should look at and which ones it should ignore beneath the mask.
For example, when a binary mask is laid over an IP address also translated into binary, a 1 over a number tells the router to look at the number beneath, and a 0 says to ignore the number.
The subnet mask tells a router which bits to pay attention to when calculating the network ID portion of an IP address.
Subnet Calculation By Hand
You can calculate IPv4 subnet masks by hand if you so desire, but it is much easier to just use a subnet calculator which is hosted on this blog.
For the die-hard, however, let’s walk you through IP subnetting step by step.
By default, the subnet mask for a Class C IP address class is set to 255.255.255.0, meaning that the first 3 octets (24 bits) in an IP address are used to identify the network ID, and the last octet (8 bits) are dedicated to the host ID.
But subnetting your network by hand can be tricky. Using an online subnet calculator like my own Subnet Calculator can quickly help you divide your IP network into smaller subnet ranges.
That means that on this particular subnet, there are 256 possible IP addresses. How did we figure this out? Remember that 255 is the highest number that can be represented in binary with 8 bits. To get to 255, all of the 8 bits must be set to 1, each one representing a number in decimal (1+2+4+8+16+32+64+128=255). When you include the number zero that makes 256 possible values.
But if we had a subnet mask of 255.255.255.192, that would mean there are only 6 bits available to us (we get 192 because the bits representing 128 and 64 are masked out). Because 63 is the highest decimal value that can be represented with 6 binary bits (1 + 2 + 4 + 8 + 16 + 32), when you add the zero, that makes 64 possible values.
Calculating hosts or subnets based on the subnet mask
A quicker way to figure out how many hosts will exist on a particular subnet is to use the formula 2n-2
, where n is the number of bits available to the host ID, where 2n represents 2 raised to the nth power.
You must then subtract two from the result because 2 addresses are reserved for the network ID and broadcast address or ID.
So in our examples above:
2^n-2 where n is 8 for 8 bits
2^8 – 2 = 254
2^n-2 where n is 6 for 6 bits
2^6 – 2 = 62
But you don’t have to do that work manually. If you're going to calculate a subnet mask, here’s a quick cheat sheet to help you figure out how many host addresses are available depending upon the CIDR notation.
CIDR Notation | Available IP Addresses | Hosts | Netmask |
---|---|---|---|
/30 | 4 | 2 | 255.255.255.252 |
/29 | 8 | 6 | 255.255.255.248 |
/28 | 16 | 14 | 255.255.255.240 |
/27 | 32 | 30 | 255.255.255.224 |
/26 | 64 | 62 | 255.255.255.192 |
/25 | 128 | 126 | 255.255.255.128 |
/24 | 256 | 254 | 255.255.255.0 |
/23 | 512 | 510 | 255.255.254.0 |
/22 | 1,024 | 1,022 | 255.255.252.0 |
/21 | 2,048 | 2,046 | 255.255.248.0 |
/20 | 4,096 | 4,094 | 255.255.240.0 |
/19 | 8,192 | 8,190 | 255.255.224.0 |
/18 | 16,384 | 16,382 | 255.255.192.0 |
/17 | 32,768 | 32,766 | 255.255.128.0 |
/16 | 65,536 | 65,534 | 255.255.0.0 |
/15 | 131,072 | 131,070 | 255.254.0.0 |
/14 | 262,144 | 262,142 | 255.252.0.0 |
/13 | 524,288 | 524,286 | 255.248.0.0 |
/12 | 1,048,576 | 1,048,574 | 255.240.0.0 |
/11 | 2,097,152 | 2,097,150 | 255.224.0.0 |
/10 | 4,194,304 | 4,194,302 | 255.192.0.0 |
/9 | 8,388,608 | 8,388,606 | 255.128.0.0 |
/8 | 16,777,216 | 16,777,214 | 255.0.0.0 |
/7 | 33,554,432 | 33,554,430 | 254.0.0.0 |
/6 | 67,108,864 | 67,108,862 | 252.0.0.0 |
/5 | 134,217,728 | 134,217,726 | 248.0.0.0 |
/4 | 268,435,456 | 268,435,454 | 240.0.0.0 |
/3 | 536,870,912 | 536,870,910 | 224.0.0.0 |
/2 | 1,073,741,824 | 1,073,741,822 | 192.0.0.0 |
/1 | 2,147,483,648 | 2,147,483,646 | 128.0.0.0 |
/0 | 4,29,49,67,294 | 4,29,49,67,294 | 0.0.0.0 |
Conclusion
Subnet masks are an essential part of IP addressing and are used to divide IP addresses into network and host portions. Analyzing subnet masks is an important skill for network administrators.
In this blog post, we discussed the three different notations for subnet masks: binary, dotted-decimal notation (DDN), and prefix or CIDR notation.
We also discussed how to analyze subnet masks in each of these notations. We learned that a subnet mask works like a filter, helping to route traffic inside a subnet.
The subnet mask tells the router which numbers it should look at and which ones it should ignore beneath the mask.
We also learned how to calculate the number of hosts that will exist on a particular subnet using the formula 2^n-2, where n is the number of bits available to the host ID.
With this knowledge, you should be able to analyze subnet masks and understand how they are used in IP addressing. Happy subnetting! 😊