Subnetting

You are currently browsing articles tagged Subnetting.

One of the concepts that I initially struggled with was wild card masks.  They just didn’t make any sense to me.  I couldn’t understand them and the examples in the Cisco press book just pushed that frustration further.  And then one day, while studying for the CCNA, it just clicked.  I thought I’d try to explain them in my own words so that other people might be able to benefit from, what I think is, a simpler way to look at them.

What is a wild card mask?
Wild card masks are used for a variety of different tasks.  OSPF area definitions and some access lists use them to define a certain part of the network.  They work much like subnet masks but in reverse.  For instance, take this Class C subnet.

192.168.127.1 /24
Network – 192.168.127.1
Subnet mask – 255.255.255.0
Wild Card Mask – 0.0.0.255

Pretty straightforward right?  The wild card mask is essentially the reverse of the subnet mask.  So if the binary subnet mask looked like……

11111111.11111111.11111111.00000000

The wild card mask would look like this…..

00000000.00000000.00000000.11111111

That’s all fairly easy to understand, however when you start using VLSM it can get a little trickier.  For instance, take this class C subnet.

192.168.127.1 /27
Network – 192.168.127.1
Subnet mask – 255.255.255.224
Wild Card Mask – 0.0.0.31

The binary would look like this…..

11111111.11111111.11111111.11100000

The wild card mask would look like this…..

00000000.00000000.00000000.00011111

Now that’s a little more confusing isn’t it?  What might even be harder to understand is if you were simply given this…

access-list 1 permit 192.168.127.1 0.0.0.31

The Cisco book I read suggested that you do the binary conversion to figure out what exact network that ACL represented.  That seems like a waste of time to me.  Why not just subtract the wild card octets from 255.255.255.255.  In other words….

     255.255.255.255
   –     0.     0.     0.  31
—————————
     255.255.255.224

Then to convert a mask from standard notation to wild card you simply subtract the subnet mask from 255.255.255.255. 

    255.255.255.255 
255.255.255.224
————————— 
          0.     0.     0.  31

Wasn’t that easy?  Now I know some of you sitting out there reading this are thinking to yourself “Wow, we all knew that already”.  But for someone who has just be introduced to wild card masks this could be a huge help.  If someone would have just told me that I could just subtract as shown above it would have saved me one or two nights of frustration.  I think the Cisco press books meant well by trying to show you the full binary math behind wild card masks – and I’m not saying you should learn the binary way of doing this as well – but knowing the quickest way to do something is often far more helpful (especially on exams!).

Tags:

I can’t make this point any more definite.  You NEED to know how subnetting works if you are going to work on networks.  It’s just that simple.  Sure, you can get by using /24 networks everywhere for awhile.  But once you get your XBOX online and you actually want to work on big networks you’ll be sunk.  I’m glad that Cisco realized this and made it such a large part of their certifications.  So be warned, you don’t have a prayer at passing their entry level cert (CCNA) if you can’t subnet. 

So, since I already talked about subnetting in an earlier post let’s talk about VLSM (Variable Length Subnet Masks), or as I like to call it, ‘subnetting a subnet’.  VLSM , in my opinion, really boils down to knowing block sizes.  Block sizes are the entire IP space that a network takes up.   For instance, a /30 (255.255.255.252) network has a block size of 4.  How do I know that?  I subtract the last octet from 256.  In the case of /30 you have a network number, a broadcast number, and two usable IP’s.  So in total, there are 4 IP’s making the block size 4  I’ll list some of the more typical block sizes below.

Block Size Usable IP’s Last Octet
/30 4 2 252
/29 8 6 248
/28 16 14 240
/27 32 30 224
/26 64 62 192
/25 128 126 128
/24 256 254 0

Now, let’s talk about the actual problem again.  You should know by this point how to do basic subnetting.  What I mean by that is if someone gives you a subnet and asks you to subnet it, you should know how.  Most of the time it means doing what I call ‘equal subnetting’.  That is you take a subnet and divide it into equal parts using one part for each network.  This often leads to waste.  Take this subnetting question into consideration. 

You have the network 192.168.50.0 /24 and you need 6 networks with the maximum available hosts in each network.  Define each network.

