how to subnetting

1. What is an IP Address? An IP address is made of 4 Octets, or 32 bits. It is usually represented in dotted decimal format like this: 131.107.2.205. Each number represents an octet. An octet is a group of 8 bits. Since we have 4 octets in an IP Address, there are 8*4=32 bits in an IP Address. Computers do not understand dotted decimal notation, as they only function in binary. All computers understand is 1 and 0. Therefore, we must find a way to transfer an IP Address from dotted decimal format to binary. We do this octet by octet. Each bit in an octet has an associated decimal value: Bit 1 2 3 4 5 6 7 8 Bit value 128 64 32 16 8 4 2 1 So you can follow, here is a decimal to binary calculator. However, I advise you to do the math at first to better understand the concepts... Insert Number: Let’s take an example. I have an IP address of 131.107.2.4. What is that in Binary? Let’s do this octet by octet: 131: Bit Value 128 64 32 16 8 4 2 1 Binary 1 0 0 0 0 0 1 1 Column with a “1” in binary mean that we count the corresponding bit value. If you add up all the bit values marked with a one, you get 128+2+1=131. 107: Bit Value 128 64 32 16 8 4 2 1 Binary 0 1 1 0 1 0 1 1 Column with a “1” in binary mean that we count the corresponding bit value. If you add up all the bit values marked with a one, you get 64+32+8+2+1=107 2: Bit Value 128 64 32 16 8 4 2 1 Binary 0 0 0 0 0 0 1 0 Column with a “1” in binary mean that we count the corresponding bit value. If you add up all the bit values marked with a one, you get 2 4: Bit Value 128 64 32 16 8 4 2 1 Binary 0 0 0 0 0 1 0 0 Column with a “1” in binary mean that we count the corresponding bit value. If you add up all the bit values marked with a one, you get 4 Now we know that another way of writing our example IP address of 131.107.2.4 is: 10000011.01101011.00000010.00000100 IP Addresses are made of two distinct parts: the Network ID and the Host ID. When you try to ping an IP address, IP at Layer 3 needs to determine whether the target IP address is local or remote to your subnet. To explain this, I like to ask my students the following question: “Let’s say I live on Maple Tree Lane. You say that you also live on Maple Tree Lane. Are we neighbors? Well, we may be, or we may not be. We do not have enough information to answer that question. Specifically, we do not know if we live in the same town. If we do live in the same town, and our street addresses are similar, then we are neighbors. If we do not live in the same town, it does not matter whether our street addresses are similar or not: we are not neighbors.” The same applies to IP addressing. Before I can find out what your Host ID is – i.e. your street address – I have to worry about what your Network ID is – i.e. your town. So how does IP know what the Host ID and Network IDs are? That is the role of the Subnet Mask. Please note that neither the network ID, the host ID nor the subnet bit can be all 0s or all ones. More to come about this later…

