The Basics of IP Subnetting

Ready for some counting fun? Here's a guide for figuring out how to subnet an IP range.

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.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

basics in subnetting

Timothy Virgin's picture

Real man, u helped millions of people out there with ur expalnation, actually i have earned alot in that topic. keep it up mr bright. hope to find more of subnetting and re-subnetting on the same website.
see u then.
God bless

Here is an automat for subnetting exercising :

Didier Vandenbroucke's picture

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

Hmmm...

Anonymous's picture

"You gave the address 210.127.109.217 while 210.127.109.410 was expected."

Not sure that I can trust either your or my answers :(

Oops ?? I would like to see

Anonymous's picture

Oops ?? I would like to see the whole question / answer thingy ... It is stated that there is a possibility on errors.. Should this happen, please provide as much info as possible including the text starting with Ver: up to the end of the line. It would help me find the problem, and supply you with the correct answer.
thx, brouckie ( Didier Vandenbroucke )

Re: The Basics of IP Subnetting

Anonymous's picture

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

Anonymous's picture

Are the instructors at systems plus good?

Re: The Basics of IP Subnetting

Anonymous's picture

Thanks, you kick ass!

Re: The Basics of IP Subnetting

Anonymous's picture

Great Job! Thanks. That had to be a lot of work. Disregard thost guys that criticized your math.

Re: The Basics of IP Subnetting

Anonymous's picture

Hey man! it's great getting this piece on the net. Go ahead

Re: The Basics of IP Subnetting

Anonymous's picture

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

Anonymous's picture

Thanks for the time you spent explaining this.
It was very well done.
Good on you!!

Re: The Basics of IP Subnetting

Anonymous's picture

Thanks for taking the time to explain this. Wish my instructor had explained it as well as you did.

Re: Help subnetting

phlat's picture

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

Anonymous's picture

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

Anonymous's picture

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

Anonymous's picture

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

Anonymous's picture

could i read this info you did on subnetting

Re: The Basics of IP Subnetting

Anonymous's picture

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

Anonymous's picture

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

Anonymous's picture

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

Anonymous's picture

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

Anonymous's picture

the article is right, clear and easy to understand, is IP Basic for Dummies... :p

Re: The Basics of IP Subnetting

Anonymous's picture

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

savvy's picture

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

dmarti's picture

All possible netmasks expanded. lists all the ways to subnet a class C.

Re: The Basics of IP Subnetting

Anonymous's picture

- 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

Anonymous's picture

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

Anonymous's picture

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

Anonymous's picture

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

Anonymous's picture

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

Anonymous's picture

Hmm isn't it 2^5 -2 =30

Re: The Basics of IP Subnetting

Anonymous's picture

5 ^ 2 - 2 = 30

Re: The Basics of IP Subnetting

Anonymous's picture

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!

Anonymous's picture

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!

Anonymous's picture

hey dip stick.

it's 254 because they use 0 as a number.

nice try Einstein!!!!!

Re: Guess again!

Anonymous's picture

Thats has already been made apparent. 8P 8). Thanks for reading it and making it better.

Re: The Basics of IP Subnetting

Anonymous's picture

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

Anonymous's picture

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

Anonymous's picture

could you please let me in on this simple process of subnetting

Re: The Basics of IP Subnetting

Anonymous's picture

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

Anonymous's picture

hey you, 0's and 1's do have special purposes in IP addressing.

Re: The Basics of IP Subnetting

Anonymous's picture

YES!!!!!

Re: The Basics of IP Subnetting

Anonymous's picture

lol stupid computers start at zero...WAKE UP

Re: The Basics of IP Subnetting

Anonymous's picture

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

Anonymous's picture

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

Anonymous's picture

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.

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix