The Basics of IP Subnetting
August 24th, 2002 by Mark Birchfield in
To understand how subnetting works, you first must have a good basic understanding of IP addresses. An IP address is set of binary octets broken into quads. That definition may not have made any sense to you, so we will try it another way. An IP address follows what is called dotted octet notation. There are four sets of numbers in an IP address, and dots are used to separate them, for example, 192.168.0.1.
Let's go a bit further into the binary octet discussion. Binary numbers are broken down by what is known as positional notation, which works from right to left in increasing place values. Here is an example:
192.168.0.1 in binary octet form would be 11000000.10101000.00000000.00000001 Binary form of 192: 1 1 0 0 0 0 0 0 = 192 128 64 32 16 8 4 2 1 (Hint: Add up the ones with the numbers below them. First one equals 128, plus the second, which is 64. Added together this equals 192.) 1 0 1 0 1 0 0 0 = 168 128 64 32 16 8 4 2 1 Binary form of 168 (Again, each 1 holds the value of the number below it.) 0 0 0 0 0 0 0 0. = 0 128 64 32 16 8 4 2 1 0 0 0 0 0 0 0 1 = 1 128 64 32 16 8 4 2 1
So, 11000000.10101000.00000000.00000001 is the binary octet breakdown of 192.168.0.1. Believe it or not, this information actually is important.
Now, let's delve into the realm of subnet masks. The subnet mask is what actually will do all of the work of subnetting (read again, subnet mask). The subnet mask of an IP address is what tells the computer or router or whatever which part of your IP address belongs to your network and which part belongs to the hosts. Thus, a subnet mask of 255.255.255.0 tells your computer that the first three quads of your IP address belong to the network, and all of your hosts will be referenced with the last quad. This gives us a standard subnet mask of 255.255.255.0, with a possibility of 254 hosts in our network.
What? Even though I failed Algebra II, my math here does make sense. You are required to have a base network address and a broadcast address for every subnet. With the standard subnet mask and the default IP address in our example, the network address is 192.168.0.0 and the broadcast address is 192.168.0.255, which leaves us 192.168.0.1-254 for our hosts.
The basics are out of the way, so let's move on to the important stuff. How we subnet an IP range depends first on how large your assigned IP range is. If you are running a private network going through one static IP address, then your range is 192.168.xxx.xxx. In this case, there really is no reason to subnet unless you want to cut down on traffic and segment your LAN for whatever reason you feel is worth undertaking this task.
To begin, assume an IP address of 128.16.8.0 as a base. This is obviously a simplified example, but it's enough to convey the point of the exercise. Broken down into dotted octet notation, 128.16.8.0 is
10000000.00010000.00001000.00000000
The first step in subnetting is planning. How many hosts do you want per mask? Is there a chance that you may be expanding any or all of these subnets in the future? These are all things that have to be taken into consideration before you get set up everything, because the number of hosts you decide upon directly effects all the following steps. Say you want to have 20 hosts available per subnet. This means that you will need a minimum of 22 hosts, (remember, network address and broadcast have to be taken into account also). Let's zoom in on the last octet of our IP address.
0 0 0 0 0 0 0 0 (Remember this from above?) 128 64 32 16 8 4 2 1
So, if we want at least 22 hosts on each of our subnets, we are going to need the last five bits in our octet quad. This will give us a total available of 16+8+4+2+1 or 31 possible hosts, 29 if you don't count the network address and broadcast address. This leaves the first three bits of the octet for network addressing. This makes our subnet mask for the entire network 255.255.255.224. How did I come up with this? The positional notation values for the first three bits of our final octet, when added together, equal 224.
Network bits Host bits
|
128 64 32 | 16 8 4 2 1
|
0 0 0 0 0 0 0 0 Network address for this subnet
0 0 0 0 1 IP Range of 128.16.8.0-31
0 0 0 1 0
0 0 0 1 1
....... and on till we get the numbers below
1 1 1 1 1 Broadcast address for this subnet
0 0 1 0 0 0 0 0 Network address for this subnet
0 0 0 0 1 IP Range of 128.16.8.32-63
0 0 0 1 0
0 0 0 1 1
.......
1 1 1 1 1 Broadcast address for this subnet
0 1 0 0 0 0 0 0 Network address for this subnet
0 0 0 0 1 IP Range of 128.16.8.64-95
0 0 0 1 0
0 0 0 1 1
.......
1 1 1 1 1 Broadcast address for this subnet
.............
.............
1 1 1 0 0 0 0 0 Network address for this subnet
0 0 0 0 1 IP Range of 128.16.8.224-255
0 0 0 1 0
0 0 0 1 1
.......
1 1 1 1 1 Broadcast address for this subnet
Do you get the picture so far? Let's review. We have an IP address of 128.16.8.0. For our first subnet, we use a subnet mask of 255.255.255.224. This gives us hosts from 128.16.8.1 to 30, with 128.16.8.0 as the network address and 128.16.8.31 as the broadcast address. Our next subnet would be 128.16.8.32 with the same 31 hosts, including broadcast and network. The subnet following that would have an IP range of 128.16.8.64-95. The next would be 128.16.8.96-127, then 128-159, then 160-191, 192-223 and, finally, 224-255.
These results are a simplified example that doesn't include a lot of reasons why things happen. The following is an attempt on my part to explain how all this works. Your IP address and your subnet mask are bitwise "and"ed together (read boolean algebra). 0s hide the number, while 1s let it show through. The resulting binary number is the network address that falls out of the addition. Here's an example:
11000000.10101000.00000000.00000001 Network address (192.168.0.1) 11111111.11111111.11111111.11100000 + Subnet Mask (255.255.255.224) 11000000.10101000.00000000.00000000 Network address (192.168.0.0 in this case)
This means anything to the right of the fourth bit in the final octet is a host address. This also means that the first three bits in the final octets are the network address. So, as outlined above, our first subnet would be 192.168.0.0-31. After that we would have to set the third bit from the left in the final octet, which changes the network address and results in our second subnet. :
11000000.10101000.00000000.00100000 Network address (192.168.0.32) 11111111.11111111.11111111.11100000 + Subnet Mask (255.255.255.224) 11000000.10101000.00000000.00100000 Network address (192.168.0.32 in this case)
This breaks us down into the subnet IP range of 192.168.0.32-63. Are you catching on yet? Here is another quick example. In it, our next subnet would be what?
11000000.10101000.00000000.01000000 Network address (192.168.0.64) 11111111.11111111.11111111.11100000 + Subnet Mask (255.255.255.224) 11000000.10101000.00000000.01000000 Network address (192.168.0.64 in this case)
which leaves 192.168.0.64-95 as our subnet IP ranges.
Hope I didn't confuse you terribly, but this is the main line of thinking for subnetting a network. Feel free to contact me with any questions. I might not be able to answer them off the top of my head, but I will do my best.
Special Magazine Offer -- 2 Free Trial Issues!
Receive 2 free trial issues of Linux Journal as well as instant online access to current and past issues. There's NO RISK and NO OBLIGATION to buy. CLICK HERE for offer
Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.
Sorry, offer available in the US only. International orders, click here.
Subscribe now!
The Latest
Featured Videos
Email is one of the least private and least secure forms of communication, although few people realize this. MixMaster is one way to allow secure, anonymous communication even over the very public medium of email. This tutorial will get you started with MixMaster quickly and easily.
In case you were wondering about the fun side of Linux World Expo, we thought we'd give you a peek at our shenanigans. We at Linux Journal love what we do so much, that we can't help but have a ball wherever we go.
Recently Popular
From the Magazine
September 2008, #173
Feeling a bit like a Thermian? Never give up, never surrender! Someday, you could go from underdog to top dog. Just take a look at a few of the underdogs we highlight in this issue: Mutt, djbdns, Nginix, Gentoo, Xara and the program voted mostly likely to fail just a few years back—Firefox. If Firefox is not radical enough for you, check out Chef Marcel's column for some more alternatives. Having trouble mapping your program data to your relational database? If so, Rueven Lerner shows you some tricks in his At The Forge column.
Need to run GUI applications on your server in the next state? In his Paranoid Penguin column, Mick Bauer shows you how to do it securely. Kyle Rankin keeps hacking and slashing and shows you a few split screen secrets you may not be familiar with. Finally, we all know what happens next February, but only Doc knows what happens afterward.
Delicious
Digg
Reddit
Newsvine
Technorati







