Tutorial: IP Addresses and Subnetting

When you connect your computer to the internet, your computer is given an Internet Protocol (IP) address.  If you check your connection settings, you will commonly see two similar values; one is called a subnet and the other a gateway.  Have you ever wondered what these three actually mean and what they do?

An IP address is like your address at your home.  Your home address tells other people where to find you when you’re home, and your IP address tells other computers where to find your computer.  The most common form of an IP address is called dotted decimal notation, which has four sets of numbers, each ranging from 0 to 255, separated by a period.  192.168.0.1 is a common example, and I’ll use it throughout this tutorial, so write it down!

Why 0 to 255?  It is the range of an octet, or 8-bit number.  As you’ve heard before, computers speak in binary, which is just 0’s and 1’s, on and off, etc.  Each bit can have a 0 or a 1, so the range 0 to 255 is really 00000000 to 11111111 in binary.  There are four octals in an IP address, which is a fancy way of saying an IP address is a 32-bit number.

Which of these numbers is easiest to understand?

  1. 192.168.0.1 – Dotted Decimal Notation using octals
  2. 11000000101010000000000000000001 – Binary
  3. 11000000.10101000.00000000.00000001 – Dotted Binary
  4. 3232235521 – Decimal Notation

They are all the same!  But #1 has proven itself to be the easiest to use, especially when you have subnetworks.

Subnetworks?  You mean there’s more than one???  The reason relates to divide-and-conquer.  One person trying to manage 4294967296 computers would be tasking, to say the least.  Hence we can use subnetworks, or subnets, so that one computer is not responsible for the whole network.  With the hardware and software out today, it’s easy for a device to manage it’s own subnet.  But which one are you using?  How big of a subnet are you in?

The answer is right there in your subnet, sometimes called a subnet mask.  This tells us what subnet we are a part of, and how big the subnet is.  To make things easier, there are three defined subnets:

  • Class A – 255.0.0.0
  • Class B – 255.255.0.0
  • Class C – 255.255.255.0

For our example, let’s say that our IP address, 192.168.0.1, is in a Class C subnet, 255.255.255.0.  This means that 192.168.0.1 is in a subnet with 256 addresses ranging from 192.168.0.0 to 192.168.0.255.  (“How I did that” is coming up…)

An IP address is actually a combination of two IDs, a network ID and a host ID.  Notice in the range above, the 192.168.0 stayed constant while the last octet changed.  Simply put, the constant 192.168.0 is the network ID and the last octet is the host ID.  This is important so your computer knows what subnet you are on.

By now you’ve noticed that our subnet mask, 255.255.255.0 has no digits in common with our IP or our range of IPs–so why is it important?  Our subnet mask is the dividing line between network and host!  Let’s look at our IP and subnet mask:

IP:     192.168.  0.  1
Subnet: 255.255.255.  0

That vaguely shows me that the first three octets are the network, but you’ve seen subnets that don’t have 255 or 0 in all of the slots.

What does binary show us?

IP:     11000000.10101000.00000000.00000001
Subnet: 11111111.11111111.11111111.00000000

There it is!  Every bit in the subnet that’s a 1 makes that bit in the IP part of the network.  Every bit in the subnet that’s a 0 makes that bit in the IP part of the host.

Let’s take a look at a different subnet mask: 255.255.255.128.  This isn’t one of our three “class” subnets, and thus it is called a classless subnet.  Again, in binary:

IP:     11000000.10101000.00000000.00000001
Subnet: 11111111.11111111.11111111.10000000

Not a big change, but what does that do to our network?  First, you now only have 2^7, or 128, hosts in your subnet instead of 256.  And now your network ID has changed…

With our new subnet, is 192.168.0.127 in our subnet?

Subnet: 11111111.11111111.11111111.10000000
IP:     11000000.10101000.00000000.00000001 <-- 192.168.0.1
IP:     11000000.10101000.00000000.01111111 <-- 192.168.0.127
        ←          Network         →← Host→

Both IPs have the same Network ID, thus they are in the same subnet.

What about 192.168.0.128?

Subnet: 11111111.11111111.11111111.10000000
IP:     11000000.10101000.00000000.00000001 <-- 192.168.0.1
IP:     11000000.10101000.00000000.10000000 <-- 192.168.0.128
        ←          Network         →← Host→

These have different Network IDs, so they are in different subnets.

What if we go back to a Class C subnet?

