Digital Globe

I thought it would be a good idea to cover the basics of IPv4 subnetting. There are a couple of reasons for this, but primarily it will help you when I start getting into some of the topics I want to cover later on. Understanding this is essential for every network and server engineer or admin in a current generation network.

One of my biggest concerns in the IT world is the complete and total lack of understanding many system administrators seem to have for how IP networking really works. They seem to understand very clearly how Windows Active Directory networking works, but the fundamental understanding of the OSI model in reference to networking just doesn’t exist. The OSI model is a very essential model that all admins (network and system) need to know about and understand. However, at this point we’re going to concentrate on just one of the layers within the OSI model. That is layer 3.

Layer 3 (the network layer) is where the IP protocol exists. IPX and ICMP are two other well known protocols that exist at this layer. Layer 4 (the transport layer) is where the TCP protocol exists. SPX and UDP are two other well known protocols at this level. We will not be worrying about Layer 4 protocols at this point. If you do not understand the OSI model, tell me and I’ll cover it at a later point. However, for now, we are going to be working solely with IP, thus layer 3.

The IP protocol is the network protocol that does the routing and subnetting. It is the protocol with which we define networks and the paths used by networks to pass packets amongst themselves. People will often refer to TCP/IP when they mean just IP. For example, in Windows it will give you TCP/IP settings inside your network interface device, however most people are solely configuring IP settings here (IP address, netmask, default gateway.) The TCP part comes from defining your DNS settings. IP does not use hostnames at all. They don’t even exist in IP.

I’m covering IPv4 because that is currently the most prevalent network protocol in use across the world. IPX is another routed network protocol that has had major use in the past, but has lost significant ground to IPv4 over the past 10 or 15 years. Ironically, its happened much the same way Novell Netware lost ground to Microsoft Windows. Theres a good reason why this coincided with the decline of IPX. Netware was probably (in my opinion at least) the largest install base of the IPX protocal. IP also happens to have been the basis of Internet traffic routing, so as the Internet grew in use in the late 80s and early 90s, so too did the decline of IPX start happening.

IPv6 is definitely one you will need to know in the future. Unfortunately, because organisations like ICANN and the IANA are in no rush to promote IPv6, it has very little use globally outside of countries in Asia and some countries in South America. This will change, but I’ll cover all this in another post a little later.

Lets get into it shall we?

So what are IP addresses and what the heck is a subnet?

Think of it in terms of a postal address. Your house has a specific number on a specific street, in a specific zip code for a specific area. IP addressing is much the same way. The IP address is your street address. However, the netmask defines how many houses are allowed to be included in a zip code. It is effectively the thing that defines the boundaries of the zip code. Each zip coded area then becomes a separate network.

Each group of computers within a single area or network is able to talk to each other freely. However, if you want to talk to a computer in another zip code (outside your defined network) you need to go through an intermediary. Essentially, you need to send a letter from your zip code to the other zip code. In the IP networking, this is known as routing. Routing allows the different zipcodes/networks to talk to each other.

Networks are often split up like this for specific purposes. The common one being performance and also security. You may not want California to talk to Florida openly, but you may want them to have some basic communication that you can limit or control. The orange industry is cut throat, so you want to be able to ensure that secrets from one area are not being passed to the other. So you put them on two separate networks and require that they talk through an intermediary.

Welcome to Steve’s Subnetting 101.

Splitting up the networks is done using a subnet mask. A subnet mask is a 4byte number (32bits) that is usually written in much the same way an IP address is (xxx.xxx.xxx.xxx) but that defines the boundaries of a network. The most common subnet mask that just about everyone is familiar with is the Class C subnet, 255.255.255.0. This is a 24 bit subnet mask.

Why is it 24bit? Well, working with subnets is best done in binary. Looking at that dotted-decimal notation there doesn’t really tell you how things are put together. The math involved is a lot harder when you’re working with dotted-decimal. It makes a lot more sense when you start to work in binary.

255.255.255.0 = 11111111.11111111.11111111.00000000

There are 24 out of 32 bits that are set to on (1). Thus, it is called a 24 bit netmask. One group of 8 there is called an octet. Each of those 4 octets make up an 8 bit (1 byte) number. Converted to decimal, 255.255.255.0. However, in networking, when working with networks, we count the total of consecutive 1′s from the left to right to give us the netmask. Because there is a total of 24 1′s, thats a 24 bit netmask.

Now let me confuse you immensely by talking about how you actually count normal numbers in binary.

In binary, we count in colums from right to left. Here is a very fast explanation of how we get 255 from 11111111

00000000 = 0
00000001 = 1
00000010 = 2
00000011 = 2 + 1 = 3
00000100 = 4
00000101 = 4 + 1 = 5
00000110 = 4 + 2 = 6
00000111 = 4 + 2 + 1 = 7
00001000 = 8
00001001 = 8 + 1 = 9
00001010 = 8 + 2 = 10
00010000 = 16
00100000 = 32
01000000 = 64
10000000 = 128
11111111 = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255