Subnetting
On November 26th, 2007 Nance (not verified) says:
Thank you so much for that. I have sat here for days trying to understand this, going through tutorial upon tutorial. Yours was the very first I completely understood. What a relief. I was beginning to think I would never understand this. This is how it should be presented by Cisco. Thanks again.
This is a very good tutorial
On May 30th, 2007 Wilfried (not verified) says:
This is a very good tutorial for beginner .I am actually studying for a CCNA exam and I think the topic covered is really important .I have learned so much in a short time .Thank you Mark
The Basics of IP subnettimg
On November 10th, 2006 Derick (not verified) says:
This is a great piece
Here is an automat for subnetting exercising :
On August 3rd, 2006 Didier Vandenbroucke (not verified) says:
As read before there a lot of people who grasp the idea at first, think they have the know how, only to find out some later time that they dont know any more: the insite has gone, and suddenly its confusing again. To help here i have written a simple aid: an exersiser : http://www.brouckie.be/cgi-bin/IPsubnetting/index.pl
HTH
brouckie
Now I understand subnetting
On October 29th, 2005 AJ (not verified) says:
Mark,
Thank you for you detailed, but simple demonstration on how to subnet. I'm doing a paper for school and my next class is on "Building firewalls" and I'm looking forward to that. Anyway, I've read about 15 different articles and books and could not get it. I was starting to think that I was a dunce. But thanks to you, I got IT!
Re: The Basics of IP Subnetting
On May 7th, 2004 Anonymous says:
This really helped me study for my test in subnetting. Thanks for the article! Hopefully I'll pass my Advanced Networking class...
Re: The Basics of IP Subnetting
On February 18th, 2004 Anonymous says:
This subnetting is hard for those people who really don't know about networking... My instructor taught us how to subnet... Thanks for Mr. Erwin Benavides [CISCO Instructor]... Systems Plus Computer College. Philippines.
From Als Forto - CN108MA
Re: The Basics of IP Subnetting
On August 7th, 2004 Anonymous says:
Are the instructors at systems plus good?
Re: The Basics of IP Subnetting
On April 11th, 2004 Anonymous says:
Thanks, you kick ass!
Re: The Basics of IP Subnetting
On July 12th, 2003 Anonymous says:
Great Job! Thanks. That had to be a lot of work. Disregard thost guys that criticized your math.
Re: The Basics of IP Subnetting
On December 1st, 2003 Anonymous says:
Hey man! it's great getting this piece on the net. Go ahead
Re: The Basics of IP Subnetting
On December 1st, 2003 Anonymous says:
Hey man! it's great getting this piece on the net. Go ahead and make it more elementary for millions out there that value it. Never mind, critics 'll always come.
Odoeme Patrick
Re: The Basics of IP Subnetting
On May 20th, 2003 Anonymous says:
Thanks for the time you spent explaining this.
It was very well done.
Good on you!!
Re: The Basics of IP Subnetting
On March 30th, 2003 Anonymous says:
Thanks for taking the time to explain this. Wish my instructor had explained it as well as you did.
Re: Help subnetting
On February 8th, 2003 phlat (not verified) says:
I am new to subnetting and routing in general. I would really appreciate some feedback. Will this work?
Thanks in advance!
#!/bin/sh
HOSTNAME=`hostname`
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
# Setting up Loopback Device
echo "Network Setup..."
/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo
# Setting up Masquerading for 10.1.0.0/16
for modules in /lib/modules/2.2.16/ipv4/ip_masq*; do insmod $modules; done
# Masq 10.1.0.0/16
ipchains -A forward -s 10.1.0.0/16 -d 0/0 -j MASQ
echo "Setting up Internet connection"
ifconfig eth0 66.224.98.4 netmask 255.255.255.0 broadcast 66.224.98.255
route add default gw 66.224.98.3
ifconfig eth1 10.0.1.1 netmask 255.255.255.0 broadcast 10.0.1.255
ifconfig eth1:1 66.224.98.33 netmask 255.255.255.224 broadcast 66.224.98.63
ifconfig eth2 10.0.2.1 netmask 255.255.255.0 broadcast 10.0.2.255
ifconfig eth2:1 66.224.98.65 netmask 255.255.255.224 broadcast 66.224.98.95
ifconfig eth3 10.0.3.1 netmask 255.255.255.0 broadcast 10.0.3.255
ifconfig eth3:1 66.224.98.97 netmask 255.255.255.224 broadcast 66.224.98.127
ifconfig eth4 10.0.4.1 netmask 255.255.255.0 broadcast 10.0.4.255
ifconfig eth4:1 66.224.98.129 netmask 255.255.255.224 broadcast 66.224.98.159
ifconfig eth5 10.0.5.1 netmask 255.255.255.0 broadcast 10.0.5.255
ifconfig eth5:1 66.224.98.161 netmask 255.255.255.224 broadcast 66.224.98.191
Re: Help subnetting
On May 16th, 2004 Anonymous says:
I don't know, but I am willing to try it out if I get a few more NIC cards
Re: The Basics of IP Subnetting
On January 27th, 2003 Anonymous says:
Hey, good job on this. 'Ba-hooey' to those folks criticizing the math thing. I've read over this subnet bit thing in many other sources, I think I've finally got it now, thanks to your article. Thanks for taking the time to write it!
Re: The Basics of IP Subnetting
On January 22nd, 2003 Anonymous says:
I am in my 2nd term in cisco This site has been more helpfull to me, than my text books. I am having trouble taking in the full range of information on IP Subnetting. But this site is giving me an leg up on it.
Thank You
Kid Cisco
Re: The Basics of IP Subnetting
On October 15th, 2004 Anonymous says:
could i read this info you did on subnetting
Re: The Basics of IP Subnetting
On September 3rd, 2002 Anonymous says:
Its amazing !!!! People can find the time to criticize, but they can't find the time to help. Granted, so of the negative postings were correct. But, I don't think the author was trying to teach experienced experts about subnetting. He was trying to teach the everyday joe blow. Make suggestions to the article, but please try not to criticize.
Re: The Basics of IP Subnetting
On December 8th, 2002 Anonymous says:
I had to sit here and read it a few times because I'm doing a subnetting project for a nortel class but I got it more than my teacher could tell me.
Thank you
Re: The Basics of IP Subnetting - simple mistakes
On October 29th, 2002 Anonymous says:
i agree totally with the last comment!!!
This article, while having a few simple errors anyone could make, is good, and i thank the author for taking the time to put it up on this site!! After all... It's through people like Mark Birchfield, on the net, that many of us learn a good deal of our required knowledge. Without them, we'd have to resort to sorting through half adequate books, or delve into far-too-technical scientific papers.
Re: The Basics of IP Subnetting
On October 1st, 2002 Anonymous says:
As a beginner it's very important to have the confidence that what you're reading is correct. By definition of being a beginner, one does not have the knowledge to spot errors in other's work - even if they are startlingly apparent to the experienced reader.
This article was very well well put and pitched at the right level, but I have to say that when I see one mistake I find it difficult to trust the rest of what I'm reading.
Re: The Basics of IP Subnetting
On October 24th, 2002 Anonymous says:
the article is right, clear and easy to understand, is IP Basic for Dummies... :p
Re: The Basics of IP Subnetting
On August 27th, 2002 Anonymous says:
Thanks for a simple breakdown on how to subnet, thats how all things should be explained, we are not all gifted with more than one brain cell. I do find it quite amazing how you can read a few articles on the same subject and not really get a grasp on the subject and then one of them just happens to use the words that mke sense to you personally and make it fall into place.
Also thanks to the linuxmafia link from on of the earlier posters.
regards
Ian
Re: The Basics of IP Subnetting
On August 26th, 2002 savvy (not verified) says:
I've been setting up basement networks for a while, but I never really understood what the subnet mask was really for. I thought this was a pretty clear way of explaining it, and I'm fairly confident I actually get it! 8) Thanks for a good article.
Re: The Basics of IP Subnetting
On August 26th, 2002 dmarti (not verified) says:
All possible netmasks expanded. lists all the ways to subnet a class C.
Re: The Basics of IP Subnetting
On August 25th, 2002 Anonymous says:
- Another similar error. It's 32 (2^5) possible hosts, not 31.
- Before "subnet mask", the address is better called "IP address".
No offence. It's to help the new learners.
Re: The Basics of IP Subnetting
On January 5th, 2003 Anonymous says:
He is actually right. I think he is commenting regarding the "This will give us a total available of 16+8+4+2+1 or 31 possible hosts, 29 if you don't count the network address and broadcast address." statement in the original post.
Although usually we don't count in the network address and broadcast address into as the "possible hosts", that makes it 32-2=30 hosts. But the statement 32 possible hosts stand correct (judging from the original context), including the network address and broadcast address.
Re: The Basics of IP Subnetting
On September 1st, 2002 Anonymous says:
To work out possible hosts the correct formula is (2^n)-2. Is this case it is (2^5)-2=30.
Not 32 and not 31.
No offence to you, but check your FACTS before posting and confusing learners even more.
Re: The Basics of IP Subnetting
On March 17th, 2003 Anonymous says:
You know for some people any information helps, you take it at face value and use it as a guide and a tool, not a rule. I'm an IT trainer and have been for 17 years. To the critics of this gentleman's attempt at helping people....SHUT THE HELL UP. If you think you know something post it in a manner that accents what is there, save the crap, and be part of the solution not part of the moronic gesture trying to tell someone you are smarter, because impressed i'm not I think you are an anal retentive twit.
Re: The Basics of IP Subnetting
On August 30th, 2002 Anonymous says:
All these comments just sucks!! :)) I'm twisted now, I just wanted to understand this f*cking subnetting ;P
Are you sure ? :)) 32 ? Really? Set up 5 bits, and then (use bc if you want to add the values) 1+2+4+8+16=? :))
Greetz from Poland :)
Re: The Basics of IP Subnetting
On August 27th, 2002 Anonymous says:
Hmm isn't it 2^5 -2 =30
Re: The Basics of IP Subnetting
On February 7th, 2003 Anonymous says:
5 ^ 2 - 2 = 30
Re: The Basics of IP Subnetting
On August 26th, 2002 Anonymous says:
Not a problem. The off by one in subnetting seems to be a comman problem, (especially so with me it would seem 8) ). I will fix it in my copy and have them change it. Thanks for all the positive criticism so far.
Guess again!
On August 25th, 2002 Anonymous says:
ok, you suck on basic maths:P
"...with a possibility of 253 hosts in our network. ...which leaves us 192.168.0.1-254 for our hosts."
That's 254 hosts! Not 253!
Cheers mate:P
Re: Guess again!
On November 9th, 2002 Anonymous says:
hey dip stick.
it's 254 because they use 0 as a number.
nice try Einstein!!!!!
Re: Guess again!
On August 26th, 2002 Anonymous says:
Thats has already been made apparent. 8P 8). Thanks for reading it and making it better.
Re: The Basics of IP Subnetting
On August 24th, 2002 Anonymous says:
No offence, but you really did fail Algebra II, didn't you? 1-254 is 254 hosts, not 253. 0 - 255 is 256 addresses, where 0 and 255 are taken, leaving 1-254. How often are we off by one? I think the computer science is to blame with its idea of confusing 0 as a valid member.
Re: The Basics of IP Subnetting
On January 23rd, 2004 Anonymous says:
I'm a PG in CS, a Systems Analyst and a MCSE, who still hadn't grasped the concepts of subnetting which is why my NIS 70-216 was a bit weak. This article has not only simpliifed the concepts of subnetting but has stripped the complexities down to something so easy to comprehend as well as something that can be used as a basis to even deal with other Classes. The Algebra or the numerics isn't as important here as this article has intended to deal with giving the baseline of TCP/IP Subnetting and the not so algebraic but rather numeric part is something that should BE OBVIOUS TO USERS WHO ARE ON THIS PAGE AS I'M SURE THAT BIT IS WELL UNDERSTOOD and which is precisely what this article has done and achieved sucessfully... Kudos to Mark Birchfield. :D and I feel its a good thing that the Critics have pointed out certain shortcommings of the article, though not in the right manner and spirit I'd say.... which alltogether goes to make a Excelent learning base for any Beginner, Newbie or someone wanting to Refresh their concepts as REgards the same...
Re: The Basics of IP Subnetting
On October 15th, 2004 Anonymous says:
could you please let me in on this simple process of subnetting
Re: The Basics of IP Subnetting
On October 22nd, 2003 Anonymous says:
Thank you. This was the final piece needed. Your explaination of subnetting, particularly the how to figure number of nodes on net and thus the mask, was awesome.
Re: The Basics of IP Subnetting
On March 26th, 2003 Anonymous says:
hey you, 0's and 1's do have special purposes in IP addressing.
Re: The Basics of IP Subnetting
On November 3rd, 2003 Anonymous says:
YES!!!!!
Re: The Basics of IP Subnetting
On October 2nd, 2002 Anonymous says:
lol stupid computers start at zero...WAKE UP
Re: The Basics of IP Subnetting
On September 6th, 2002 Anonymous says:
Hi,
Please forgive me if I'm going about this the wrong way. I'm new to this arena and this article is as close as I've been able to come to finding some answers. The people writing and replying to this article seem very knowledgeable and I really need help.
Will you please recommend some direct links, sites or personal contacts that have VERY SPECIFIC, STEP-BY-STEP INSTRUCTIONS on how to set up FTP & WEB sites in LINUX. Man pages, Linux for dummies, The Linux Bible, bookstores and dozens of sites that I've visited have been of no help. 40 hours into this and I'm still at square-one.
I'm very new to LINUX and can't even figure how to find or open Executable files. Needless to say, it's been frustrating.
I have some details below if you're interested.
Thanks,
Scott Ferguson
capitalmanagers@comcast.net
Ph 866-366-2968
Details:
I've installed a free download of Red Hat LINUX 7.3 on a server that is exclusively for hosting 2 web & FTP sites. My PC is for daily operations and is running Windows ME (unfortunately). I have a copy of XP Pro and will install that in the near future for the PC (after the web site is operational).
They both go through a FVS 318 router to share internet cable access and share controls via a KVM switch.
I'm trying to figure out how to start an FTP site to store and access my files & forms which are mostly in .pdf format. These need to be freely available to the internet through the web site. The FTP site will also need upload access from a single remote location that has a static IP address.
My location is served by cable and has a dynamic IP, however, the IP seems to only change when I shut down the computer and cable modem simultaneously. I don't know how to check the IP, gateway or subnet mask since LINUX has been installed.
The web site is 80% complete in Front Page but would like to transfer it over to Apache. I know very little or nothing about either program and nothing on how to set it up on LINUX.
I already have a domain name but it is not
connected to the IP through DNS.
Samba has been recommended but I don't know what it is or does.
Please call me at the below number or reply by e-mail with ANY direct links or recomendations. I'll be glad to answer any questions. I'm at the computer all day every business day.
Scott
866-366-2968
Re: The Basics of IP Subnetting
On January 14th, 2004 Anonymous says:
to check the ip address,subnet mask, and gateway in Linux, the command is ifconfig instead of ipconfig on windows machines.
Ping command also works on Linux, except that you have to stop the command using ctrl-c or use the switch -c 4 .
The number 4 can be replaced by the number of ping responses you want. The four is used just because that is the default for Microsoft.
Hope that helps.
Re: The Basics of IP Subnetting
On August 24th, 2002 Anonymous says:
heh, Ive read and re-read this a thousand times, and never noticed it. Ill take the palm to the forehead now followed by a loud "DOH!". I will correct it and thanks for pointing it out.