Subnet: 11111111.11111111.11111111.00000000
IP:     11000000.10101000.00000000.00000001 <-- 192.168.0.1
IP:     11000000.10101000.00000000.10000000 <-- 192.168.0.128
        ←          Network        →← Host →

Now they are in the same subnet!

Before we noted that dotted decimal notation is preferred for writing IP addresses because it’s the easiest to remember.  If you have a Class C subnet and are responsible for assigning IP addresses to computers, you know that [in our example] the first three octets will always be 192.168.0!  Much easier!

There’s also a shorthand for writing subnets.  Just put a slash (” / “) after the IP address, and then write how many 1’s are in your binary form of subnet.  For example, with a Class C subnet our shorthand would read 192.168.0.1/24, and our classless example would be 192.168.0.1/25.

In your network settings, there’s also a gateway.  How does it relate?  The gateway is an IP address INSIDE your subnet which connects you to the OUTSIDE of your subnet.  If you try to send a packet to a computer and it’s IP address isn’t in your subnet, then your computer sends it to your gateway and the gateway passes the message on.

I know how you feel.  When I learned about subnetting, the only thing I could think of is, “how will this be useful?”  I then went into work and looked at my company’s IP address, subnet, and gateway (I changed the company IP to protect my company, sorry):

IP:     192.168. 25.174
Subnet: 255.255.255.252
Gateway:192.168. 25.173

Back to binary:

IP:     11000000.10101000.00011001.10101110
Subnet: 11111111.11111111.11111111.11111100
Gateway:11000000.10101000.00011001.10101101

Let’s look at the subnet first.  There are only two bits for hosts IDs (and 00 and 11 are reserved), which leaves exactly TWO IP addresses in this subnet.  This means that my computer is on a network BY ITSELF, and the other is used as the gateway!  This does not work for every case but when I have just one computer I don’t want anyone else inside my subnet!

And my IP and subnet are easy to remember because I write it as 192.168.25.174/30!

Internet Safety and Privacy Concerns…are you protected?

Over my tenure as a “computer guy” I’ve been asked to “fix” a computer countless times.  I remember it started out as “my computer won’t print” or “the screen went blank”, but lately I’ve heard a different phrase… “the internet is down!”  While this may be true, it is also proving to be safer.  Recently I’ve helped family, friends, clients, etc. to get rid of Antivirus spoofs, or fake programs that look legitimate, but in reality are a virus, a phishing scam, or worse!

It starts with an unknown website or email attachment (I even saw one come in from an internet ad!) which puts the virus on your computer.  From there, it quietly works its way into the computer disabling the “easy way” for me to fix it, then finally pops up a window saying “You are infected!”  The popup looks like a windows program and most of the time doesn’t have a brand name so it just says “Antivirus 2009” etc.  If I’m lucky, I get a call when they see this screen.  Most of the time, I’m not that lucky…

Should you let it scan your computer, it starts listing important files as infected and says that you can pay some amount to buy the program and it will clean the viruses for you.  At which point they ask you for a credit card number, and then you are toast!  It was all a ploy to steal your credit card & identity to do who knows what with them!

Granted there are fixes, patches, and repair tools to these problems.  However, these attacks are better off being prevented than treated, and all it takes is an antivirus and/or antispyware program, some are even FREE.

So why hasn’t every computer user without antivirus downloaded the free antivirus tool?  Because the average user doesn’t think that they will get a virus, which is the same as the average biker not wearing a helmet because they don’t think they’ll crash.

We are not as safe on the internet as we think we are!

Case in Point: AT&T had a glitch the other day where a customer was on their phone going to Facebook to login, and they were automatically logged in…TO SOMEONE ELSE’S ACCOUNT!  Apparently, the servers were confused on who was who, and it sent the wrong information to the wrong phone.  I don’t think anyone is to blame, but this just proves that what you think is safe isn’t really safe.  (Read the AP story here.)

What you think is private isn’t really private.  You can put the pictures of you partying on MySpace, but just remember that a court order will put those pictures in the hands of the prosecutor.  If you don’t believe me, read here.

Now an antivirus/antispyware program won’t prevent the outcomes of the past two points, but that doesn’t mean you shouldn’t protect your computer.  Without these programs, anyone could take over your phone and make calls or hack into your personal computer and download your pictures.  If you buy a brand new 65″ Plasma TV, you’d get the protection plan.  Even if it’s free, you’d still want it.  So protect your computer!