Understanding IP addresses (part 1)
Written by Iceberg   
Monday, 19 January 2009 20:11
Ok, so I'm taking a course for a CCNA certification at the community college. This article will explain basically how an IP address actually works.

Introduction

So, you've probably heard people talk about how computers all use binary numbers to really work. In movies and TV, they often will overlay computer scenes with 1s and 0s to sort of make it look all techie, right? If you're like most people though, you have never actually seen any evidence of binary when working with your computer.

This is about to change.

The IP Address

An IP address, (or Internet Protocol address) is a set of numbers that represent a location on a network. For most of us the most common network we see is the Internet. When you open your web browser and give it an address such as www.google.com, your computer consults a sort of digital phone book called DNS. (Domain Name Service) A DNS server computer responds to your computer's request with a set of numbers that represents the address you gave it. For example, www.google.com may actually point to 74.125.19.103. This number is an IP address, and is the "real" address of the computer you have asked to contact.

Remember how I said we were going to finally meet some binary numbers in your computer? Well, there they are! That set of four numbers is actually a decimal representation of a set of 32 binary digits! These digits have been grouped into sets of eight (octets) for ease of use.

Going Binary

To understand binary numbers, you have to first understand how we write down numbers for our use. Binary is a numbering system, just like the Decimal system we're all used to using. The number set we normally use in our lives is also sometimes called "base-10" because it has ten digits in each decimal place. Think of it like an odometer in your car. As you count up, you use the first place until you get to nine, then that place resets to zero, and the one to the left goes up by one digit.

01
02
03
04
05
06
07
08
09
10

Binary is exactly the same way, except that it has only two digits, which is why it's called "base-2". If you wanted to count in binary, you could think of the same odometer with only two digits on each one of the places.

01
10
11
100
101
110
111

See how each time it advances, the one on the far right starts over?

In a numbering system, each digit is a product of that digit and a power of the base number, starting with zero. Let's look at an example again to get this sorted out. Here's a number:

196

The six is in the first place. It is worth 10 to the 0th power, or 1. (In math, anything to the 0th power is one.) For our number then, the first digit is 6 x 10 ^ 0 (six times ten to the zero'th power). Or 6x1=6.

This is where it starts to make sense! The second digit is nine, and it's in the second place. The value of that place is 10, which is 10 to the 1st power. So the value of that slot is nine times ten to the first power, or 9 x 10 ^ 1 = 90. That place is worth 90.

Finally the third digit is worth ten to the second power, or 100. So the 1 is actually 1 x 10 ^ 2, which is 1 x 100 = 100.

Add them all up:  100 + 90 + 6 = 196!

Binary works exactly the same way, except that the numbers are base-2, so all the digits are powers of two instead of ten!

Here's a binary number:  

11000100

Starting at the right, we then can figure out the value by using the powers of two, just like we did with the powers of ten!

0 x 2 ^ 0 = 0    (2 ^ 0 = 1)
0 x 2 ^ 1 = 0    (2 ^ 1 = 2)
1 x 2 ^ 2 = 4    (2 ^ 2 = 4)
0 x 2 ^ 3 = 0    (2 ^ 3 = 8)
0 x 2 ^ 4 = 0    (2 ^ 4 = 16)
0 x 2 ^ 5 = 0    (2 ^ 5 = 32)
1 x 2 ^ 6 = 64    (2 ^ 6 = 64)
1 x 2 ^ 7 = 128    (2 ^ 7 = 128)

Now add up all the values:  128 + 64 + 0 + 0 + 0 + 4 + 0 + 0 = 196

Congratulations! You can now convert from decimal to binary!

Back to the IP address

Getting back to that address we found for www.google.com earlier...  It was 74.125.19.103.

What you're actually looking at are four sets of eight binary "switches" that make up a 32-bit address. A bit is just a single binary "switch" in your computer's cpu! These switches are how computers actually think! Let's take apart that network address.

First Octet:  74.
The values of a set of eight binary digits from left to right are 128, 64, 32, 16, 8, 4, 2, 1. (Remember the powers of two?) To get the value 74, we need to figure out what binary places should be "turned on" to make 74. We'll start on the left.

128?  Nope, too big. Leave this one off (0)
64?  Yep, that's less than 74. Now we have 10 left to fill. Set this one to on (1)
32?  No, we only have 10 left, remember? Leave this one off (0)
16?  Still more than 10. Leave this one off (0)
8?  Yes! That's less than 10. Now we have 2 left to fill. Set this switch to on (1)
4?  Nope, greater than the 2 we have left. Leave this one off (0)
2?  That's it! Exactly the value we need! Set this one on (1)
1?  We already finished our value! No need for this one. Set it off (0).

The value of our first octet, which is 74 in decimal numbers is 01001010 in binary!

If we do the same for each of those, we'll get a binary version that looks like this:

01001010.01111101.00010011.01100111

Get rid of the periods...

01001010011111010001001101100111

And that is the actual IP address for www.google.com, as your computer sees it.