At this point our best friend is the old 2n-2 equation.  Technically you could set the equation equal to 6 (AKA 6=2n-2) and solve using natural log functions, but I think it’s easier to just guess until you get it right.  So plug in some numbers and see what works.  As it turns out, when we plug in 3 we get 6.  Really the equation should read 6≤2n-2 since we can’t talk about decimals here.  If you actually solved the equation and received a decimal you would need to round up to the next whole number.  At any rate, we solved the equation and got 3 as our answer.  That means we need to borrow 3 network bits in order to get 6 subnets.  When we do that we end up with a subnet mask of /27 and our subnets are as follows.

Subnet Network Broadcast Usable Block Size Subnet Mask
1 192.168.50.0 192.168.50.31 .1-.30 32 /27
2 192.168.50.32 192.168.50.63 .33-.62 32 /27
3 192.168.50.64 192.168.50.95 .65-.94 32 /27
4 192.168.50.96 192.168.50.127 .97-.126 32 /27
5 192.168.50.128 192.168.50.159 .129-.158 32 /27
6 192.168.50.160 192.168.50.191 .161-.190 32 /27

Pretty easy right?  Now what happens if three of these networks are point to point WAN links?  WAN links that are point to point only require 2 usable IPs and are typically given /30 subnet masks because of this.  So in the above example we have literally wasted over 80 IP addresses!  So what’s the solution to this problem?  VLSM.  Basically we just add the block sizes we need onto each other starting from the beginning.  So let’s start with a more defined question.

You have the network 192.168.50.0 /24 and require the following subnets. 
-3 subnets for WAN links
-2 subnets with at least 60 usable host IP’s
-1 subnet with at least 20 usable host IP’s

The first thing you should think about is block sizes.  If we look at the question again we can determine what block sizes we need just by analyzing the host IP count requirement.

You have the network 192.168.50.0 /24 and require the following subnets. 
-3 subnets for WAN links (Block size of 4)
-2 subnets with at least 60 usable host IP’s (Block size of 64)
-1 subnet with at least 20 usable host IP’s (Block size of 32)

I’m hoping at this point what needs to be done might be obvious.  We simply start from the first available network number and add up the block sizes.  Let me lay it out below and see if it helps.

Subnet Network Broadcast Usable Block Size Subnet Mask
1 192.168.50.0 192.168.50.3 .1-.2 4 /30
2 192.168.50.4 192.168.50.7 .5-.6 4 /30
3 192.168.50.8 192.168.50.11 .9-.10 4 /30
4 192.168.50.12 192.168.50.75 .13-.74 64 /26
5 192.168.50.76 192.168.50.107 .77-.106 32 /27
6 192.168.50.108 192.168.50.139 .109-.138 32 /27

Really what I do is add up the required block sizes and then fill in info like the usable IP range and broadcast.  Just make sure that you get your network numbers right.  If you are off by even one number everything after that will be wrong.  So, as you can see when we use VLSM we saved a lot of IP space by only allocating networks that met the host size requirement that we needed for that network.  The most dramatic savings often come from WAN links that only require 2 usable IPs and use the /30 subnet masks.

Tags:

Hands down one of the most important things to know in the networking world is how to subnet.  If you are going to work on anything past your basic Linksys home router than you better have a good understanding of how it works.  If you are considering taking any Cisco certifications than it’s a MUST.  There is absolutely no way to even finish all of the questions on the CCNA if you can’t do subnet calculations in well under a minute.  While studying for my CCNA I became especially frustrated with subnetting.  The way the Cisco Press books taught you to do it took far too long and required writing a lot of stuff down.  A colleague of mine showed me a different way to do it and with enough practice you can do all the calculations in your head.  I’ll outline the method below since I haven’t found another online resource that does so.

Step 1 – Memorize the subnet mask values
Subnets are 8 bits long and are inverse.  That is they start “filling” from left to right rather than right to left. 
1 – 128
2 – 192
3 – 224
4 – 240
5 – 248
6 – 252
7 – 254
9 – 255
As a side note subnet masks can be represented in a few different ways…
Dotted Decimal Notation – 255.255.192
Prefix Notation – /18
Binary – 11111111.11111111.11000000.00000000

Step 2 – Find and locate the Interesting Octets
The interesting octet is found by locating the “weird” subnet mask octet.  If the octet isn’t composed completely of 1’s or 0’s its weird.  And weird is interesting : )  For instance in the subnet mask 11111111.11111111.11000000.00000000 octet 3 is interesting since its not totally 1’s or 0’s.  The IP address’s interesting octet is the same as the subnet masks. 