255.0.255. What is a Subnet Mask? A Subnet Mask is used to enable IP at Layer 3 to find out whether the target IP address you are trying to contact is local or remote to your network.0 11111111. let’s apply the same logic: 131. and the host ID is 4. So. If you add up all the bit values marked with a one. and which is the Host ID. what happens? Well.2. 01101011.2. 00000010 00000100 255. 01101011. 00000000 Do the Network IDs match? No! Look at the third octect: 00000010 00000101 If the network IDs do not match. 11111111. 00000000 00000000 What happens now? My network ID is now 131. That is all it does. 00000000 I highlighted the Network bits in Red.0: 131.00000000 Note that a subnet mask is also a 32 bit. or remote? You cannot answer that question.4 10000011. It helps you determine which part of an IP Address is the Network ID.255.0 11111111.107.107. Notice anything? All the network bits are the bits that had a value of “1” in the subnet mask. isn’t it? In our example. the Network ID is 131. 00000100 .0 11111111. 00000010.6 10000011. So how does it do that? We have all seen a Subnet Mask before.2.107. They only understand binary. 11111111. 00000010.4 10000011. as you may have heard before. 11111111. our 255.107.0.255.4 10000011. 01101011.255.5.255. I would get this: 131.5. 01101011.4 10000011.0 subnet masks in binary looks like this: 11111111.6 Are they local to each other. In other words.2.255.255. They are on different subnets. 255 is “all ones”. you get 0. and the Host bits in Blue.0. If I change the subnet mask to 255.2.255. 11111111.255. As we already know. then the two IP addresses are remote from each other.2.107 and my host ID is 2. and you will need a router to go from one to the other.0. 01101011. you get 128+64+32+16+8+4+2+1=255 So. 00000010.107.107. 0 is “all zeros”. If you add up all the bit values marked with a one. 0: Bit Value 128 64 32 16 8 4 2 1 Binary 0 0 0 0 0 0 0 0 Column with a “1” in binary mean that we count the corresponding bit value. 00000100 255. Easy.4 and 131. So let’s apply what we know about binary to our subnet mask: 255 Bit Value 128 64 32 16 8 4 2 1 Binary 1 1 1 1 1 1 1 1 Column with a “1” in binary mean that we count the corresponding bit value. 00000110 255.11111111.2. 11111111. and all the host bits are the bits that had a value of “0” in the subnet mask. Let’s take the same example with a different subnet mask of 255. It usually looks something like this: 255. computers do not understand this format.4! That is why an IP address on its own cannot exist! That is why a host on a network needs at least an IP address AND a subnet mask! Let’s say that I tell you that I have 2 IP addresses: 131. however.107.0 This subnet mask is obviously displayed in dotted decimal format. because it is incomplete! I need to give you the subnet mask as well! Let’s see why… Let’s say that the subnet mask is 255. 4 octet entity that matches the structure of our IP addresses… If I were to superimpose the IP address and subnet mask we have translated so far.255.11111111.255. 00000101. 00000100 131.0.107. Then we have: 131.255. as you may have heard before.

0 Class B 255. Class C 192-223 110xxxxx. What are IP classes? You may have heard of the different classes for IP addresses. We already established previously that the Network ID was 131. Let’s sum this up: we have seen how only having an IP address is not sufficient. class A. Therefore. 00000000.107. What is subnetting? Subnetting is the action of taking an IP range where all IP addresses are local to each other and dividing it into different ranges – or subnets – where IP addresses from one range will be remote from any other IP addresses from any other range. Class B 128-191 10xxxxxx.255. but they are not used right now and are illegal on the Internet. and how the same two IP addresses can be either remote or local to each other depending on which subnet mask you are using. InterNIC decided that the 1st octet would start with a bit value of 0. 01101011.255. In other words. Let’s take our previous example of 131.5.0.0. That means that in our example. all local to each other. InterNIC decided that the 1st octet would start with a bit value of 10.0. B and C.214 valid IP addresses in that range! What if I do not need that many – heck. D and E. and the highest is 11011111 (in decimal. then the two IP addresses will be on the same network. note that you can use any subnet mask classes with any IP address classes. .0 Class C 255. Also. we have 3 octets for the Network ID and one octet – or 8 bits – for the Host ID. You do not need a router to go from one to the other in this scenario. and the highest is 01111111 (in decimal. and the highest is 10111111 (in decimal.x. namely. first you need to determine how many host bits there are. 11111111.2. Now that you have determined the amount of host bits you had.0. apply that number to the following formula: (2^N)-2)=number of hosts. that would be from 192 to 223) There are other classes. I need to subnet. where N is your number of host bits That gives us: ((2^8)-2)=254 hosts. the lowest binary of the 1st octet is 0000001.4 and 255.107. InterNIC decided that the 1st octet would start with a bit value of 110. How does that work? Let’s look at the following table: Class A 1-127* 0xxxxxxx.107. it is totally possible to have a Class B IP address and a class C subnet mask… hang on… isn’t that what we have been taking as an example all along? Remember our 131.107.x. the lowest binary of the 1st octet is 1000000.0 In other words.107. but you cannot assign any 127.x network.2 and the Host ID was 4.x IP addresses to hosts as the entire range is reserved by InterNIC for the loop back address… What does this mean? When talking about a Class of IP addresses. *127 is part of the class A range.255. 3. we have the 131. If you want to find out how many hosts you have in an IP range.255. 00000101. that would be from 1 to 127) For class B.255.0 11111111.131.2. This is at the basis of IP troubleshooting. Therefore.255.255.0. who does J -. you only look at the first octet to determine what class this IP address belongs to. Therefore. which contains 254 possible IP addresses. 00000000 Do the Network IDs match now? Yes! If the network IDs match. the lowest binary of the 1st octet is 1100000.255. 00000110 255.6 10000011. more manageable ranges? Well. Subnet mask classes are as follows: Class A 255. that would be from 128 to 191) For class C.and decided to divide that range in to several other.777.4 w/ a subnet mask of 255.0? 4. For class A.2. What if I chose a class A subnet mask? I would then have: (2^24)-2)=16.

