IP Addressing and Subnet Masking

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 16

IP Addressing and Subnet Masking

IP addresses are 32 bits long and are represented as a quad octet set. Each octet represents 1
byte (8 bits) and has a range of 0-255 for 256 values ( 2 8 = 256 ). IP networks are divided into classes,
with each class having a network ID and host range. Each class uses bits from the first octet as part of
the network ID and depending on the network class can use up to two other octets for the network ID with
the remaining octets reserved for hosts on the network. For example, class A networks use the first octet
as the network range and the other three octets are for hosts on the networks and class C networks use
the first three octets from the left as the network ID, leaving only one octet available for hosts. The
Network classes are divided into classes as follows.

IP Address Classes
First Octet's First Octet's
Default Subnet
Class Range Binary Network Host
Mask
Decimal Range

Network.Host.Host.Host
00000000 -
A 0-126 Example 255.0.0.0
01111110
10.128.22.100

Network.Network.Host.Host
10000000 -
B 128-191 Example 255.255.0.0
10111111
172.12.15.65

Network.Network.Network.Host
11000000 -
C 192-223 Example 255.255.255.0
11011111
209.38.1.2

D 224-239 11100000 - D is for multicast


N/A
E 240-255 11111111 E is experimental

Some IP addresses are reserved for special use and are not to be used as networks.

Reserved IP Addresses
Address Use

127.0.0.1 Used for loopback

Used as default route on Cisco


0.0.0.0
Equipment

255.255.255.255 Broadcast to all nodes on network

IP Network addressing

• A network address uniquely identifies each network.


• Every machine on the network shares the same network portion of it's IP address.
• The node portion of the IP address uniquely identifies the node on its network, can also be called
host address.
Identifying the Parts of IP Network Addresses

This table has one example with the other fields left blank for your practice.

Address Class Network Portion Host Portion Default Subnet


63.125.22.14 A 63. 125.22.14 255.0.0.0

199.2.2.10

189.88.25.1

16.12.1.84

145.1.40.2

221.220.21.20

Process For Subnet masking

1. How many subnets?


2(masked bits) - 2 = Subnets

2. How many valid hosts per subnet?


2(unmasked bits) - 2 = Hosts

3. What are the valid subnets?


256-(subnet base)=Base number

4. What are the valid hosts in the subnets?


All numbers between subnets minus the all 1s (.255) and all 0s (.0) host addresses.

5. What is broadcast address of the subnet?


All the host bits turned on.

Example of subnet masking

(255.255.255.192) = (11111111.1111111.1111111.11000000)

1. (22)-2 = 2 Subnets

2. (26)-2 = 62 Hosts per subnet

3. 256 - 192 = 64 (.01000000) {For the first subnet}

4. 65 to 126 (.01000001 to .01111110) Valid hosts in the subnets

5. 127 (.01111111) Broadcast

Class A
Network Bits Subnet Mask Number of Subnets Number of Hosts

/8 255.0.0.0 0 16777214

/9 255.128.0.0 2 (0) 8388606

/10 255.192.0.0 4 (2) 4194302

/11 255.224.0.0 8 (6) 2097150

/12 255.240.0.0 16 (14) 1048574

/13 255.248.0.0 32 (30) 524286

/14 255.252.0.0 64 (62) 262142

/15 255.254.0.0 128 (126) 131070

/16 255.255.0.0 256 (254) 65534

/17 255.255.128.0 512 (510) 32766

/18 255.255.192.0 1024 (1022) 16382

/19 255.255.224.0 2048 (2046) 8190

/20 255.255.240.0 4096 (4094) 4094

/21 255.255.248.0 8192 (8190) 2046

/22 255.255.252.0 16384 (16382) 1022

/23 255.255.254.0 32768 (32766) 510

/24 255.255.255.0 65536 (65534) 254

/25 255.255.255.128 131072 (131070) 126

/26 255.255.255.192 262144 (262142) 62

/27 255.255.255.224 524288 (524286) 30

/28 255.255.255.240 1048576 (1048574) 14

/29 255.255.255.248 2097152 (2097150) 6

/30 255.255.255.252 4194304 (4194302) 2

Class B

Network Bits Subnet Mask Number of Subnets Number of Hosts


/16 255.255.0.0 0 65534

/17 255.255.128.0 2 (0) 32766

/18 255.255.192.0 4 (2) 16382

/19 255.255.224.0 8 (6) 8190

/20 255.255.240.0 16 (14) 4094

/21 255.255.248.0 32 (30) 2046

