03 Mar 2011 - Lab-Rat
Wendall Odom taught me subnetting after I just couldn’t get it for years. A subnet mask is just a filter to show which bits belong to the network, and which belong to the host. When I first learned to subnet I did it in binary, which was slow and painful. This method uses decimal (mostly, you have to know a bit of binary to get the correct decimal mask value). Here’s how it works
1. If the mask is in slash notation (i.e. 192.168.12.7/28) convert the mask into dotted decimal. It’s easier if you just remember the following conversions for adding up bits from most significant to least:
1 bit = 128
2 bits= 192
3 bits= 224
4 bits= 240
5 bits= 248
6 bits= 252
7 bits= 254
8 bits= 255
So for our /28, the mask would be:
8 bits for the first octet (takes care of 8/28 network bits): 255
8 bits for the second octet(takes care of 16/28 network bits): 255
8 bits for the third octet (takes care of 24/28 network bits): 255
4 bits for the fourth octet (takes care of 28/28 network bits): 240
This yields a decimal mask of 255.255.255.240. The interesting octet is the one that doesn’t contain a 0 or 255. To determine the network, first, last, and broadcast addresses, use the following rules.
2. If the corresponding mask octet is 255, just copy the ip address straight down.
192.168.12 .7
255.255.255.240
-————–
192.68.12.?
3. If the corresponding mask octet is 0, put a zero down.
- No zeros in this example mask
4. If the mask is the interesting octet, subtract the interesting octet from 256.
256 - 240 = 16
This gives you the network ranges. So the network ranges are:
192.168.12.0
192.168.12.16
192.168.12.32
192.168.12.64
192.168.12.80
192.168.12.96
192.168.12.112
192.168.12.128
192.168.12.144
192.168.12.160
192.168.12.176
192.168.12.192
192.168.12.208
192.168.12.224
192.168.12.240
5. Pick the multiple of the network range that your host value falls in. This is the network id. Our ip address is 192.168.12.7, which means it falls in the 192.168.12.0-15/28 network. If it was 192.168.12.145/28, it would fall in the 192.168.12.144/28 network.
Network id: 192.168.12.0
6. Add one to the network number, this is your first address.
First address: 192.168.12.1
7. To find the broadcast, take the next highest network number, and subtract 1.
The next network number is 192.168.12.16. If we subtract 1, we get:
Broadcast: 192.168.12.15
8. To find the last ip address, subtract 1 from the broadcast address.
192.168.12.15 - 1
Last address: 192.168.12.14
So for ip address 192.168.12.7/28,
Network: 192.168.12.0
First IP: 192.168.12.1
Last IP: 192.168.12.14
Broadcast: 192.168.12.15
So what if the hosts span more than a single octet? Same rules, but you have to understand how to subtract properly.
Let’s do 172.16.37.9/18
1. Convert from slash notation to decimal. The first two octects take up 16 (8+8) bits of the subnet mask. We know 8 bits is equal to 255, so we can write out the first half of the mask as:
255.255. ? . ?
This leaves 2 bits of subnet mask left. From our chart, we know that two bits is equal to 192.
255.255.192. ?
No more mask bits left- all zeros left. So we have the final octet, 0.
255.255.192.0
2. If the mask octet is 255, just copy the value down.
172.16 .37 .9
255.255.192.0
-————
172.16. ? . ?
3. If the mask octet is 0, then put a zero down.
172.16. ? . 0
4. If the mask is the interesting octet, subtract the interesting octet from 256.
256 - 192 = 64
So the networks would be:
172.16.0.0
172.16.64.0
172.16.128.0
172.16.192.0
5. Pick the multiple of the network range that your host value falls in. This is the network id.
172.16.0.0
6. Add one to the network id. This is the first host.
172.16.0.1
7. To find the broadcast, take the next highest network number, and subtract 1.
The next highest network id is:
172.16.64.0
Subtract 1. Be careful, we’re subtracting one from the HOST portion. The answer is NOT 63.0. When you subtract 1 from a zero octet, the answer is 255, and then you subtract 1 from the octet to the left.
172.16.63.255 is the next step down. As you do more problems, this will get easier and make sense.
8. To find the last ip address, subtract 1 from the broadcast address.
172.16.63.254
So the networks/hosts/broadcasts for 172.16.37.9/18 are
Network: 172.16.0.0
First IP: 172.16.0.1
Last IP: 172.16.63.254
Broadcast: 172.16.63.255
San Bernardino Valley College has a great online subnet practice page.
Spend some time practicing- you’ll be surprised how much easier it is once you get the hang of it.
Additional Reading:
CCIE Routing and Switching Certification Guide