Subnetting Made Simple

Updated 2009-04-05 for ipV4

Over the years, I have found many books on subnetting will bore the crap out of you with "The history of the Ethernet started in 1980 with the 802.1... zzzz..." and before you know it, you've fallen asleep and gotten drool on your nice new $75 Cisco CCNA Manual. I plan on making this page simple and to the point because too many subnetting FAQs out there went on and on before they taught you anything useful. There are four things I want you to remember first:

  1. Those decimal numbers are MEANINGLESS to the computer. 192.168.foo.blahblah... they are confusing because the computer has helpfully turned binary into decimal numbers because humans seem to remember decimals easier. Forget about them for now. Just think, "the computer doesn't know what 192 is... shouldn't I know how the computer thinks?" Yes. Yes you should. And it's not hard. Binary is easy; there's only 2 numbers to remember: 1 and 0, on and off. Like a light switch. In fact, that's how computers think: millions of on and off switches. Marvel in that thought. I'll wait.
  2. No octet (the decimal numbers between the dots, of which there are 4 sets) can be less than 0 and over 255. In fact, often an IP address will not end with either 0 or 255.
  3. Those decimal numbers are a meaningless as how your cell phone number maps to who you are as a person. Yeah, I know I said this 2 steps ago, but I know how FRUSTRATING it can be when you think there's something wrong with your brain because 192.168.fuck.me doesn't make any sense. It's not you. Just take a chill pill.
  4. Fuck yeah, I will swear in this document. Take THAT, fuckers! Want a piece of this?
You're going to hear a lot of terms in your studies. Most are written by people who would BORE you at the most exciting rock concert, no matter how much pot you smoked. But the concepts are SO SIMPLE, I mean, they have to talk to a computer, and computers are dumb as rocks (Hel-LO? Silicon based?). At least a pot head can make you a decent tye dye shirt without some algorithm and 10,000 lines of code.

What's an IP address?

Three things to remember to set up an IP address:
  1. IP address is like the address on your house. It's how your computer is found on the network. There can only be one IP with that address on that network. Now, some IP addresses, especially private ones, are duplicated in separate networks. But if you set the IP to 10.20.4.12... there better be only one computer with that address on your network.
  2. The network mask is simply how the computer knows which part of the IP is the network bits versus the hosts bits. Like separating jellybeans with a friend: "Here, Mr. Network, these jellybeans on the left are for you, and I keep the ones on the right for me, Mr. Hosts." Leave the licorice ones for the network portion, I can't stand them myself.
  3. The broadcast address is basically the last useable address in a block, which is used for broadcasts on the network that don't want to hear back from anyone, or maybe only a few hosts. Like an opt-in email list: you only want to hear from the people that don't have one, not "I have one" from everyone else.

What's a Default Gateway?

You don't really "need" one to get an IP, but you do need one to speak to another network. A default gateway is where your network sends packets that it doesn't know what to do with. This is your network saying, "This isn't mine, here, you take it." If the gateway doesn't know where it goes, it passes it to ITS default gateway, "this isn't mine, here, you take it," and so on up the chain until someone takes it, or it comes back, "Bzzzt... can't find address. Thank you for playing." A default gateway is only needed if you have to send traffic outside your network, for like, you know, Internet browsing and such. But if you have 10 computers in a LAN party, and don't want outside access, you don't really need one. The default gateway needs to be in your subnet.

DHCP vs Static IP?

The "D" in DHCP means "dynamic" as in "changes." Think of Dynamite, the Drag Queen of Detroit. She changes a LOT. Most computers that are NOT servers use DHCP (desktops, laptops, workstations, etc). This means they boot up, and some script or program first looks for an IP. It sends out a broadcast "Hey! Yo! Over here! I need IP, dog!" A DHCP server is listening for anynone who calls from a broadcast address on a certain port for an IP. Often the DHCP server is on your side of the firewall, either from a router that also does Network Address Translation (or NAT-ting, which means it has one outside facing IP that takes care of many inside IPs) or a server inside your "broadcast domain." The DHCP server responds, "I got your IP right here, G!" and sends some IP information back to your computer. This will have info like your IP, subnet mask, gateway, name servers, and so on. Your computer loads them up. The DHCP server also keeps track of what computer has what IP, so you don't get some bozo computer who has your same IP, and then there's a horrible mess of confused traffic. DHCP has a "pool" of addresses it can give out, and keeps track of them by "leases," which have an expiration date. Every so often, your computer renews this lease, unless it doesn't (like it's turned off or goes dead), and you still have connectivity.