See whats happening there? Binary is counting using an on/off switch. Each switch is a bit. In this case, we’re counting using 8 bits. IP addresses and netmasks are made up of 4 x 8 bits, so a total of 32 bits.

My computer that I’m using currently has the following IP address

11000000.10101000.01100101.00001010

Lets break that down.

  1   1   0   0   0   0   0   0
128  64   0   0   0   0   0   0   = 128 + 64 = 192

  1   0   1   0   1   0   0   0
128   0  32   0   8   0   0   0   = 128 + 32 + 8 = 168

  0   1   1   0   0   1   0   1
  0  64  32   0   0   4   0   1   = 64 + 32 + 4 + 1 = 101

  0   0   0   0   1   0   1   0
  0   0   0   0   8   0   2   0   = 8 + 2 = 10</pre>

Put together, that means my IP address is 192.168.101.10

Right, now we’ve covered how to count in binary, lets get into the gritty details of subnetting and how to work out networks based on subnets.

Subnets are worked out in binary in much the same way. You count in base 2 just as you do when counting IP addresses. However, when deciding on a netmask or subnet size, we need to consider several things. How many computers do we want in a single network? How many networks do we have? How many IPs do we have that we need to divide between the networks?

On my own network, I have limited the amount of IP addresses. The number is basically the total number of computers I own + the number of computers my family own + a number of spares left over for when people visit with their laptops or whatever. I also take into account the printer that is plugged in to the network, the router, the firewall and things like my brother’s PSP.

This subnet mask is 255.255.255.224. In binary, this is the same as:

11111111.11111111.11111111.11100000

   1   1   1   1   1   1   1   1
 128  64  32  16   8   4   2   1   = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255

   1   1   1   0   0   0   0   0
 128  64  32   0   0   0   0   0   = 128 + 64 + 32 = 224

Now, most people are used to seeing the netmask as being 255.255.255.0 which allows for 254 IP addresses to be used on any given network. That is, 256 minus the broadcast address, minus the network address. Don’t worry about these for now, we’ll cover them later. What I want to know is, how many total IP addresses have I got available on my network with that netmask and what is the range I’m in?

Heres where things get really funky and your binary math skills start getting put to use. :-) Remeber before I mentioned that 255.255.255.0 is a 24 bit subnet mask? Well, 224 is a 27 bit subnet mask. Here how you work that out.

11111111.11111111.11111111.11100000   =  27 consecutive 1's

hehehe. Bet you thought I was going to scare you with some long math? :-) What I will point out however is that any bit that is turned on (set to 1) is considered part of the network address space, while any bit turned off (set to 0) is part of the host space. You’ll see what I mean in a second.

Now, thats well and great, but how many networks does that give us? And how many hosts on each network? Actually, its not as hard as you might think. First we take the last of the 1′s there and work out what its numeric value is. In this case its 32. For this extremely simple example, that happens to be the number of IP addresses in each of our networks (but not the number of usable host addresses.) Want proof? Lets work it out properly.

Because we’re using 3 bits out of the last octet to represent the network, that tells us how many subnets we will be using. 23 = 8. So there will be 8 possible networks available to us. How many IPs on each network? Well, we have 5 bits left over (switched off.) So 25 = 32. So we have 32, minus the network address, minus the broadcast address for a total of 30 possible devices or hosts connected to the network.

We know that all octets start at 0 and end at 255. We now know that there are 32 addresses per network and 8 possible networks in our netmask. So that leaves us with the following…

192.168.101.0     -   192.168.101.31
192.168.101.32    -   192.168.101.63
192.168.101.64    -   192.168.101.95
192.168.101.96    -   192.168.101.127

192.168.101.128   -   192.168.101.159
192.168.101.160   -   192.168.101.191
192.168.101.192   -   192.168.101.223
192.168.101.224   -   192.168.101.255

So there we have it. That gives us 8 networks, each containing 32 addresses. However, on every network, 2 addresses are not usable by hosts or devices. Those being the first and last address.

The first address (192.168.101.128 for example) is the network address. The second address (192.168.101.159) is the broadcast address. Anything sent to the broadcast address is effectively sent to all computers/hosts/devices that are on that network.

The more common ones that everyone may know would be something along the lines of 192.168.1.0 – 192.168.1.255. Where 0 is the network address and 255 is the broadcast address. This is called a 24 bit network, or a Class C network.

Some people wonder why we say there are 256 addresses when we stop at 255. Well, the simple answer is that we start counting at 0. 20 is where we begin, and 27 is where we end. That is a total of 256 numbers, the first of which is 0, the last of which is 255. Counting up to 256 would mean we used 9 bits (100000000) and that throws a whole new kettle of worms on the fire. Its also something we’ll discuss when we talk IPv6 at a later date.

I’m sure all of this is as clear as mud. I’m probably not helping too much by using a very simplistic example here (and will expand on it if people want me to) but its a good place for you to get your start.

If you’d like me to explain something here, please feel free to ask and I’ll do so as usefully as I can.