/22 255.255.252.0 64 (62) 1022

/23 255.255.254.0 128 (126) 510

/24 255.255.255.0 256 (254) 254

/25 255.255.255.128 512 (510) 126

/26 255.255.255.192 1024 (1022) 62

/27 255.255.255.224 2048 (2046) 30

/28 255.255.255.240 4096 (4094) 14

/29 255.255.255.248 8192 (8190) 6

/30 255.255.255.252 16384 (16382) 2

Class C

Network Bits Subnet Mask Number of Subnets Number of Hosts

/24 255.255.255.0 0 254

/25 255.255.255.128 2 (0) 126

/26 255.255.255.192 4 (2) 62

/27 255.255.255.224 8 (6) 30

/28 255.255.255.240 16 (14) 14

/29 255.255.255.248 32 (30) 6

/30 255.255.255.252 64 (62) 2

Supernetting (CIDR) Chart


• CIDR - Classless Inter-Domain Routing.
• Note: The Number of Class C networks must
be contiguous.
For example, 192.169.1.0/22 represents the
following block of addresses:
192.169.1.0, 192.169.2.0, 192.169.3.0 and
192.169.4.0.

Class C

Number of Class C
CIDR Block Supernet Mask Number of Hosts
Addresses

/14 255.252.0.0 1024 262144

/15 255.254.0.0 512 131072

/16 255.255.0.0 256 65536

/17 255.255.128.0 128 32768

/18 255.255.192.0 64 16384

/19 255.255.224.0 32 8192

/20 255.255.240.0 16 4096

/21 255.255.248.0 8 2048

/22 255.255.252.0 4 1024

/23 255.255.254.0 2 512

The first thing you must know is that the common number system used world wide
is the decimal system (otherwise known as base 10). What makes the decimal
system a base 10 system is that it is based on grouping numbers by 10's. It is
believed that the system evolved because we have ten fingers and ten toes which
over the years we have used for counting. I use mine all the time (grin). We name
the ten digits: zero, one, two, three, four, five, six, seven, eight and nine.

