Networking 101: Undressing IP addresses (Part 2 of 4 )

In the previous post, you learned all about IP addresses and how to convert them to binary.

In this guide we’ll review the conversion process and then jump into:

  • The purpose of subnet masks and why you need them.
  • What the heck are private IP addresses?
  • How to figure out the IP address Class.

Let’s jump right in.

Here’s a quick test.

How would you convert the number 51 into binary?

Binary to Decimal is easy

You could think something like this:

128, 64, 32, 16, 8, 4, 2, 1.

  • Can I squeeze 128 into 51? No: 0.
  • Can I squeeze 64 into 51? No: 0.
  • Can I squeeze 32 into 51? Yes: 1.
    • What’s left over? 19
  • Can I squeeze 16 into 19? Yes: 1.
    • What’s left over? 3
  • Can I squeeze 8 into 3? No: 0.
  • Can I squeeze 4 into 3? No: 0.
  • Can I squeeze 2 into 3? Yes: 1.
    • What’s left over? 1
  • Can I squeeze 1 into 1? Yes: 1

So 51 in binary is 00110011.

Let’s try another number.

What’s 192 in binary?

Write out your binary chart again:

128, 64, 32, 16, 8, 4, 2, 1

  • Can I squeeze 128 into 192? Yes: 1.
    • What’s left over? 64
  • Can I squeeze 64 into 64? Yes: 1.
    • What’s left over? 0

So 192 is 11000000 in binary.

Are you started to get the hang of it?

Lets try one more just to drive the concept home:

Convert 255 to binary:

128, 64, 32, 16, 8, 4, 2, 1

  • Can I squeeze 128 into 255? Yes: 1
    • What’s left over? 127
  • Can I squeeze 64 into 127? Yes: 1
    • What’s left over? 63
  • Can I squeeze 32 into 63? Yes: 1
    • What’s left over? 31
  • Can I squeeze 16 into 31? Yes: 1
    • What’s left over? 15
  • Can I squeeze 8 into 15? Yes: 1
    • What’s left over? 7
  • Can I squeeze 4 into 7? Yes: 1
    • What’s left over? 3
  • Can I squeeze 2 into 3? Yes: 1
    • What’s left over 1
  • Can I squeeze 1 into 1? Yes: 1

So 255 in binary is…

Converting 255 to Binary

11111111

Great!  I think you’re getting the hang of this.

Now that you know how to convert decimal numbers to binary I can show you how we know which part of an IP address belongs to the street (the network) and which part belongs to the house number (the hostID).

Let’s convert 10.0.2.15 into binary.

00001010 00000000 00000010 00001111

32 bits, 4 bytes, 1 IP address.

Hiding behind a mask

In order to find which portion belongs to the network and host we have to look at the subnet mask.  Every IP address has a subnet mask (sometimes called a netmask or just a mask)  In fact, without a mask there’s no way to actually use an IP address because no one would know which street the device lives on.

If you type ipconfig on your PC or ifconfig on your Mac you’ll see a value that says Subnet Mask or Netsmask.  We’re going to use this mask for 10.0.2.15:

255.255.255.0

Why are we using that?  Because the network administrator assigned that mask to the IP address.  When you understand subnet masks you can determinate exactly how many hosts you want per network and a bunch of other cool things.

Let’s convert 255.255.255.0 to binary and put it under the 10.0.2.15 IP address:

00001010 00000000 00000010 00001111  10.0.2.15
11111111 11111111 11111111 00000000  255.255.255.0

Everywhere you see a 1 in the mask is where the IP address belongs to the network ID and everywhere you see a zero is where the IP address belongs to host.

So in this example,

10.0.2 is the network ID and .15 is the host ID.  That’s where we divide the line.

Subnet Masks and IP addresses love each other

There are 24 bits in the subnet mask so you might

Network Administrators would typically say, this host lives on the network of 10.0.2.0.  Note the last zero.  We just use it as a placeholder.  The 10.0.2.0 is just a street name; the network where the host lives.

Also, since there are 24 consecutive bits in the mask you might see 255.255.255.0 written as /24. (slash twenty four).  This is known as Classless Interdomain Routing Notation (CIDR).

10.0.2.0/24 means the first 24 bits of the IP address denote the network and the last 8 bits are reserved for hosts.

CIDR

Shh… some IP addresses are special

So there’s this big company called the Internet Assigned Numbers Authority (IANA) that is responsible for handing out unique IP addresses to everyone.  Technically you could use any valid IP address you want inside your own organization; however, IANA has designated specific addresses as Private Addresses.  Interent Service Providers won’t let organizations route traffic through the internet if the device is using a private IP address.  This means organizations can use private IP addresses in their organizations without any fear of IP conflicts.  Two companies can both have the same private IP address without any issues because private IP addresses aren’t routable.

Here are the Private Addresses you need to know:

  • 10.0.0.0/8
  • 172.16.0.0/12 through 172.31.255.255/12
  • 192.168.0.0/16

IP addresses are classy

Remember I told you that every IP addresses needs a subnet mask?  If a device ever sees a “naked” IP address, it assumes a default mask based on the first IP address number.  By the way, this is also called the first octet since each decimal number is 8 bits long.

There are three classes

  • Class A is /8 so this is 255.0.0.0
  • Class B is /16 so this is 255.255.0.0
  • Class C is /24 and this one is 255.255.255.0

By the way, IP networks that use these default masks are called classful masks.  There aren’t too many of these out there.  If it’s classless it means all you care about are the number of successive bits (from left to right).


 

So here’s the breakdown for the first octet:

  • Class A is when the first octet falls within 1 and 126
  • Class B is when the first octet falls within 128 and 191
  • Class C is when the first octet falls within 192 and 223

The 127 block is reserved and isn’t used that’s why I skipped it in the list above.

So let me ask you a question: which class does this IP address fall in?

8.8.8.8

Well the first octet is an 8 so you know by default it’s a Class A address with a 8 bit mask.

How about this one:

198.57.208.223

Just look at the first octet.  Since 198 falls between 192 and 223 inclusive, it belongs to Class C.

And now you know the basics of IPv4!

The Bottom Line

In the next guide, we’re going to look at IPv6 addresses and explain why we even have two versions.

If you’ve followed my tutorial series so far you should know:

  • Exactly what an IP address is
  • How to convert an IP address into binary
  • The purpose of the Subnet Mask
  • How to determine the class an IP address belongs to

You’re getting smarter with every article.  The next time you watch a movie and a hacker says something about IP addresses you’ll know exactly what she means.

Stay tuned.

 

About

Connect with Vonnie on Twitter

Posted in Mac OS X 10.10 Yosemite, Mac OS X 10.8 Mountain Lion, Mac OS X 10.9 Mavericks, What Is, Windows, Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Vista, Windows XP Tagged with: , , ,