Subnetting is an act of breaking up a giant network into a bunch of smaller ones. A subnet mask is a 32-bit value that allows the device that’s receiving IP packets to distinguish the network ID portion of the IP address from the host ID portion of the IP address. This 32-bit subnet mask is composed of 1s and 0s, where the 1s represent the positions that refer to the network subnet addresses.
Not all networks need subnets, and if not, it means that they’re using the default subnet mask, which is the same as saying that a network doesn’t have a subnet address.
The table below shows the default subnet masks for Classes A, B, and C.
Although you can use any mask in any way on an interface, typically it’s not usually good to mess with the default masks. In other words, you don’t want to make a Class B subnet mask read 255.0.0.0, and some hosts won’t even let you type it in. But these days, most devices will. For a Class A network, you wouldn’t change the first byte in a subnet mask because it should read 255.0.0.0 at a minimum. Similarly, you wouldn’t assign 255.255.255.255 because this is all 1s, which is a broadcast address. A Class B address starts with 255.255.0.0, and Class C starts with 255.255.255.0.
Classless Inter-Domain Routing (CIDR)
It’s the method that Internet service providers (ISPs) use to allocate several addresses to a company, a home—their customers.
When you receive a block of addresses from an ISP, what you get will look something like this: 192.168.10.32/28. This is telling you what your subnet mask is. The slash notation (/) means how many bits are turned on (1s). The maximum could only be /32 because a byte is 8 bits and there are 4 bytes in an IP address: (4 n 8 = 32). But keep in mind that regardless of the class of address, the largest subnet mask available can only be a /30 because you’ve got to keep at least 2 bits for host bits.
Take, for example, a Class A default subnet mask, which is 255.0.0.0. This tells us that the first byte of the subnet mask is all ones (1s), or 11111111. When referring to a slash notation, you need to count all the 1-bits to figure out your mask. The 255.0.0.0 is considered a /8 because it has 8 bits that are 1s—that is, 8 bits that are turned on. A Class B default mask would be 255.255.0.0, which is a /16 because 16 bits are ones (1s): 11111111.11111111.00000000. 00000000.
The Table below has a listing of every available subnet mask and its equivalent CIDR slash notation.
The /8 through /15 can only be used with Class A network addresses. /16 through /23 can be used by Class A and B network addresses. /24 through /30 can be used by Class A, B, and C network addresses. This is a big reason why most companies use Class A network addresses. Since they can use all subnet masks, they get the maximum flexibility in network design.
Subnetting Class C Addresses
There are many ways to subnet a network. The right way is the way that works best for you. In a Class C address, only 8 bits are available for defining the hosts. Remember that subnet bits start at the left and move to the right, without skipping bits. This means that the only Class C subnet masks can be the following:
We can’t use a /31 or /32 because, as I’ve said, we must have at least 2 host bits for assigning IP addresses to hosts. But this is only mostly true. we can never use a /32 because that would mean zero host bits available.
Subnetting a Class C Address—The Fast Way!
When you’ve chosen a possible subnet mask for your network and need to determine the number of subnets, valid hosts, and the broadcast addresses of a subnet that mask will provide, all you need to do is answer five simple questions:
- How many subnets does the chosen subnet mask produce?
2. How many valid hosts per subnet are available?
3. What are the valid subnets?
4. What’s the broadcast address of each subnet?
5. What are the valid hosts in each subnet?
Below are the answer to the above questions.
1. How many subnets? 2x = number of subnets. x is the number of masked bits or the 1s. For example, in 11000000, the number of 1s gives us 22 subnets. So in this example, there are 4 subnets.
2. How many hosts per subnet? 2y – 2 = number of hosts per subnet. y is the number of unmasked bits or the 0s. For example, in 11000000, the number of 0s gives us 26 – 2 hosts or 62 hosts per subnet. You need to subtract 2 for the subnet address and the broadcast address, which are not valid hosts.
3. What are the valid subnets? 256 – subnet mask = block size, or increment number. An example would be the 255.255.255.192 mask, where the interesting octet is the fourth
4. octet (interesting because that is where our subnet numbers are). Just use this math: 256 – 192 = 64. The block size of a 192 mask is always 64. Start counting at zero in blocks of 64 until you reach the subnet mask value and these are your subnets in the fourth octet: 0, 64, 128, 192.
5. What’s the broadcast address for each subnet? Now here’s the really easy part. Since we counted our subnets in the last section as 0, 64, 128, and 192, the broadcast address is always the number right before the next subnet. For example, the 0 subnet has a broadcast address of 63 because the next subnet is 64. The 64 subnet has a broadcast address of 127 because the next subnet is 128, and so on. Remember, the broadcast address of the last subnet is always 255.
1. What are the valid hosts? Valid hosts are the numbers between the subnets, omitting the all-0s and all-1s. For example, if 64 is the subnet number and 127 is the broadcast address, then 65–126 is the valid host range. Your valid range is always the group of numbers between the subnet address and the broadcast address.
Let answer the following questions.
- Let use the below 5 questions to solve is 255.255.255.128 (/25)
Since 128 is 10000000 in binary, there is only 1 bit for subnetting and 7 bits for hosts. We’re going to subnet the Class C network address 192.168.10.0.
192.168.10.0 = Network address
255.255.255.128 = Subnet mask
Question 1: How many subnets? Since 128 is 1 bit on (10000000), the answer would be 2^1 = 2.
Question 2: How many hosts per subnet? We have 7 host bits off (10000000), so the equation would be 27 – 2 = 126 hosts. Once you figure out the block size of a mask, the amount of hosts is always the block size minus 2.
Question 3: What are the valid subnets? 256 – 128 = 128. Remember, we’ll start at zero and count in our block size, so our subnets are 0, 128. By just counting your subnets when counting in your block size.
Question 4: What’s the broadcast address for each subnet? The number right before the value of the next subnet is all host bits turned on and equals the broadcast address. For the zero subnets, the next subnet is 128, so the broadcast of the 0 subnets is 127.
Question 4: What are the valid hosts? These are the numbers between the subnet and broadcast address. The easiest way to find the hosts is to write out the subnet address and the broadcast address, which makes valid hosts completely obvious. The following table shows the 0 and 128 subnets, the valid host ranges of each, and the broadcast address of both subnets:
2. Let used the below 5 questions to solve is 255.255.255.192(/26)
we’re going to subnet the network address 192.168.10.0 using the subnet mask 255.255.255.192.
192.168.10.0 = Network address
255.255.255.192 = Subnet mask
So let answer the following questions.
- How many subnets? Since 192 is 2 bits on (11000000), the answer would be 22 = 4 subnets.
2. How many hosts per subnet? We have 6 host bits off (11000000), giving us 26 – 2 = 62 hosts. The amount of hosts is always the block size minus 2.
3. What are the valid subnets? 256 – 192 = 64. Remember, to start at zero and count in our block size. This means our subnets are 0, 64, 128, and 192. We can see we have a block size of 64, so we have 4 subnets, each with 62 hosts.
4. What’s the broadcast address for each subnet? The number right before the value of the next subnet is all host bits turned on and equals the broadcast address. For the zero subnets, the next subnet is 64, so the broadcast address for the zero subnets is 63.
5. What are the valid hosts? These are the numbers between the subnet and broadcast address. As I said, the easiest way to find the hosts is to write out the subnet address and the broadcast address, which clearly delimits our valid hosts. The following table shows the 0, 64, 128, and 192 subnets, the valid host ranges of each, and the broadcast address of each subnet:
The below table makes subnetting easy to solve.
Regardless of whether you have a Class A, Class B, or Class C address, the /30 mask will provide you with only two hosts, ever.
Subnetting Class B Addresses
Before we dive into this, let’s look at all the possible Class B subnet masks first. Notice that we have a lot more possible subnet masks than we do with a Class C network address:
We know the Class B network address has 16 bits available for host addressing. This means we can use up to 14 bits for subnetting because we need to leave at least 2 bits for host addressing. Using a /16 means you are not subnetting with Class B, but it is a mask you can use.
Subnetting Practice Examples: Class B Addresses
Subnetting Class B is the same as subnetting with Class C, except we start in the third octet—with the same numbers.
Example 1: Used the subnet to answer the below questions 255.255.128.0 (/17)
172.16.0.0 = Network address
255.255.128.0 = Subnet mask
Question 1: How many subnets?
Answer= 2^1 = 2
Question 2: How many hosts are on the subnet?
Answer = 2^15 -2 = 32,766.
Question 3: What is the valid subnet?
Answer= 256 – 128 = 128. 0, 128. Remember that subnetting is performed in the third octet, so the subnet numbers are 0.0 and 128.0, as shown in the next table. These are the exact numbers we used with Class C; we use them in the third octet and add a 0 in the fourth octet for the network address.
The table below shows the two subnets available, the valid host range, and the broadcast address.
Subnetting in Your Head: Class B Addresses
Are you nuts? Does Subnet Class B address in our heads? It’s actually easier than writing it out— I’m not kidding! Let me show you how:
Question 1: What is the subnet and broadcast address of the subnet in which 172.16.10.33 /27 resides?
Answer: The interesting octet is the fourth one. 256 – 224 = 32. 32 + 32 = 64. You’ve got it: 33 is between 32 and 64. But remember that the third octet is considered part of the subnet, so the answer would be the 10.32 subnet. The broadcast is 10.63 since 10.64 is the next subnet. That was a pretty easy one.
Question 2: What subnet and broadcast address is the IP address 172.16.66.10 255.255.192.0 (/18) a member of?
Answer: The interesting octet here is the third octet instead of the fourth one. 256 – 192 = 64. 0, 64, 128. The subnet is 172.16.64.0. The broadcast must be 172.16.127.255 since 128.0 is the next subnet.
Question 2: What subnet and broadcast address is the IP address 172.16.50.10 255.255.224.0 (/19) a member of?
Answer: 256 – 224 = 0, 32, 64 (remember, we always start counting at 0). The subnet is 172.16.32.0, and the broadcast must be 172.16.63.255 since 64.0 is the next subnet.
Question 3: What subnet and broadcast address is the IP address 172.16.46.255 255.255.240.0 (/20) a member of?
Answer: 256 – 240 = 16. The third octet is important here: 0, 16, 32, 48. This subnet address must be in the 172.16.32.0 subnet, and the broadcast must be 172.16.47.255 since 48.0 is the next subnet. So, yes, 172.16.46.255 is a valid host.
Question 4: What subnet and broadcast address is the IP address 172.16.45.14 255.255.255.252 (/30) a member of?
Answer: Where is our interesting octet? 256 – 252 = 0, 4, 8, 12, 16—the fourth. The subnet is 172.16.45.12, with a broadcast of 172.16.45.15 because the next subnet is 172.16.45.16. Question 5: What is the subnet and broadcast address of the host 172.16.88.255/20?
Answer: What is a /20 written out in dotted decimal? If you can’t answer this, you can’t answer this question, can you? A /20 is 255.255.240.0, gives us a block size of 16 in the third octet, and since no subnet bits are on in the fourth octet, the answer is always 0 and 255 in the fourth octet: 0, 16, 32, 48, 64, 80, 96. Because 88 is between 80 and 96, the subnet is 80.0 and the broadcast address is 95.255.
Question 6: A router receives a packet on an interface with a destination address of 172.16.46.191/26. What will the router do with this packet? Answer: Discard it. Do you know why? 172.16.46.191/26 is a 255.255.255.192 mask, which gives us a block size of 64. Our subnets are then 0, 64, 128, and 192. 191 is the broadcast address of the 128 subnets, and by default, a router will discard any broadcast packets.
Subnetting Class A Addresses
You don’t go about Class A subnetting any differently than Classes B and C, but there are 24 bits to play with instead of the 16 in a Class B address and the 8 in a Class C address. Let’s start by listing all the Class A masks:
The reason class A addresses are so popular to implement is because they give the most flexibility. You can subnet in the 2nd, 3rd or 4th octet.
Examples: Class A Addresses
Example 1 1: 255.255.0.0 (/16)
Class A addresses use a default mask of 255.0.0.0, which leaves 22 bits for subnetting because you must leave 2 bits for host addressing. The 255.255.0.0 mask with a Class A address is using 8 subnet bits:
Question 1How many Subnets do we have? 2^8 = 256.
How many Hosts do we have? 2^16 – 2 = 65,534.
Example 2: 255.255.240.0 (/20)
255.255.240.0 gives us 12 bits of subnetting and leaves us 12 bits for host addressing.
How many Subnets? 2^12 = 4096.
How many Hosts? 2^12 – 2 = 4094.