Subnetting 101
From Internetworkpro
For some people, subnetting can be a difficult task but with this article I hope to make the process easy.
Basic Definitions
[edit] =========
Here are some basic definitions I think that one should know in order to understand this article:
IP Address - A unique number ID assigned to one host or an interface on a network.
Subnet - A portion of a network sharing a particular address.
Subnet Mask - A 32 bit combination used to describe which portion of an address refers to the subnet and which part refers to the host.
(a) 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.
To be very good at subnetting, I've discovered the more you practice, the better you become.
If you want to find out how many hosts you have in an IP range, first you need to determine how many host bits there are.
Let’s take our previous example of 192.168.4.6 and 255.255.255.0. We already established previously that the Network ID was 192.168.4 and the Host ID was 6. In other words, we have 3 octets for the Network ID and one octet – or 8 bits – for the Host ID. Now that you have determined the amount of host bits you had, apply that number to the following formula: (2^N)-2)=number of hosts, where N is your number of host bits That gives us: ((2^8)-2)=254 hosts. That means that in our example, we have the 192.168.4.x network, which contains 254 possible IP addresses, all local to each other.
Who in the world need that many ip's. If you work for an ISP then you need to range in to several other, more manageable ranges? Well, I need to subnet. Note: we have to subtract 2 because we lose the all ones and all zeroes values. If I only had 2 bits to play with, in binary, I would have 2^2=4 possibilities: 00 01 10 11 However, all zeros in IP means the whole network, and all ones is the broadcast ID, neither one being valid IP addresses that can be assigned to a host. That is why we always lose 2 and have to subtract two from (2^N)…
(b) The Table!
This is the only table you need to learn to understand IP subnetting and IP addressing.
| 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 |
Three little lines! Let’s look at it line by line. The first line you should already be acquainted with, so I will not spend more time on it. The second line tells you what your subnet mask will be. How do we get those results? If you look at the bit value line, and add up the bit values, 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? Ehh
Now to the third line. This one tells you how many subnets will get if you use the corresponding subnet mask. In other words: if you use the 192 in your subnet mask, you will get 2 subnets. If you use 224, you will get 6 subnets, etc… So how did I get those numbers? Well, let’s take 192 as an example. How many bits did I use to get 192? Well, I added 128 and 64, so that would be two bits, right? Let’s look at our well-known formula: ((2^2)-2)= 2 That is where the values in the third line come from. 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, or a total of 5 bits. ((2^5)-2)=30 So now, we know how to build that table, and we understand how it is built. We are almost done with subnetting!
(c) Calculating
Let’s say my Kewlb as my boss shows up one morning and says: “Dark3Lite, I have an IP range of 145.128.0.0 and a subnet mask of 255.255.0.0. I want 6 subnets out of this.” What do I do now? I look at my chart, and I see that to get 6 subnets, I need a subnet mask of 224. I already have an existing subnet of 255.255.0.0, which in binary looks like this: 11111111.11111111.00000000.00000000 I cannot “borrow” any more bits from the first 2 octets, as they are already network bits – represented by a binary value of 1. So the only I can add this “224” to my subnet mask is to borrow from the host ID. I take the next available octet – the third in our example – and end up with a subnet mask of 255.255.224.0, which looks like this in binary: 11111111.11111111.11100000.00000000 Note that we “borrowed” 3 host bits – binary value of 0 -- in the third octet and made them network bits – binary value of 1. Note as well that 3 bits is what I need to make 224: 128+64+32=224. Now that I have a subnet mask, I can tell that I have 13 host bits, 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, your new subnet mask for the 145.128.x.x network will be 255.255.224.0, and you will have 6 subnets with 8190 IP addresses in each range.” What’s Kelwb's next question? “Dark3Lite, what are those ranges?”
(d) Calculating the IP ranges in subnetted environments
Let's look at our subnetting chart again and see how we will derive the actual IP ranges from the network address and subnet mask.
| 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 |
In our example, we had: Original IP range: 145.128.x.x Original Subnet Mask: 255.255.0.0 Subnetted subnet mask: 255.255.224.0 Amount of subnets: 6 The first valid range will be 145.128.32.1 to 145.128.63.254. How did I get there? I used the above chart. Once I determined that 224 was my subnet bit, I asked myself: what is the lowest bit value needed to make 224?” The answer is: 32 (128+64+32=224, and 32 is the lowest of all 3 bit values.) If you look at the chart, you can see this: Bit value 32 Subnet Mask 224 Number of subnets 6 Visually, it is easy to see that to have 6 subnets, I will use 224 as a subnet bit and will start my first range at 32. I will then increment each range by that same value of 32. I love this chart! My 6 ranges will be:
| 145.128.32.1 to 145.128.63.254 |
| 145.128.64.1 to 145.128.95.254 |
| 145.128.96.1 to 145.128.127.254 |
| 145.128.128.1 to 145.128.159.254 |
| 145.128.160.1 to 145.128.191.254 |
| 145.128.192.1 to 145.128.223.254 |
As you can see, to get the next range, I simply incremented my original value by the same value (look at bold numbers) I started at 32, then incremented 5 times by that same value of 32. If you look at the values in bold numbers in the ending range you will see that they always are the next first bold value minus 1. For example, if I look at the first range x.x.32.1 to x.x.63.254, I looked at the next line’s bold value, here 64, and subtracted 1 to get to 63. That is all there is to it! By the way, note that my last octet on the start of range is always 1 – it cannot be 0, 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, or else it would be all 1s, which we know is the broadcast address, and is therefore not available for hosts to have.
(e) Complex Example
You've just been hired as a Network Administrator for a
large International firm. As the "new guy" to the team,
you've been assigned the CIO's latest task - IP address
allocation of the RFC 1918 192.168.0.0 private
addressing for the 5 subsidiaries. In addition to the
following requirements, the addresses must be summarizable:
| Company A has 150 people, 30 printers, and 50 servers in their corporate offices, plus 12 retail stores that require 10 IP addresses each. |
| Company B has 2 corporate offices with 300 people, 50 printers, and 150 servers in each building. |
| Company C has 24 small field offices with 3 PCs and a router, plus a corporate office with 100 people, 8 printers, and 20 servers (but plans to add up to 50 more devices in the next two years) |
| Company D has three mid-size offices and a data center. Each office has about 75 people, 10 printers, and 3 servers, and the Data Center has 20 people, and 300 servers. |
| Company E has a small corporate office of 35 people and 10 printers, but has a large sales staff of 450 across the country who VPN from their home offices (each user must have their own IP address assigned for access to network resources). |
Answer:
| Parent Company - 192.168.0.0 /23 - 510 hosts |
| Company A - corp - 192.168.2.0 /24 retail 192.168.3.0 /24 summary - 192.168.2.0 /23 |
| Company B - corp1 - 192.168.4.0 /24 corp2 - 192.168.5.0 /24 summary - 192.168.4.0 /23 |
| Company C - field - 192.168.6.0 /24 corp - 192.168.7.0 /24 summary - 192.168.6.0 /23 |
| Company D - office1 - 192.168.8.0 /25 office 2 - 192.168.8.128 /25 office3 - 192.168.9.0 /25
dist ctr - 192.168.10.0 /23 summary - 192.168.8.0 /22 |
| Company E - office & VPN - 192.168.12.0 /24 |
| Summary of all addressing - 192.168.0.0 /20 (192.168.0.0 thru 192.168.15.0) |
In Terse:
I hope that I made this tutorial simple and clear enough. Should you have any questions, comments, suggestions do not hesitate to contact me on IRC @ irc.freenode.net #cisco. This tutorial utilizes few articles of Cisco (R).

