IP addresses!
Oh yeah, I know what those are. I’m hearing about IP addresses everywhere these days.
Chloe on 24 tells Jack Bauer that she just hijacked the IP address that belongs to a terrorist. And in Live Free or Die Hard, super hacker Matt tells McClane that he blocked the enemy IP address from getting on the network.
IP addresses are getting a lot of fame these days but what exactly is an IP address? I don’t want the hollywood definition – I want the real definition!
In this guide you’re going to learn:
- How to think about IP addresses
- Converting decimals to binary
Let’s jump in.
Right now I want you to stop what you’re doing and view your IP address.
Press the Windows Logo key and type cmd.exe. Then type ipconfig and hit enter.
If you’re using a Mac, press Command + Space, type terminal and type ipconfig getifaddr en0 enter.
Look at the IPv4 Address listed below: 10.0.2.15
What does this number mean? What’s a good way to think about it?
An introduction to IPv4 Addresses
IP addresses come in two versions:
- IPv4
- IPv6
I’m going to start you off with IPv4 and we’ll move into IPv6 later.
For now, I’m going to tell you the purpose of an IP address:
IP addresses name networks in the same way streets name houses.
Think about where you live for a moment. There are houses in your neighborhood and each house has a unique numerical address. When we talk about IP addresses, each “street” is a computer network and each “house” on a given network is called a host.
Street intersections are known as Routers because routers connect networks. In fact, every Network Interface Card (NIC) on a router connects to a completely different network (completely different street).
The IP address is the street name and house number for a given device.
Undressing IP addresses
Every internet connected device has an IP address. Every computer, tablet, smartphone, smartTV, Roku, router, printer, server or refrigerator has an IP address if it’s connected to a network.
And every IP address must be unique. There’s one little exception there but for now all you need to know is that you can’t have two devices connected to the same network with the same IP address.
So lets break down the anatomy of an IP address by looking at this one:
10.0.2.15
Every IP address in the universe is a combination of a street name and house number; a network name and a house number.
The trick to understanding IP addresses is knowing how to group the numbers. In other words, in the above example, I’m telling you that 10.0.2 is the network that a host named .15 lives on.
But how does the computer know that? And heck, how did I know that? Did I just make it up?
What I’m about to tell you next is super important but before you can understand how to identify the network and host ID portions of an IP address you need to know how binary works.
Beefy Binary
I don’t know why I’m calling binary “beefy” – I mean that doesn’t even make sense haha. Actually, it’s kind of an inside joke between me and my wife. Whenever we do something really cool or dorkish we say “beefy” so I’m trying to say that binary is really cool in a dorky kind of way.
So here’s the deal: whenever you hear someone say “Binary” I want you to think of an old school flippy light switch.
The switch can either be on or off.
- On is one
- Off is zero
There are only two unique possibilities so we say binary is a base 2 numbering system.
Let’s say you just won the lottery and went to a Nissan dealership. You walk up to the dealer, point to the shiny showroom Nissan GTR Nismo and boldly say:
I’ll take it
Baffled, the dealer looks at you and retorts:
That’s a 2016 top of the line GTR. It costs $149,990
And you calmly reply with a smug smirk on your face
I know. I’m paying in cash…
Whoa that would feel so good. Okay, let me snap out of it.
So what does $149,990 mean?
It means one hundred and forty-nine thousand nine hundred and ninety dollars. But it only means that because it’s based on a base 10 numbering system.
Remembering Base 10
We have 10 fingers on our hands so a base 10 numbering system makes sense. So starting with your left pinky you can count:
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
Once you get to the last digit, the 9, you run out of fingers so how do we represent bigger numbers?
We just carry the one! So 9 becomes 10, 11, 12 and so on… and when we get to 99 we carry the one again another place to the left to get 100. This goes on forever – everyone knows how to count.
By the way, I’m not trying to insult you and I know this is super basic stuff but I don’t want to make any assumptions here!
So with 149,990 the zero is in the ones place so it’s worth 1. The next number (from right to left) is a 9 and it’s in the 10’s place so it’s worth 10. And this keeps going.
After the ones place, each place value is 10 times larger the value to its right. The one’s place is a 1. The tens place is a 10. The hundreds place is 10 times the tens place and the thousands place is 10 times the hundreds place. The ten thousands place is 10 times the thousands place and the hundred thousands place is 10 times the ten thousands place.
In other words, when we say 149,990 we’re really saying:
0 ones + 9 tens + 9 hundreds + 9 thousands + four ten thousands + 1 hundred thousand.
That’s how we get the price of your new Nissan GTR. Okay, I’m glad that’s over.
Checking out Base 2
Base 10 gives us zero through 9 so base 2 gives us 0 through 1.
In base 10, each number is 10 times the previous number and in base 2 each number is 2 times the previous number.
Base 10 gives us:
… 100,000, 10,000, 1,000, 100, 10 and 1
Base 2 gives us. I listed 8 position because computers only care about 8 positions:
… 128, 64, 32, 16, 8, 4, 2 1
So let’s look at the IP address again:
10.0.2.15
An IP address is said to be a dotted decimal address because it contains four numbers in base 10 separated by dots. But computers only understand binary so they convert the decimal numbers to binary.
We need to learn to think about numbers like computers.
How would you convert 10.0.2.15 into binary? Well let’s look at our little binary chart:
we have:
128, 64, 32, 16, 8, 4, 2 1
and we have
10.0.2.15
So we ask this question:
Can we squeeze the top number into the bottom number? Can we squeeze 128 into 10? If so write a 1 over the number and put the difference (the remainder) over the next number in the chart. Then we ask if the remainder can go into the bottom number again. We keep doing this writing down a 1 if it can squeeze in or a 0 (zero) if it can’t.
That sounds confusing I know so look at this example: can we squeeze 128 into 10?
No, so we write a zero over the 128 and move down to the next number.
- Can we squeeze 64 into 10? No, so we write down a zero move down to the next number.
- Can we squeeze a 32 into 10? Nope, so we put down a zero and keep going.
- Can we squeeze a 16 into 10? Nope, we write down another zero and look at the 8.
Can we squeeze 8 into 10? Yes! so we write down a 1 and put the remainder (10-8=2) over the next number. So now the 2 is our new number to squeeze into.
Think about a fat guy trying to squeeze into a size two dress lol,
Can we squeeze a 4 into 2? Nope write down a zero.
Can we squeeze a 2 into 2? Yes! so write down a 1. and put the remainder over the next (and last) number.
Can we squeeze 1 into 0? Nope, so write down a zero.
So now you have he binary number:
00001010
And that my friend is the decimal number 10 in binary.
Each zero or one is called a bit and eight bits is known as a byte.
So a standard IPv4 address is 4 bytes (32bits long).
The Bottom Line
I know it feels painful to do the conversion but I promise you if you do this 30 minutes a day for a week, you’ll be converting numbers to binary in your sleep. It gets really easy with practice because it’s so methodical.
Before we finish up I want you to convert the rest of this IP address to binary. Once you have that, convert your own IP address to binary. Then go out and find a random IP address on the web and convert it to binary.
That’s your homework. Just stick with it. I’m not kidding if you stick with this and do a few IP addresses it’ll start to get super easy. And don’t be afraid to bust out a pen and pad and write this out.
Write out the 128, 64, 32, 16, 8, 4, 2, 1 chart and do exactly what I did in the examples above.
You’ll need it because the next article in this series assumes you have zero issues converting decimal numbers to binary. I’ll see you soon!