or a total of 5 bits. and I see that to get 6 subnets. I would have 2^2=4 possibilities: 00 01 10 11 However.00000000 Note that we “borrowed” 3 host bits – binary value of 0 -. meaning that I will have ((2^13)-2)=8190 valid IP addresses per range J So I can go back to my boss and say “Boss. How many bits did I use to get 192? Well.255.255. which looks like this in binary: 11111111. your new subnet mask for the 131. etc… So how did I get those numbers? Well.107.255.0 and a subnet mask of 255. and all ones is the broadcast ID.0. This one tells you how many subnets will get if you use the corresponding subnet mask.11111111.224.11111111. The first line we are already acquainted with. I already have an existing subnet of 255. If you use 224. you will get 2 subnets. in binary.x network . How do we get those results? If you look at the bit value line. and we understand how it is built.Note: we have to subtract 2 because we lose the all ones and all zeroes values.0. so that would be two bits. The second line tells you what your subnet mask will be. I can tell that I have 13 host bits. as they are already network bits – represented by a binary value of 1. all zeros in IP means the whole network. Want to check another one? Let’s look at 248. How many bits did I use to get to 248? 128+64+32+16+8=248. we know how to build that table.00000000 I cannot “borrow” any more bits from the first 2 octets.” What do I do now? I look at my chart.0.107. ((2^5)2)=30 So now. If I only had 2 bits to play with. I want 6 subnets out of this.00000000. right? Let’s look at our well-known formula: ((2^2)-2)= 2 That is where the values in the third line come from.0. I need a subnet mask of 224. and add up the bit values. So the only I can add this “224” to my subnet mask is to borrow from the host ID.in the third octet and made them network bits – binary value of 1. I have an IP range of 131. I added 128 and 64. which in binary looks like this: 11111111. you will see that: 128+64=192 192+32=224 224+16=240 240+8=248 248+4=252 252+2=254 254+1=255 Easy? J Now to the third line. In other words: if you use the 192 in your subnet mask. That is why we always lose 2 and have to subtract two from (2^N)… Let’s look at the following table: Bit Value 128 64 32 16 8 4 2 1 Subnet Mask 192 224 240 248 252 254 255 Number of Subnets 2 6 14 30 62 126 254 This table is the only table you need to learn to understand IP subnetting and IP addressing! Three little lines! Let’s look at it line by line. let’s take 192 as an example. We are almost done with subnetting! Let’s say my boss shows up one morning and says: “Dave. so I will not spend more time on it. neither one being valid IP addresses that can be assigned to a host.11100000.0.0. Now that I have a subnet mask. you will get 6 subnets.x. Note as well that 3 bits is what I need to make 224: 128+64+32=224. I take the next available octec – the third in our example – and end up with a subnet mask of 255.