Step 3 – Find the special number
The “special” number is found by subtracting the value of the subnet masks interesting octet from 256.  For instance with a subnet mask of /18 the interesting octet’s value would be 192 since the octet has 2 bits that are 1.  You then subtract 192 from 256 leaving you with 64.  So the special number is 64.

Step 4 – Find the network number
To find the network number you keep adding the special number to itself getting as close to the IP Addresses interesting octet number without exceeding it.  So if you had the IP address and subnet of 216.21.245.17 /29 our special number would be 8.  So we add 8 to itself until we get close but don’t exceed 17.  17 is the IP addresses interesting octet.  We know this because the subnet mask’s interesting octet is the 4th octet since it isn’t all 1’s of 0’s. 
0 + 8 = 8
8 + 8 = 16
16 + 8 = 24
The closest we can get to 17 without going over is 16.  Now all we do is put that in the place of the IP addresses interesting octet.  Our Network number is 216.21.245.16. We copy any octets prior to the interesting octet so we brought over 216.21.245 and then added our 16 in the interesting octet.  If the interesting octet would have been the third or second octet we would have just put 0’s in any octets to the right of the interesting one.  We’ll see that in the examples.

Step 5 – Find the rest of the subnet information
The rest is pretty easy.  We add another iteration of the “special” number to our network number’s interesting octet.  This calculates the next possible network number using that mask.  So in our case the next network number is 216.21.245.24 since 16 (our calculated network number) plus 8 (our special number) gives us 24.  If we subtract 1 from the 24, we get our networks broadcast address.  The number proceeding the broadcast address is the last usable IP in the subnet.  The first usable IP in the subnet is the network number plus 1.  So here it all is…
Given IP address – 216.21.245.17 /29
Network number – 216.21.245.16 /29
First Usable IP – 216.21.245.17 /29
Last Usable IP – 216.21.245.22 /29
Broadcast IP – 216.21.245.23 /29

Now let’s walk through a few examples.

Example 1
Find the subnet info for the given IP address
IP address – 34.233.159.241 /12
Step 1 – Our subnet uses the first two octets.  The first uses all 8 bits (255) and the second uses 4 bits (240)
Step 2 – The interesting octet is the second since its not all 1’s and 0’s
Step 3 – 256 – 240(the interesting octets dotted decimal value) = 16
Step 4 – Add up increments of 16 until we get close to 233 but don’t exceed it
0 + 16 = 16
16 + 16 = 32
32 + 16 = 48
……..
192 + 16 = 208
208 + 16 = 224
224 + 16 = 240
The winner is 224 since 240 exceeds the 233 value.  Copy the first octet from the IP, insert our 224, and put 0’s for the remaining octets.  So our Network number is 34.224.0.0
Step 5 – Our next subnet with this mask would be 34.240.0.0  So our broadcast would be the closest IP to the next subnet.  I like to think of it as literally 34.240.0.0 minus 1.  That gives us a broadcast of 34.239.255.255.  And 1 less the broadcast is the last usable IP which is 34.239.255.254. The first usable IP would be the network number plus 1 which gives us 34.224.0.1.

Example 2
Find the subnet info for the given IP address
IP address – 187.11.111.138 /27
Step 1 – Our subnet uses all four octets.  The first three use all 8 bits (255) and the fourth uses 3 bits (224)
Step 2 – The interesting octet is the fourth since its not all 1’s and 0’s
Step 3 – 256 – 224(the interesting octets dotted decimal value) = 32
Step 4 – Add up increments of 32 until we get close to 138 but don’t exceed it
0 + 32 = 32
32+ 32 = 64
64+ 32 = 96
96+ 32 = 128
128+ 32= 160
The winner is 128 since 160 exceeds the 138 value.  Copy the first three octets from the IP and insert our 128 in the last octet.  So our Network number is 187.11.111.128.
Step 5 – Our next subnet with this mask would be 187.11.111.160.  So our broadcast would be the closest IP to the next subnet.  That gives us a broadcast of 187.11.111.159.  And 1 less the broadcast is the last usable IP which is 187.11.111.158. The first usable IP would be the network number plus 1 which gives us 187.11.111.129.

If you are looking for more practice I found this website which creates subnet problems for you.
http://faculty.valleycollege.net/rpowell/jscript/subnet2.htm

Tags: