Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
What is an IP Address?
An IP address is made of 4 octets, or 32 bits. It is represented in dotted decimal format such as
131.107.2.205. Each number represents an octet and an octet made up of 8 bits, so as we have 4
octets in an IP Address, there are 32 (8 x 4) bits in an IP Address.
Computers do not understand dotted decimal notation, as they only function in binary (ones and
zero’s). Therefore we must find a way to transfer an IP Address from dotted decimal format to
binary. We do this octet at a time…
w
When working with binary, each bit in the octet has an associated decimal value as shown below:
Bit 1 2 3 4 5 6 7 8
w
Bit 128 64 32 16 8 4 2 1
value
w
131:
yh
Bit 128 64 32 16 8 4 2 1
Value
Binary 1 0 0 0 0 0 1 1
ef
Columns with a “1” in binary mean that we count the corresponding bit value. If you add up all
the bit values marked with a one, you get 128+2+1 = 131.
fe
107:
Bit 128 64 32 16 8 4 2 1
r
Value
Binary 0 1 1 0 1 0 1 1
.c
Columns with a “1” in binary mean that we count the corresponding bit value. If you add up all
the bit values marked with a one, you get 64+32+8+2+1 = 107
om
2:
Bit 128 64 32 16 8 4 2 1
Value
Binary 0 0 0 0 0 0 1 0
Columns with a “1” in binary mean that we count the corresponding bit value. If you add up all
the bit values marked with a one, you get 2
Bit 128 64 32 16 8 4 2 1
Value
Binary 0 0 0 0 0 1 0 0
Finally, we get a 4!
Now we know that another way of writing our example IP address of 131.107.2.4 is:
10000011.01101011.00000010.00000100
w
IP Addresses are made of two distinct parts: the Network ID and the Host ID. When you try to
ping an IP address, IP (at Layer 3, see my OSI Guide for more info!) needs to determine whether
the target IP address is local or remote to your subnet (or network). To explain this, I like to ask
w
“Let’s say I live at number 8 East Street, and you say that you also live in East Street at number
.ra
57. That means we are neighbours right? Well, I live in a town called Worthing and you live in a
town called Chichester so, no we are not neighbours at all. In fact, in my street there is no house
or building with number 57! It only goes up to number 31.
yh
The same logic applies to IP addressing. Before I can find out what your Host ID (your street
address), I have to find out what your Network ID is (your town).
So how does the computer (or more specifically the IP protocol) know what the Host ID and
ef
Network ID’s are when it looks at an IP address? That is the role of the Subnet Mask!
fe
r .c
om
A Subnet Mask is used to enable IP (at Layer 3) to find out whether the target IP address you are
trying to contact is local or remote to your network. That is all it does, so it’s not very scary. It
helps you determine which part of an IP Address is the Network ID (town), and which is the Host
ID (street and house number). So how does it do that?
We have all seen a Subnet Mask before. It usually looks something like this:
255.255.255.0 (this is a Class C mask by the way. See the different classes in the next section!)
This subnet mask is obviously displayed in dotted decimal format. As we already know, computers
w
do not understand this format as they only understand binary. So let’s apply what we know about
binary to our subnet mask:
w
255
w
Bit 128 64 32 16 8 4 2 1
Value
Binary 1 1 1 1 1 1 1 1
.ra
Column with a “1” in binary mean that we count the corresponding bit value. If you add up all the
bit values marked with a one, you get 128+64+32+16+8+4+2+1 = 255. So, 255 is “all ones” as
you may have heard before.
yh
0:
Bit 128 64 32 16 8 4 2 1
ef
Value
Binary 0 0 0 0 0 0 0 0
fe
Column with a “1” in binary mean that we count the corresponding bit value. If you add up all the
bit values marked with a one, you get 0. So, 0 is “all zeros” as you may also have heard before.
r
In other words, our 255.255.255.0 subnet masks in binary looks like this:
.c
11111111.11111111.11111111.00000000
Note that a subnet mask is also a 32 bit, 4 octet structure that matches that of our IP address.
om
I highlighted the network part of the address in red and the host bits in blue. Notice anything? All
the network bits are the bits that had a value of “1” in the subnet mask, and all the host bits are
the bits that had a value of “0” in the subnet mask. Easy, so far! In our example the Network ID is
131.107.2, and the host ID is 4.
Okay, let’s change the subnet mask to 255.255.0.0, what happens now?
w
My network ID is now 131.107 and my host ID is 2.4! That is why an IP address on its own
cannot exist! That is why a host on a network needs at least an IP address AND a subnet mask!
.ra
Now, here’s a question for you. I’ve got two IP addresses of 131.107.2.4 and 131.107.5.6, are
they on the same subnet (network), or are they on different subnets? Well, you can’t answer that
unless I give you the subnet mask!
yh
Let’s say that the subnet mask for these two addresses is 255.255.255.0. Then we have:
Do the Network ID’s (in red) match? No they don’t! Look at the 3rd octet above and you’ll see
they are different. If the network ID’s do not match then the two IP addresses are on different
subnets, and you will need a router to go from one to the other. (Or in our example earlier, a
r
Let’s look at this example again with a different subnet mask of 255.255.0.0:
If the network IDs match, then the two IP addresses will be on the same network. You do not
need a router to go from one to the other in this scenario. (Or in our example earlier, you can
deliver the letter yourself and a postman in not necessary!)
To summarise then, we have seen how having an IP address without a subnet mask is not
sufficient, and how the same two IP addresses can be either remote or local to each other
depending on which subnet mask you are using. You’ve learnt the basics of IP addressing!
You may have heard of the different classes for IP addresses, namely, class A, B and C. How does
that work? Let’s look at the following table:
*127 is part of the class A range, but you cannot assign any 127.x.x.x IP addresses to hosts as
the entire range is reserved by InterNIC for the loopback address.
w
What does all this mean? When talking about a class of IP addresses, you only look at the first
octet to determine what class this IP address belongs to.
w
For class A, the InterNIC decided that the 1st octet would start with a bit value of 0xxxxxxx.
Therefore, the lowest binary of the 1st octet is 0000001, and the highest is 01111111 (in decimal,
w
For class B, InterNIC decided that the 1st octet would start with a binary value of 10xxxxxx.
.ra
Therefore, the lowest binary of the 1st octet is 1000000, and the highest is 10111111 (in decimal,
that would be from 128 to 191)
For class C, InterNIC decided that the 1st octet would start with a bit value of 110xxxxx.
yh
Therefore, the lowest binary of the 1st octet is 1100000, and the highest is 11011111 (in decimal,
that would be from 192 to 223)
There are other classes too, (D and E), but they are not used right now and are illegal on the
Internet. So we won’t worry about those as you’ll never come across them in day to day
ef
networking.
However, these classes of subnet mask aren’t restricted to those ranges of IP addresses. These
fe
Class A 255.0.0.0
r
Class B 255.255.0.0
.c
Class C 255.255.255.0
In other words, it is totally possible to have a Class B IP address and a class C subnet mask…
om
hang on… isn’t that what we have been taking as an example all along? Remember our
131.107.2.4 w/ a subnet mask of 255.255.255.0?
Subnetting is the action of taking an IP range where all IP addresses are local to each other and
dividing it into different ranges (or subnets), where IP addresses from one range will be remote
from any other IP addresses from any other range.
If you want to find out how many hosts you have in an IP range, first you need to determine how
many host bits there are. Let’s take our previous example of 131.107.2.4 and 255.255.255.0.
We already established previously that the Network ID was 131.107.2 and the Host ID was 4. In
other words, we have 3 octets for the Network ID and one octet – or 8 bits – for the Host ID.
Now that you have determined the amount of host bits you had, apply that number to the
following formula:
w
That means that in our example, we have the 131.107.2.x network, which contains 254 possible
w
What if I do not need that many (who does!?), and decided to divide that range in to several
other, more manageable ranges? Well, I need to subnet.
Note: we have to subtract 2 because we lose the “all ones” and “all zeros” values.
ef
If I only had 2 bits to play with in binary, I would have 2^2 = 4 possibilities:
fe
00
01
r
10
.c
11
om
However, “all zeros” in IP means the whole network, and “all ones” is the broadcast ID, neither
one being valid IP addresses that can be assigned to a host. That is why we always lose 2 and
have to subtract two from (2^N).
This table is the only table you need to learn to understand IP subnetting and IP addressing!
Three little lines! Let’s look at it line by line. The first line we are already acquainted with, so I will
not spend more time on it.
The second line tells you what your subnet mask will be. How do we get those results? If you
w
look at the bit value line, and add up the bit values, you will see that:
128+64 = 192
w
192+32 = 224
w
224+16 = 240
.ra
240+8 = 248
248+4 = 252
yh
252+2 = 254
254+1 = 255
ef
Easy!
Now to the third line. This one tells you how many subnets will get if you use the corresponding
fe
subnet mask. In other words: if you use the 192 in your subnet mask, you will get 2 subnets. If
you use 224, you will get 6 subnets, and so on. So how did I get those numbers? Well, let’s take
192 as an example. How many bits did I use to get 192? Well, I added 128 and 64, so that would
r
((2^2)-2) = 2
That is where the values in the third line come from. Want to check another one? Let’s look at
om
248. How many bits did I use to get to 248? 128+64+32+16+8=248, or a total of 5 bits.
((2^5)-2) = 30
“Ray, I have an IP range of 131.107.0.0 and a subnet mask of 255.255.0.0. I want 6 subnets out
of this and tell me right away or you’ll loose your job!!!!” What do I do now apart from panic!?
I look at my chart and I see that to get 6 subnets, all I need is a subnet mask of 224. I already
have an existing subnet of 255.255.0.0, which in binary looks like this:
11111111.11111111.00000000.00000000
I cannot “borrow” any more bits from the first 2 octets, as they are already network bits
w
represented by a binary value of 1. So the only I can add this “224” to my subnet mask is to
borrow from the host ID. I take the next available octet (the third in our example), and end up
with a subnet mask of 255.255.224.0, which looks like this in binary:
w
11111111.11111111.11100000.00000000
w
Note that we “borrowed” 3 host bits from the third octet and made them network bits. Note that 3
bits is all I need to make 224: 128 + 64 + 32 = 224.
.ra
Now that I have a subnet mask, I can tell that I have 13 host bits, meaning that I will have
((2^13)-2) = 8190 valid IP addresses per range! (I can’t stop worrying about my job now!)
yh
So I can go back to my boss and say “Boss, your new subnet mask for the 131.107.x.x network
will be 255.255.224.0, and you will have 6 subnets with 8190 IP addresses in each range.”
“Ray, what are those ranges?”, so I say “Bastard! I haven’t learnt that yet, hold on…” So it’s on
to the next section to discuss the ranges.
fe
r .c
om
Here is our subnetting chart again. In this section, we will learn how to derive the actual IP ranges
from the network address and subnet mask.
The first valid range will be 131.107.32.1 to 131.107.63.254. How the hell did I get that? I used
the above chart.
.ra
Once I determined that 224 was my subnet bit, I asked myself: what is the lowest bit value
needed to make 224?” The answer is: 32 ( 128 + 64 + 32 = 224, and 32 is the lowest of these
values.)
yh
Visually, it is easy to see that to have 6 subnets, I will use 224 as a subnet bit and will start my
first range at 32. I will then increment each range by that same value of 32. This is the cool bit!
ef
131.107.128.1 to 131.107.159.254
131.107.160.1 to 131.107.191.254
om
131.107.192.1 to 131.107.223.254
As you can see to get the next range, I simply incremented my original value by the same value
(look at the numbers in red). If you look at the values in blue you will see that they always are
the next red value minus 1. For example, if I look at the first range x.x.32.1 to x.x.63.254, I
looked at the next line’s red value, here 64, and subtracted 1 to get to 63. That is all there is to
it!
By the way, note that my last octet on the start of range is always 1 (it cannot be 0, or else my
host ID would be all 0’s), and that the last octet is always 254 in the last IP of each range (it
cannot be 255, or else it would be all 1’s), which we know is the broadcast ID, and is therefore
not available for hosts to have.
To get 14 subnets I need a subnet bit of 240, therefore my new subnet mask becomes
255.240.0.0. Note that my subnet bit is now the second octet, not the third as in the previous
example. This will have an importance when we create our ranges.
w
What is the smallest bit value needed to make 240? It’s 16, therefore I will start my ranges at 16
and will increment by that same value of 16.
w
My ranges are:
w
10.16.0.1 to 10.128.0.1 to
10.31.255.254 10.143.255.254
10.32.0.1 to 10.144.0.1 to
.ra
10.47.255.254 10.159.255.254
10.48.0.1 to 10.160.0.1 to
10.63.255.254 10.175.255.254
yh
10.64.0.1 to 10.176.0.1 to
10.79.255.254 10.191.255.254
10.80.0.1 to 10.192.0.1 to
10.95.255.254 10.207.255.254
ef
10.96.0.1 to 10.208.0.1 to
10.111.255.254 10.223.255.254
10.112.0.1 to 10.224.0.1 to
fe
10.127.255.254 10.239.255.254
r .c
om
To get 6 subnets I need a subnet bit of 224, therefore my new subnet mask becomes
255.255.255.224. Note that my subnet bit is now the 4th octet, not the third or second as in the
previous examples. This will have its importance when we create our ranges.
What is the smallest bit value needed to make 224? 32. Therefore I will start my ranges at 32
w
and will increment by that same value of 32. (Are you getting the hang of it by now?)
My ranges are:
w
192.168.2.33 to 192.168.2.129 to
w
192.168.2.62 192.168.2.158
192.168.2.65 to 192.168.2.161 to
192.168.2.94 192.168.2.190
.ra
192.168.2.97 to 192.168.2.193 to
192.168.2.126 192.168.2.222
yh
But you might have thought we were going to start at 32?! My first range is starting at 33! Well,
remember the other examples? We always started at .1, didn't we? Except that here, because we
are already subnetting at the fourth octet, we don't have room for a fifth to add the .1, so we
have to incorporate it in the last octet. So why can we not use 192.168.2.32 w/ a subnet mask of
ef
Looking at it in binary, it is obvious that the Host ID is all zeroes, which we know is not
r
possible...
.c
That’s all, and if you can learn this then you’re subnetting! Enjoy practicing, and good
luck if you have an exam!
om