Therefore I will start my ranges at 16 and will increment by that same value of 16.1 to 131.32.127.192.0. note that my last octet on the start of range is always 1 – it cannot be 0.107.x.0. For example. it is easy to see that to have 6 subnets. Note that it is somewhat different if you subnet a Class A and a Class C.0.254 .107.1 to 10.47. How did I get there? I used the above chart.159.254 10.96.107.1 to 10.x.63.223.1 to x. we will learn how to derive the actual IP ranges from the network address and subnet mask. I love this chart! My 6 ranges will be: 131. then incremented 5 times by that same value of 32.255.x Original Subnet mask: 255.128.107.255.255. Original IP range: 10. or else my host ID would be all 0s – and that the last octet is always 254 in the last IP of each range – it cannot be 255.128. which we know is the broadcast address.1 to 131.254 10.0.254 10. I looked at the next line’s red value. Note that my subnet bit is now the second octet.0.1 to 10. I will then increment each range by that same value of 32.107.107.254 131.0.255.255.) If you look at the chart. Let’s do a Class A example. therefore my new subnet mask becomes 255.175.” What’s my boss’ next question? “Dave. I simply incremented my original value by the same value (look at the numbers in RED) I started at 32. I asked myself: what is the lowest bit value needed to make 224?” The answer is: 32 (128+64+32=224.254 131. That is all there is to it! By the way.1 to 131. and you will have 6 subnets with 8190 IP addresses in each range.32.0 Subnetted subnet mask: 255.0 Amount of subnets: 6 The first valid range will be 131.160. we subnetted a Class B network into 6 subnets. and is therefore not available for hosts to have.48. In our example.1 to 131.191.254 As you can see.224.254 10.254 131.x Original Subnet Mask: 255. what are those ranges?” Oh yeah… maybe I forgot that part J 5. This will have its importance when we create our ranges. and subtracted 1 to get to 63.x. My ranges are: 10.0.will be 255.254 131.64.1 to 10.254.107. not the third as in the previous example.107. Calculating IP ranges in subnetted environments Bit Value 128 64 32 16 8 4 2 1 Subnet Mask 192 224 240 248 252 254 255 Number of Subnets 2 6 14 30 62 126 254 Here is our little subnetting chart again.255.107.107.224.63. What is the smallest bit value needed to make 240? 16.x.1 to 10.107. or else it would be all 1s.107.32.159.1 to 131.254 10.32. I will use 224 as a subnet bit and will start my first range at 32. we had: Original IP range: 131.63.1 to 131.107.107.0 Amount of subnets needed: 14 To get 14 subnets I need a subnet bit of 240. if I look at the first range x.255.255. and 32 is the lowest of all 3 bit values. here 64.254.144.143. In this example. In this section.0.160.1 to 10.240.1 to 131.95.255.63. If you look at the values in BLUE you will see that they always are the next red value minus 1. to get the next range.16.0.31.0. you can see this: Bit value 32 Subnet Mask 224 Number of subnets 6 Visually.107.254 131.0. Once I determined that 224 was my subnet bit.x.0.

127..32 w/ a subnet mask of 255. Therefore I will start my ranges at 32 and will increment by that same value of 32.2.255.1 to 10.2.1 to 10.254 Now let's do this with a class C. we don't have room for a fifth to add the .168. Remember.255.112.158 192.2. it is obvious that the Host ID is all zeroes. (Are you getting the hang of it by now?) My ranges are: 192.254 10.1.224 11111111.208.2.254 10. so follow this carefully! Original IP range: 192.190 192.224? Let's see why: 192.222 But.255.223.2.255.2.33 to 192..168.1 to 10.2.224.62 192.255.1 to 10.254 10.129 to 192.0.239.191.168.255.0. you say.10. class C is the hardest. remember the other examples? We always started at .0. because we are already subnetting at the fourth octet. 11111111. which we know is not possible.168.0 Amount of subnets needed: 6 To get 6 subnets I need a subnet bit of 224.255. I thought I was starting at 32?!? My first range is starting at 33! Well. That is it.2.64.255.80. Note that my subnet bit is now the 4th octet.1 to 10.2.2. 00100000 255.x Original Subnet mask: 255.168. If you know and understand this.207. not the third or second as in the previous examples.2.32 11000000. therefore my new subnet mask becomes 255..1 to 10..168. you can subnet! Enjoy practicing. 00000010.0.0.255.0.94 192.168.254 10. So why can we not use 192.2. 11100000 Looking at it in binary. This will have its importance when we create our ranges.192.193 to 192.126 192.168.168.224.254 10. 10101000.255.65 to 192.176.95. .168.255.79. so we have to incorporate it in the last octet.168.168. didn't we? Except that here.111.168.1 to 10.0.2. 11111111.0. What is the smallest bit value needed to make 224? 32.255.168.254 10.254 10.96.168.97 to 192.2.161 to 192.255.2.255.1.255.255.1 to 10.