The decimal system has a 1's place, a 10's place, a 100's place, a 1000's place
and so on. We say the number places are grouped by 10's because multiplying
each number place by 10 gives you the next number place. So: 1x10=10
(the 10's place), 10x10=100 (the 100's place), 100x10=1000 (the 1000's place)
etc.
Let's look at the decimal number 103 by place.

103 <- read from right to left

We have a 3 in the 1's place


We have a 0in the 10's place
We have a 1 in the 100's place

Thus: 100+0+3=103

By now you probably feel like you have attended Kindergarten for the second time
in your life? Sorry about that but it is very important that you understand the
concept of what a number system is, and what it is based on before we look at
binary.
[Understanding binary - base 2]

Binary is a base 2 system, and thus groups numbers by 2's and not by 10's like the
decimal system. We name the two digits: zero and one. The binary system has a
1's place, a 2's place, a 4's place, an 8's place, a 16's place and so on. We say the
number places are grouped by 2's because multiplying each number place by 2
gives you the next number place. So: 1x2=2 (the 2's place), 2x2=4 (the 4's
place), 4x2=8 (the 8's place), 8x2=16 (the 16's place) etc.

Let's look at the decimal number Let's look at the decimal number 103 in binary
format:

01100111 <- read from right to left

We have a 1 in the 1's place


We have a 1 in the 2's place
We have a 1 in the 4's place
We have a 0 in the 8's place
We have a 0 in the 16's place
We have a 1 in the 32's place
We have a 1 in the 64's place
We have a 0 in the 128's place

Thus: 0+64+32+0+0+4+2+1=103
Okay, Let's test your skills. Here is a list of binary numbers, try converting them to
decimal and check your answers at the end of this post.
10000000
11000000
11100000
01000000
10000011
10010001
11111111

If you were able to convert these numbers to decimal then congratulations! You're
ready to move on to the next section.

[Understanding a subnet mask]

Now that you understand what binary is, let's have a look at our two subnet masks
from the beginning of my post:

192.168.1.0 / 255.255.255.0
192.168.1.0/24

The concept of a subnet mask is simple. You have a network and you have hosts on
the network (anything with an IP address is a host). The subnet mask
determines what portion of the TCP/IP address represents your network
and what portion can be used for your hosts. Because I am a simple person, I
think of it like this; The network number represents the street I live on, and the
host portion is used for the numbers on all the houses on my street.

A subnet mask of 255.255.255.0 means that the first three octets of the address
will be used for the network, and thus our network number is 192.168.1. This
means we can have 254 computers on this network, because the fourth octet is not
being used by the network portion of the address. We know this because of the 0 in
the subnet mask (255.255.255.0).

We call each of the number sections an octet because we think of them in binary,
and there are eight possible bits in each section. Eight bits is an octet. 11111111
in binary is 255 in decimal (did you do the conversions?). So our decimal subnet
mask 255.255.255.0 displayed in binary is going to be:

11111111.11111111.11111111.00000000

If you count all the ones, you will find that there are 24 of them. Now look at the
subnet mask examples again.
192.168.1.0/255.255.255.0
192.168.1.0/24

Do you see why both subnet masks are the same? The number 24 is the number of
bits used in the network portion of the address, and is short-hand for writing the
address/subnet mask combination. It becomes important to understand this when
you start dividing your network into multiple sub networks.

[Understanding Subnetting]

Before reading this section, you should have a good understanding of what a
subnet mask is and how binary bits represent the subnet mask.

Simply put, subnetting is dividing your network into multiple sub networks. To
go back to my silly example about houses and streets, subnetting gives you
multiple streets in your neighborhood.

There are two methods for dividing your network into multiple sub networks; One is
to simply change your network numbers keeping the same subnet mask. The other
is to subnet your network into smaller sub networks.

Keeping the same mask:


Your network could be divided into two or more networks by changing the network
portion of the address such as 192.168.1 and 192.168.2 and keeping the same
subnet mask.

Example:
192.168.1.0/255.255.255.0
192.168.2.0/255.255.255.0

Doing this would give you two separate networks with 254 hosts per network.
This is a very common method of dealing with multiple networks. However, back in
the good old days you had to pay for every IP address you used, and if you had 25
computers on your network you probably would not want to pay for 254 addresses!
The answer to the problem is...subnetting.

Subnetting a network:
Subnetting is when you use bits from the host portion of your address as
part of your network number. This let's you subdivide your network at the cost
of host addresses, which is great if you're paying for every host IP address. It will
save you money because you pay for fewer TCP/IP addresses. Confused? Here is
where understanding binary is important.
Lets look at a new subnet mask:
255.255.255.224

As you can see in the fourth octet, some of the host portion of this subnet mask is
now being used for part of the network address. Which means we are now using
some of the binary bits in the fourth octet for our network numbers, and
that gives us fewer hosts than our old mask (which gave us 254), but gives us
more networks (which is why we call it subnetting).

How can we tell how many networks and hosts per network this new subnet mask
will give us? Well... we shall have to use some of our newly acquired binary skills.

The first task is to find out how many bits in the fourth octet are being used?
The decimal number is 224, what is the decimal number 224 as represented in
binary?

The decimal number 224 in binary is:


11100000

We have a 0 in the 1's place


We have a 0 in the 2's place
We have a 0 in the 4's place
We have a 0 in the 8's place
We have a 0 in the 16's place
We have a 1 in the 32's place
We have a 1 in the 64's place
We have a 1 in the 128's place

Thus: 128+64+32+0+0+0+0+0=224

So our complete subnet mask in binary is:


1111111.11111111.11111111.11100000

We now know that three bits from the fourth octet are used. How can we tell how
many sub networks we're going to have? This requires some math- sorry. The
formula is: 2n-2, where n is the number of bits being used from the host portion of
our subnet mask.

Note: We subtract 2 from the total because you do not count all 0's or all 1's.

The formula for three bits is:


23-2=6

In simpler terms:
(2x2x2)-2=6

So our network is sub divided into 6 networks. Next, we want to know what the
network numbers are, and how many hosts we can have on each of the 6
networks?

What is the first subnet? Let's have a look at the bits in our fourth octet again. The
bit that gives us the answer is the (1) closest to the first zero, and in this case it is
the 3rd bit from the left.

11100000

The 3rd bit will start our first network, and the 3rd bit is in the 32's place
(remember binary). Start adding the value 32 to itself six times to get the six
network numbers.

Note: A quicker way to find our starting network number is to subtract our mask
from 256.
256-224=32

Here are our network numbers:

32
64
96
128
160
192

A better way to display this is:

192.168.1.32
192.168.1.64
192.168.1.96
192.168.1.128
192.168.1.160
192.168.1.192

The host addresses will fall between the network numbers, so we will have 30 hosts
per network. You're probably wondering why it's not 31? The answer is that the
last address of each subnet is used as the broadcast address for that subnet.

Example:
Subnet:192.168.1.32 / 255.255.255.224
Address Range: 192.168.1.33 through 192.168.1.62 (30 hosts)
Subnet Broadcast Address:192.168.1.63

Quiz:
Let's test your skills- write the address range and broadcast address for the
following subnet. You will find the answer at the end of this post.

Subnet: 192.168.1.128 / 255.255.255.224


Address Range?
Subnet Broadcast Address?

If we we're paying for our TCP/IP addresses, we would only pay for one network
and host combination, thus paying for 30 hosts and not 254. It could mean some
real savings, it also frees up the remaining addresses for other organizations to
use.

Let's look at another subnet mask:


255.255.255.240

How many bits are used from the host portion? To find this out, we need to know
how the decimal number 240 is represented in binary.

The answer is:


11110000

So four bits are taken from the host portion of our mask. We do the same math as
before:

24-2=14

In simpler terms:
(2x2x2x2)-2=14

We will have 14 sub networks, and what will the network numbers be? Look at
the fourth bit, it's in the 16's place:
11110000
Note: A quicker way to find our starting network number is to subtract the value of
our mask from 256. So: 256-240=16

Start adding 16 to itself- fourteen times to get all 14 network numbers:

16,32,48,64,80,96,112,128,144.160,176,192,208,224

A better way to display our subnets is:

192.168.1.16
192.168.1.32
192.168.1.48
192.168.1.64
192.168.1.80
192.168.1.96
192.168.1.112
192.168.1.128
192.168.1.144
192.168.1.160
192.168.1.176
192.168.1.192
192.168.1.208
192.168.1.224

The host addresses fall between the network numbers. So we will have 14 host
addresses on each of our 14 sub networks (remember: the last or 15th address is
the broadcast address for that subnet).

If you had a small company with 10 hosts and needed to have a static IP address
for all of your hosts, you would be assigned a network/subnet mask and a valid IP
address range.

Here is an example of what that might look like:

Network: 205.112.10.16/.255.255.255.240
Address Range: 205.112.10.17 through 205.112.10.30
Subnet Broadcast Address: 205.112.10.31

[Answers to Binary Conversions]

10000000 = 128
11000000 = 192
11100000 = 224
01000000 = 64
10000011 = 131
10010001 = 145
11111111 = 255

[Answer to Subnet Question]

Subnet:192.168.1.128 / 255.255.255.224
Address Range: 192.168.1.129 through 192.168.1.158
Subnet Broadcast Address: 192.168.1.159

Subnet Masks and Subnets:

notation resulting subnet


netmask shorthand number of addresses
255.255.255.0 /24 [8-bit] 28 = 256 = 254 hosts + 1 bcast + 1 net base
255.255.255.128 /25 [7-bit] 27 = 128 = 126 hosts + 1 bcast + 1 net base
255.255.255.192 /26 [6-bit] 26 = 64 = 62 hosts + 1 bcast + 1 net base
5
255.255.255.224 /27 [5-bit] 2 = 32 = 30 hosts + 1 bcast + 1 net base
255.255.255.240 /28 [4-bit] 24 = 16 = 14 hosts + 1 bcast + 1 net base
255.255.255.248 /29 [3-bit] 23 = 8 = 6 hosts + 1 bcast + 1 net base
255.255.255.252 /30 [2-bit] 22 = 4 = 2 hosts + 1 bcast + 1 net base
255.255.255.254 /31 [1-bit] 21 = - invalid (no possible hosts)
0
255.255.255.255 /32 [0-bit] 2 = 1 a host route (odd duck case)

Some Quick Notes:


An IP number has four 8-bit octets. Since each binary bit has two possible values, either
on or off (0 or 1), each octet can represent 28 = 256 decimal numbers (0..255). If we
count up all 32 bits (4x8=32), we have an Internet of 256x256x256x256 = 2 32 =
4,294,967,296 possible addresses. That's too many for any one network; this number is
segmented into more manageable chunks, or subnets, via routing. The network base
address and subnet mask determines what portion of the 32-bit Internet belongs to a
given subnet.
A network interface (NIC) should not waste its processing power looking at any and all
IP traffic. We want each NIC to ignore anything not meant for itself. A subnet mask
provides a way to quickly and efficiently filter out anything not meant for our subnet.
NICs on hosts, routers, etc., use a combination of network "base" address and "mask"
to determine what to ignore and what to listen to.

The netmask shorthand notation (the /##'s) just specifies how many 1's to _keep_ to
determine the _network_ address of an interface. Each octet has eight 1's. With no
masking, that's "11111111.11111111.11111111.11111111". The netmask would be
0.0.0.0 or just /0, meaning look at all the ones in all the octets -- the entire Internet.
Again, we generally do not want a NIC to listen for the entire Internet.

The netmask is called a "mask" because it also tells how many 1's on the left-hand side
to mask-out when figuring out a specific _host_ address.

For a "Class C" or "8-bit" subnet (32-24=8), the network interfaces only care about the
last octet. So we use 255.255.255.0, or its shorthand equivalent, /24.

For a Class B or "16-bit" subnet (32-16=16), we need the details of the last two octets.
So we use 255.255.0.0, or /16.

A Question to See if You're Awake:


Question: How many 9-bit subnets can fit into a 13-bit subnet?

Answer:

213
-- =
213 - 9 = 24 = 16
29

A Non "8-bit" Example:


207.199.153.192/27 is a "5-bit" subnet (32-27=5). There are 32 IP's in the subnet. The
"base" address or first IP of the range is simply 207.199.153.192, and is unusable as a
host address. The 30 Usable IPs are 207.199.153.193..207.199.153.223. The last one,
207.199.153.224, is the broadcast address for the subnet. Similar to the network base
address, the broadcast address is not usable as a host address.
General Network Architecture:
The internal subnetting uses the private "Class B" network, 172.16.0.0/16, divvied up as
follows:

network/mask usable IP address range bcast address location


172.16.1.0/24 172.16.1.1..172.16.1.254 172.16.1.255 Chantilly
172.16.2.0/25 172.16.2.1..172.16.2.126 172.16.2.127 Leesburg
172.16.3.0/25 172.16.3.1..172.16.3.126 172.16.3.127 Alexandria
172.16.4.0/24 172.16.4.1..172.16.4.254 172.16.4.255 Winchester
172.16.5.0/24 172.16.5.1..172.16.5.254 172.16.5.255 Arlington
172.16.6.0/24 172.16.6.1..172.16.6.254 172.16.6.255 Washington

With a Class B of 65+ thousand host addresses (256x256) to burn up, efficiency isn't
often much of an issue for a "private" subnet. However, note that the 7-bit (32-25=7)
subnets 172.16.2.128/25 and 172.16.3.128/25 are going unused. Sticking to "plain jane"
8-bit ("Class C") subnetting would simplify life. On the private network, we'd have 254
possible 8-bit subnets.

Network Base Address and Broadcast Address:


The network base address is the first IP address in a given subnet; the broadcast
address is the last. There's nothing "special" about these first and last numbers in the
math; it's just the engineering specification that defines them to these functions. All NICs
have to listen for traffic directed at their specific IP address(es) and the broadcast
address for their subnet. The base network address is all 0's for the hostid and refers to
the subnet itself; the broadcast address is all 1's and refers to all hosts on the subnet.

32-bit Octal to Dotted Quad Decimal Conversion:


Computers love octal math because they're essentially binary in nature (they like a
switch to be either OFF/0 or ON/1) the same way humans like base ten (because we
count on our fingers). Our base ten tendencies cause our eyes to glaze over when
presented with octal numbers. Still, some understanding of the octal number system
helps us comprehend IP networking a bit more clearly.

The eight "places" in 11111111 equate to 128 64 32 16 8 4 2 1.

So, the following numbers are equivalent:


10000000.00001010.00000010.00011110 32-bit Octal
128.10.2.30 Dotted Quad Decimal
Octal Decimal (128.10.2.30)
- 128 64 32 16 8 4 2 1 ttl
10000000 128 + 0 + 0 + 0 + 0 + 0 + 0 + 0 = 128
00001010 0+ 0+ 0+ 0+ 8+ 0+ 2+ 0= 10
00000010 0+ 0+ 0+ 0+ 0+ 0+ 2+ 0= 2
00011110 0+ 0 + 0 + 16 + 8 + 4 + 2 + 0 = 30

The reverse is a little bit like long division. For each octet, just keep grabbing the biggest
power of two in whatever's left till we get to 0.

11001111.11000111.10011001.11000010 32-bit Octal


207.199.153.194 Dotted Quad Decimal
Decimal (207.199.153.194) Octal
- 128 64 32 16 8 4 2 1-
207 = 128 + 64 + 0 + 0 + 8 + 4 + 2 + 1 11001111
199 = 128 + 64 + 0 + 0 + 0 + 4 + 2 + 1 11000111
153 = 128 + 0 + 0 + 16 + 8 + 0 + 0 + 1 10011001
194 = 128 + 64 + 0 + 0 + 0 + 0 + 2 + 0 11000010

You might also like