Unless the DHCP server has been set up to give YOUR specific computer the SAME IP address (and it can do that,just not usually), each time you get on the network, it's a crapshoot of what IP address you end up with. Today it's 192.168.1.2, the next time you connect, it could be 192.168.1.5. You never know. DHCP is best for laptops or workstations where the IP address doesn't really matter just as long as you have one. It also is great for managing networks.

Static IP means the machine always has the same IP, which is most useful for servers. Usually, though, you have to set everything yourself with a static IP, which means you have to know the gateway, name servers, subnet mask, and so on by yourself. In some cases, I have seen some networks set up a server as DHCP, and then tell the DHCP server, "Always give this IP address to this server." Static IPs are boring, but predictable. Like that girlfriend you pretended to dump in high school.

In either case, you have to know how to set up IPs. Either on your machine, or on the DHCP server. And that's why you're here. Let's get started, shall we? What? Bored already? Come on, man. You watched the Windows defrag tool for hours last week. Stay with me.

1. Determine the class of your network.

This is taken from the first octet in the IP address. IPs are separated into classes. Like Texas Chili.

Octet Range Class Default Subnet Mask Private Addressing Notes
1 - 126* Class A 255.0.0.0 10.x.x.x Used by really high-level companies with a lot of computers
*127.0.0.1 Loopback Used to test IP connectivity to self
128 - 191 Class B 255.255.0.0 172.16.x.x - 172.31.x.x Used by larger companies, I see a lot of this in mid-level networks
192 - 223 Class C 255.255.255.0 192.168.x.x - 192.168.255.x Used by small companies, home offices, small home networks
224 - 239 Class D
n/a
n/a
Multicast Broadcast only
240 - 255 Class E
n/a
n/a
Experimental: Reserved for future use (I don't know what the hell that means, either)

What is "private addressing?" Well, each class has a separate set of addresses that everyone has agreed on are "not Internet routable." This is very handy for firewalls and NAT. See, there aren't enough IP addresses to go around any more. So you have "outside IPs" (which are most of them), and "inside IPs" which are the private addresses. The most common you will see for home and small office networks are the 192.168.x.x variety. Because this class C address range has a default mask of 255.255.255.0, you can really only have 254 hosts per subnet

2. Determine how many bits you must borrow from the hosts portion.

Use the following equation:

2n - 2 >= Number of subnets required

So if you need 25 subnets:

  1. 2n - 2 >= 25
  2. 2n - 2 >= 25
  3. 25 - 2 >= 25
  4. 32 - 2 >= 25

If n = 4 then it would have been 16, less than 25. People would laugh at you. And point.

Note: At this point, you should about expandability. If you are going to need more than 30 (25-2 )sub-networks in the future, you should go one greater, like 62 (26-2). Remember, the more networks you have, the less collision domains you have. But you will need routers to get them to speak to each other. That's another topic for a later time, but keep in mind if you have TOO many hosts all working on the same subnet (like over 100 servers all talking at once), you are going to slow your network down.

3. Make your custom subnet mask.

First, you need to determine your default mask above. To illustrate this better, let's toss our ten-digit fingers out the window, and think of them as nothing more than nonsense labels for the moment. Computers don't have fingers or toes, only switches.

Suppose you had this address: 192.168.35.x In binary, it looks like this: 11000000.10101000.00100011.x
Looking at the default subnet mask: 255.255.255.0 Which the computer sees as: 11111111.11111111.11111111.00000000
Now since n = 5 in the example above, we know we must steal five bits, which is done from left to right 255.255.255.248 This is easier to see in binary: 11111111.11111111.11111111.11111000

As you can see, this makes less sense in our decimal world. "Huh? 248? WTF?!" Easy, tiger. This is simpler than it looks. See, each "bit" from left to right represents a factor of 2some power. Here's how we break down an octet:

Power of: 27 26 25 24 23 22 21 20
Decimal Number 128 64 32 16 8 4 2 1
Binary Number 1 1 1 1 1 0 0 0

So 5 bits stolen is really 128 + 64 + 32 + 16 + 8 = 248 (in decimal). If you think this is fun, wait until I write about Binary to Hexadecimal! But now we are getting off topic again. Focus. Before going to step 4, go and get yourself a cookie and a drink of water. I'll wait.

4. Find out your hosts per network.

Okay, you have the new subnet mask, now what? "What the heck are my goddamn IP address ranges???" Whoa, too much caffeine, there, dude. But rest assured, even with too much Mountain Dew sloshing in your belly, you can do this. First, we have to determine the number of hosts per subnet. This is also better understood in binary:

Now, remember your default mask? Unless you have ADHD, you know it as: 255.255.255.248 But again, it's easier to see in binary 11111111.11111111.11111111.11111000
Since the 11111111.11111111.11111111.11111xxx is the network portion, then the remaining bits (which are zeros) are the hosts portion! Forget decimal for now Hosts (oooh): 11111111.11111111.11111111.11111000

Now, I may not be a bright man, but even I can tell there are only 3 bits left. So we use a familiar looking equation again to determine how many hosts (anything that needs an IP address to function) we have for each network.

2n - 2 >= Number of hosts per subnet

So in this case, 23 - 2 = 8 - 2 = 6 hosts per subnet. Wow, that's not a whole lot. But you do have a Class C address, and you were the bozo that wanted 25 networks.

5. Now we determine the subnet ranges!

Bet you thought we'd never get here. There is an incrementing interval we find find out first. That's EASY. It's:

256 - subnet mask = Interval

So, in our example, 256 - 248 = 8! Well, whattia know! This will also be the value of the lowest network, unless you are including zero networks, but for this case, we won't. So, now we start moving the tables around.

Subnet Subnet Address First useable IP Address Last useable IP address Broadcast Address
First 192.168.35.8 192.168.35.9 192.168.35.14 192.168.35.15
Second 192.168.35.16 192.168.35.17 192.168.35.22 192.168.35.23
Third 192.168.35.24 192.168.35.25 192.168.35.30 192.168.35.31
Fourth 192.168.35.32 192.168.35.33 192.168.35.38 192.168.35.39
... 30th 192.168.35.240 192.168.35.241 192.168.35.246 192.168.35.247

Note we didn't use the 192.168.35.0 or 192.168.35.248 networks. We usually discard the first and last (which is why there are only 30 instead of 32 available in the equation above). This makes sense because the first would have 192.168.35.0 as a subnet, when it's really considered the name of a whole network. And 192.168.35.248 would have 192.168.35.255 as a broadcast address for a subnet when it should be the default broadcast for the whole 192.168.35.0 network. This will confuse people later on. But I'd be a liar in a Viking hat if I said that it hasn't been done before. It's just not a good IDEA. Many subnet calculators out there also include these networks, usually called zero networks.

As a side note, how many hosts SHOULD you have per subnet? Well, the rule of thumb is that you shouldn't have more than 254 hosts in the same subnet because they will all share the same collision domain. Your network will slow to a crawl with all that traffic. Keep in mind, a lot of traffic isn't just a machine accessing the Internet, a lot of services will constantly send traffic back and forth. If you have ever sniffed traffic on a closed network, even "idle" computers are sending info back and forth, espically if you haven't firewalled them and you have default services enabled. If you have 1000 hosts on the same subent, even if the machines are idle, you will notice some machines will start to slow down as the NIC or software tries to process all the messages.

A lot of people have /24 networks to make sure this doesn't happen, which is 254 hosts, and /24 is an "even break point" of one octet that's easier to do quick math. Routers/firewalls and managed switches (like VLANS) will take care of any translation from subnet to subnet.


More Examples

We're going to go through more examples now, so you can understand more.

Example 1

Problem: Given IP range of 10.x.x.x, and you have to create 10 subnets.

  1. You have a Class A address. Default mask is 255.0.0.0
  2. 24 - 2 = 14, which is > 10. So we need to steal 4 bits from the host portion.
  3. That means our subnet mask is 255.(128+64+32+16).0.0 = 255.240.0.0
  4. Our host bits left are 20, so 220 - 2 = 1,048,574 hosts per net (that ought to be enough, in fact, way too many but hey)
  5. Our digital interval is 256 - 240 or 16. So we know the first network is 10.16.0.0! You wouldn't want to use it, since it's a zero network, but I'll include it anyway to show you where it goes.
    Subnet Subnet Address First useable IP Address Last useable IP address Broadcast Address
    First 10.16.0.0 10.16.0.1 10.31.255.254 10.31.255.255
    Second 10.32.0.0 10.32.0.1 10.47.255.254 10.47.255.255
    Third 10.48.0.0 10.48.0.1 10.63.255.254 10.63.255.255
    ...14th 10.224.0.0 10.224.0.1 10.239.255.254 10.239.255.255

Example 2

Problem: Given IP range of 129.50.x.x, and you have to create subnets for each state in the US.

  1. You have a Class B address. Default mask is 255.255.0.0
  2. 26 - 2 = 62, which is > 50 states. So we need to steal 6 bits from the host portion.
  3. That means our subnet mask is 255.255.(128+64+32+16+8+4).0 = 255.255.252.0
  4. Our host bits left are 10, so 210 - 2 = 1,024 hosts per net.
  5. Our interval is 256 - 252 or 4. So we know the first network is 129.50.4.0!
    Subnet Subnet Address First useable IP Address Last useable IP address Broadcast Address
    First 129.50.4.0 129.50.4.1 129.50.7.254 129.50.7.255
    Second 129.50.8.0 129.50.8.1 129.50.11.254 129.50.11.255
    Third 129.50.12.0 129.50.12.1 129.50.15.254 129.50.15.255
    ...50th 129.50.200.0 129.50.200.1 129.50.203.254 129.50.203.255
    ...62nd 129.50.248.0 129.50.248.1 129.50.251.254 129.50.251.255
    You have 12 subnets left over for expansions into Guam, Puerto Rico, and the US Virgin Islands.

Example 3

Problem: You are a poor contractor, signed up for a great contract with the British Government to set up 2 monitoring stations in each country in the whole world. You got the IP range of 222.100.42.x. Can you do it with separate networks for each country?

  1. You have a Class C address. Default mask is 255.255.255.0
  2. 28 - 2 = 254, which is > 192 countries. So we need to steal 8 bits from the host portion.
  3. That means our subnet mask is 255.255.255.(128+64+32+16+8+4+2+1) = 255.255.255.255
  4. Our host bits left are 0, so no can do!

Problem: How about just the countries in Europe?

  1. You have a Class C address. Default mask is 255.255.255.0
  2. 26 - 2 = 62, which is > 44 European countries (as of this writing). So we need to steal 6 bits from the host portion.
  3. That means our subnet mask is 255.255.255.(128+64+32+16+8+4) = 255.255.255.252
  4. Our host bits left are 2, so 22 - 2 = 2 hosts per net... just enough!
  5. Our interval is 256 - 252 or 4. So we know the first network is 222.100.42.4!
    Subnet Subnet Address First useable IP Address Last useable IP address Broadcast Address
    Albania 222.100.42.4 222.100.42.5 222.100.42.6 222.100.42.7
    Andorra 222.100.42.8 222.100.42.9 222.100.42.10 222.100.42.11
    Austria 222.100.42.12 222.100.42.13 222.100.42.14 222.100.42.15
    ...Serbia/Montenegro 222.100.42.176 222.100.42.177 222.100.42.178 222.100.42.179
    ...62nd 222.100.42.248 222.100.42.249 222.100.42.250 222.100.42.251
    You have 12 subnets left over for expansions into some of the Middle Eastern regions.

See, it's not that hard, once you think in binary. Some classes you take might ask you to think in HEX, which is like having 10 fingers and using all the toes on one foot. They go 0,1,2,3...9 and then A,B,C,D,E, and F for 10-15. "Hexadecimal" means "six and ten" or 16, which is 0-15 (remember, computers always start with 0 when counting). In some of the old configs I have seen on Sun/Solaris boxes, I have seen the netmask as ff.ff.ff.C0. That's really 255.255.255.192, because ff = 16 x 16 numbers, or 256, which is 0-255 in range.

And you now know what that is in binary, right? ;-)


Who is the author? Grig "Punkie" Larson is listed elsewhere on this site, but as of 2009, he's a Senior Systems Administrator for a huge non-profit near DC, with a LPIC, RHCT, and is a Network+ Certified fool. He failed his CCNA at 64 the first time%. Dooooh! Who wrote that goddamn test? Retarded Elbonians? But that was in 2000, and when he finally passed, his cert expired in 2003. Time to stop living in the past. Maybe he'll get one in 2015.
[ Home ] [ How-To ] [ What's New ] [ About Me ] [ My Writings ] [ Web Links ] [ Post Office ]