You are on page 1of 95

IP Addressing

CONTENTS
INTRODUCTION
CLASSFUL ADDRESSING
SAMPLE INTERNET WITH
CLASSFUL ADDRESSES

INTRODUCTION

Introduction
In addition to the physical addresses (contained on
Network Interface Card) that identify individual
devices, the Internet requires an addressing
convention.
An address that identifies the connection of a host
to its network is known as Internet address or IP
address.
An IP address is a 32-bit address that uniquely and
universally defines the connection of a host to the
Internet.

Introduction
IP addresses are unique as each address defines
one and only one connection to the Internet.
Two devices on the Internet can never have the
same IP address.
If a device has two connections to the Internet, via
two networks, it has two IP addresses.
The IP addresses are universal as the addressing
system must be accepted by any host that wants to
be connected to the Internet.

Address Space
An address space is the total number of addresses
used by the protocol.
If a protocol uses N bits to define an address, the
address space is 2N because each bit can have two
different values (0 and 1)and N bits can have 2N
values.
Current IP version IPV4 uses 32bit address. So the
address space of IPv4 is 2^32 or 4,294,967,296.

Notation
There are 3 common notations to show an IP
address: binary notation, dotted-decimal
notation, and hexadecimal notation.
Binary notation: displayed as 32 bits. One or
more space is inserted between each octet (8 bits).
Example : 01110101 10010101 00011101
11101010
Dotted-decimal notation: IP addresses are written
in decimal form with decimal points separating
the bytes. As each byte having 8 bits, so each
number in this notation is between 0 to 255.
Example:

Notation

addr1

..

..

Hexadecimal notation: each hexadecimal digit is


equivalent to four bits.
0111 0101 1001 0101 0001 1101 1110 1010
75
95
1D
EA
0X75951DEA or 75951DEA16
0X is added at the beginning or the subscript 16 to
show that the number is in hexadecimal.

Example 1

Change the following IP address from binary


notation to dotted-decimal notation.
10000001 00001011 00001011 11101111
Solution

129.11.11.239

Example 2

Change the following IP address from


dotted-decimal notation to binary notation.
111.56.45.78
Solution

01101111 00111000 00101101 01001110

Example 3

Find the error, if any, in the following IP


address:
111.56.045.78
Solution

There are no leading zeroes in


dotted-decimal notation (045).

Example 3 (continued)

Find the error, if any, in the following IP


address:
75.45.301.14
Solution

In dotted-decimal notation,
each number is less than or
equal to 255; 301 is outside this range.

Example 4

Change the following IP addresses from


binary notation to hexadecimal notation.
10000001 00001011 00001011 11101111
Solution

0X810B0BEF or 810B0BEF16

CLASSFUL
ADDRESSING

Occupation of the address space


The IP address space is divided into five classes:
A,B,C,D and E. each part occupies some part of
the whole address space.
Each IP address consists of 32 bits (4 bytes),
defines 3 fields : class type, network id and host
id. These parts are of varying lengths, depending
on the class of the address.

Occupation of the address space

From the fig. above we can see that Class A


covers half of the address space, class B , class
C 1/8, class D an E 1/16 of the whole address
space.

Addresses per class

Addresses per class


Class

Number of Addresses

Percentage

2^31=2,147,483,648

50%

2^30=1,073,741,824

25%

2^29=536,870,912

12.5%

2^28=268,435,456

6.25%

2^28=268,435,456

6.25%

Finding the address class

Example 5

How can we prove that we


2,147,483,648 addresses in class A?

have

Solution

In class A, only 1 bit defines the class.


The remaining 31 bits are available
for the address. With 31 bits,
we can have 231 or 2,147,483,648 addresses.

Example 6

Find the class of the address:


00000001 00001011 00001011 11101111

Solution

The first bit is 0. This is a class A address.

Example 6 (Continued)

Find the class of the address:


11000001 10000011 00011011 11111111

Solution

The first 2 bits are 1; the third bit is 0.


This is a class C address.

Finding the class in decimal notation

Class

From

To

Class A

0.0.0.0

127.255.255.255

Class B

128.255.255.255

191.255.255.255

Class C

192.255.255.255

223.255.255.255

Class D

224.255.255.255

239.255.255.255

Example 7

Find the class of the address:


227.12.14.87

Solution

The first byte is 227 (between 224 and 239);


the class is D.

Example 7 (Continued)

Find the class of the address:


193.14.56.22

Solution

The first byte is 193 (between 192 and 223);


the class is C.

Netid and hostid


Network id: Identifies the particular network to
which a host machine belongs.
Host id: Identifies the actual host within that
network.

Blocks in class A
Class A is divided into 128 blocks, each having a
different netid. The first block covers addresses
from 0.0.0.0 to 0.255.255.255 (netid 0).
First byte (netid) is same but last 3 bytes (host id)
can take any value of a given range.
First and last block are reserved for special
purposes and block for netid 10 is used for private
addresses.

Blocks in class A

Millions of
class A
addresses
are wasted.

Blocks in class B
Class B is divided into 16,384 (64*256) blocks,
each having a different netid. The first block
covers
addresses
from
128.0.0.0
to
128.255.255.255 (netid 128.0).
First 2 bytes (netid) is same but last 2 bytes (host
id) can take any value of a given range.
16 Blocks are reserved for private addresses,
leaving 16,368 blocks for assignments to
organizations.

Blocks in class B

Many class B
addresses
are wasted.

Blocks in class C
Class C is divided into 2,097,152(32*256*256)
blocks, each having a different netid. The first
block covers addresses from 192.0.0.0 to
192.255.255.255 (netid 192.0.0).
First 3 bytes (netid) is same but last 1 bytes (host
id) can take any value of a given range.
256 Blocks are reserved for private addresses,
leaving 2,096,896 blocks for assignments to
organizations.

Blocks in class C

The number of addresses in


a class C block is smaller than
the needs of most organizations.

Class D
Class D is having only one block. It is designed
for multicasting.
Each address in this class is used to define one
group of hosts on the internet.
When a group is assigned an address in this class,
every host that is a member of this group will
have a multicast address in addition to its normal
(unicast) address.

Class E

Class E is having only one block. It is reserved for


future purposes.
Most of the block is wasted.

Reserved, Loopback and Private Addresses


Portions of the IP address space are set aside for
reserved, private and loopback addresses.
Several blocks of addresses were designated just
as reserved with no specific indication given of
what they were reserved for. They may have been
set aside for future experimentation, or for internal
use in managing the Internet, or for other
purposes.
There are some reserved blocks in each class A, B
and C which appears at the beginning and end of
each class.

Reserved, Loopback and Private Addresses


A loopback address is an address that tells the
computer not to test its connections to another
computer, but to test its own basic network setup.
The range of loopback address is from 127.0.0.1 to
127.255.255.255.
Private address blocks were created to allow private
IP internets to be created using addresses that were
guaranteed not to conflict with public IP addresses.
They are commonly used in internetworks not
connected to the global Internet; devices using them
can also access the global Internet by using Network
Address Translation(NAT).

Network Addresses
The network address is the first address.
The network address defines the network to the rest
of the Internet.
Given the network address, we can find the class of
the address, the block, and the range of the
addresses in the block.
In classful addressing, the network address (the
first address in the block)is the one that is assigned
to the organization.

Example 9

Given the network address 17.0.0.0, find the


class, the block, and the range of the
addresses.
Solution

The class is A because the first byte is between


0 and 127. The block has a netid of 17.
The addresses range from 17.0.0.0 to
17.255.255.255.

Example 10

Given the network address 132.21.0.0, find


the class, the block, and the range of the
addresses.
Solution

The class is B because the first byte is between


128 and 191. The block has a netid of
132.21. The addresses range from
132.21.0.0 to 132.21.255.255.

Example 11

Given the network address 220.34.76.0, find


the class, the block, and the range of the
addresses.
Solution

The class is C because the first byte is between


192 and 223. The block has a netid of 220.34.76.
The addresses range from 220.34.76.0
to 220.34.76.255.

Mask
A mask is a 32-bit binary number that gives the first
address in the block (the network address) when
bitwise ANDed with an address in the block.

AND operation
Masking uses the bitwise AND operation defined in
computer science. The operation is applied bit by bit
to the address and the mask.
AND operation does the following:
If the bit in the mask is 1, the corresponding bit in
the address is retained in the output (no change).
If the bit in the mask is 0, a 0 bit in the output is
the result.
In other words, the bits in the address corresponding
to the 1s in the mask are preserved (remain 0 or 1, as
they were) and the bits corresponding to the 0s in the
mask change to 0.

AND operation

Default Mask
Class

Mask in Binary

Mask in dotted -decimal

11111111 00000000 00000000


00000000

255.0.0.0

11111111 11111111 00000000 00000000

255.255.0.0

11111111 11111111 11111111 00000000

255.255.255.0

Default Mask
The network address is the beginning address of
each block. It can be found by applying the default
mask to any of the addresses in the block (including
itself). It retains the netid of the block and sets the
hostid to zero.
We must not apply the default mask of one class to
an address belonging to another class.
Note that the number of 1s in each class matches the
number of bits in the netid and the number of 0s
matches the number of bits in the hostid.

Example 12

Given the address 23.56.7.91 and the default


class A mask, find the beginning address
(network address).
Solution

The default mask is 255.0.0.0, which means


that only the first byte is preserved
and the other 3 bytes are set to 0s.
The network address is 23.0.0.0.

Example 13

Given the address 132.6.17.85 and the


default class B mask, find the beginning
address (network address).
Solution

The default mask is 255.255.0.0, which means


that the first 2 bytes are preserved
and the other 2 bytes are set to 0s.
The network address is 132.6.0.0.

Example 14

Given the address 201.180.56.5 and the class


C default mask, find the beginning address
(network address).
Solution

The default mask is 255.255.255.0,


which means that the first 3 bytes are
preserved and the last byte is set to 0.
The network address is 201.180.56.0.

CIDR Notation
In classful addressing each address has a default
mask, it is sometimes convenient to explicitly
indicate the default mask. Classless Interdomain
routing(CIDR) notation is used for this purpose.
In this notation, the number of 1s in the mask is
added after a slash at the end of the address.
For example, the address 18.46.74.10 is a class A
address with a default mask 255.0.0.0, is written as
18.46.74.10/8 to show that there are 8 1s in the
mask.
This is useful in classless addressing.

Sample Internet with classful addresses

Subnetting/Supernetting
and
Classless Addressing

CONTENTS
SUBNETTING
SUPERNETTING
CLASSLESS ADDRSSING

SUBNETTING

Two Levels of Hierarchy


Each 32 bit long IP address is having a portion which
indicates a network (netid) and the remaining portion
indicates the host (or router) on the network (hostid).
So to reach any host, first the network have to be
reached using the netid portion and then to the host
using hostid portion. So classes A,B and C in IP
addressing are designed with these two levels of
hierarchy.
But sometimes this two levels of hierarchy are not
enough.
Fig. shows a company with class B addresses and uses
two levels of hierarchy.

Two Levels of Hierarchy


141.14.2.21

141.14.2.105

141.14.2.20
141.14.7.96
To the
rest of
the
Internet

R1
Router

141.14.0.0
141.14.7.95

141.14.22.64
141.14.22.9

141.14.7.44

A network without subnetting

Two Levels of Hierarchy


With this scheme, all of the host are at the same level
and the network has many hosts.
This type of large network is very much complex to
be implemented as a single un routed networks.
So to manage the address space efficiently it is
necessary to allocate the available addresses to
multiple smaller network.
Further division of a network into smaller networks
are called sub networks or subnet.
So the example network is divided into 3 subnets.

A Subnetted Network
141.14.2.21
141.14.2.20

141.14.2.105
141.14.2.0
141.14.7.96

To the
rest of
the
Intern
et

Router
R1

141.14.7.0
141.14.22.0

141.14.7.95
141.14.7.44

141.14.22.64
141.14.22.9

Three Levels of Hierarchy


In this example the rest of the Internet is not aware
that the network is divided into three physical
subnetworks: the three subnets still appear as a
single network to the rest of the internet.
If a packet destined for 141.14. 2.21 still reaches
router R1. when the packet arrives at R1, the router
knows that the network 141.14.0.0 is physically
divided into 3 subnets and it also knows that the last
two octets define two things: subnetid(2) and
hostid(21).

Three Levels of Hierarchy


Adding subnets creates an intermediate level of
hierarchy.
The 3 levels are: netid, subnetid and hostid, where
the netid defines the main network, subnetid defines
the physical subnetwork and hostid defines the
connection of the host to the subnet.

Three Levels of Hierarchy

Subnet Mask
Subnet masks are used when the network is subnetted.
It is used to find the sub-network address.
A custom subnet mask is specified for all hosts in the
same subnet.

Subnet Mask

Finding Subnet Mask


We can find the custom subnet masks by using a
simple method.
At first we need to determine the number of subnets
required. Whatever be the required number of
subnet, the number must be power of 2.
Let us consider a class C address 201.70.64.0 . The
default subnet mask is 255.255.255.0. Assume that 6
subnets have to be created from this address. But 6 is
not power of 2. The next number that is power of 2 is
8(2^3). Consider the value of the power which is 3 in
this case.

Finding Subnet Mask


Next convert the higher bits of the first octet of the
host portion in the default subnet mask based on the
value of power in the previous step.
The first octet of the host portion becomes
11100000. so the custom subnet mask is
255.255.255.224 that is 11111111 11111111
11111111 11100000.

Solution (Continued)
The custom subnet mask is 11111111 11111111 11111111
11100000 or 255.255.255.224
The number of subnets is 8.
The number of addresses in each subnet is 25 (5 is the
number of 0s) or 32.

Solution (Continued)

Finding Subnet Address


Given an IP address, we can find the subnet address the
same way we found the network address in the
previous chapter. We apply the mask to the address. We
can do this in two ways: straight or short-cut.
Straight Method
In the straight method, we use binary notation for both
the address and the mask and then apply the AND
operation to find the subnet address.

Finding Subnet Address


Short-Cut Method
* If the byte in the mask is 255, copy the byte in the
address.
* If the byte in the mask is 0, replace the byte in the
address with 0.
* If the byte in the mask is neither 255 nor 0, we write the
mask and the address in binary and apply the AND
operation.

Example 15
What is the subnetwork address if the destination address
is 200.45.34.56 and the subnet mask is 255.255.240.0?
Solution
11001000 00101101 00100010 00111000
11111111 11111111 11110000 00000000
11001000 00101101 00100000 00000000
The subnetwork address is 200.45.32.0.

Example 16
What is the subnetwork address if the destination address is
19.30.80.5 and the mask is 255.255.192.0?

Solution

SUPERNETTING

Supernetting
The size of a class C block with a maximum number
of 256 addresses may not satisfy the needs of an
organization.
In supernetting, an organization can combine several
class C blocks to create a larger range of addresses.
In other words several networks are combined to
create a supernetwork.
For example, an organization that needs 1000
addresses can be granted 4 class C blocks.

Supernetting

Supernet Mask
In subnetting, we need the first address of the subnet
and the subnet mask to define the range of addresses.
In supernetting, we need the first address of the
supernet and the supernet mask to
define the range of addresses.
A supernet mask is the reverse of a subnet mask. A
subnet mask for class C has more 1s than default
mask for this class. A supernet mask for class C has
less 1s than default mask for this class.

Comparison of subnet, default,


and supernet masks

Example 17

We need to make a supernetwork out of 16


class C blocks. What is the supernet mask?
Solution
We need 16 blocks. For 16 blocks we need to
change four 1s to 0s in the default mask. So the
mask is
11111111 11111111 11110000 00000000
or
255.255.240.0

Example 18
A supernet has a first address of 205.16.32.0 and a
supernet mask of 255.255.248.0. How many blocks are in
this supernet and what is the range of addresses?

Solution
The supernet has 21 1s. The default mask has 24
1s. Since the difference is 3, there are 2 3 or 8
blocks in this supernet. The blocks are 205.16.32.0
to 205.16.39.0. The first address is 205.16.32.0.
The last address is 205.16.39.255.

Example 19
A supernet has a first address of 205.16.32.0 and a
supernet mask of 255.255.248.0. A router receives three
packets with the following destination addresses:
205.16.37.44
205.16.42.56
205.17.33.76
Which packet belongs to the supernet?

Solution
We apply the supernet mask to see if we can find
the beginning address.
205.16.37.44 AND 255.255.248.0 205.16.32.0
205.16.42.56 AND 255.255.248.0

205.16.40.0

205.17.33.76 AND 255.255.248.0

205.17.32.0

Only the first address belongs to this supernet.

CLASSLESS
ADDRESSING

Classless Addressing
In classful addressing the minimum number of
addresses granted to an organization was 256(class C);
the maximum was 16,777,216(class A). In between
these limits an organization could have a class B block
or several class C blocks.
But , what about a small business that needed only 16
addresses? Or a house that needed only two addresses?

Classless Addressing
An ISP (Internet Service Provider) can provide these
services. An ISP is granted a large range of addresses
and then subdivides the addresses (in groups of
2,4,6,8,16 and so on), giving a range to a household or
a small business.
To facilitate this evolution and to resolve the problems
of classful addressing, in 1996, the Internet authorities
announced a new architecture called classless
addressing.

Variable-length Blocks
In classless addressing variable-length blocks are
assigned that belong to no class.
In this architecture, the entire address space (2^32
addresses) is divided into blocks of different sizes. An
organization is granted a block suitable for its
purposes.

Variable-length Blocks
There is only one condition on the number of
addresses in a block; it must be a power of 2 (2, 4,
8, . . .). A household may be given a block of 2
addresses. A small business may be given 16
addresses. A large organization may be given 1024
addresses.
The beginning address must be evenly divisible by the
number of addresses. For example, if a block contains
4 addresses, the beginning address must be divisible
by 4. If the block has less than 256 addresses, we need
to check only the rightmost byte. If it has less than
65,536 addresses, we need to check only the two
rightmost bytes, and so on.

Example 20
Which of the following can be the beginning address of a
block that contains 16 addresses?
205.16.37.32
190.16.42.44
17.17.33.80
123.45.24.52

Solution
The address 205.16.37.32 is eligible because 32 is
divisible by 16. The address 17.17.33.80 is eligible
because 80 is divisible by 16.

Example 21
Which of the following can be the beginning address of a
block that contains 256 addresses?
205.16.37.32
190.16.42.0
17.17.32.0
123.45.24.52

Solution
The rightmost byte must be 0. As the IP addresses
use base 256 arithmetic, when the rightmost byte is
0, the total address is divisible by 256. 2 nd and 3rd
addresses meets the condition.

Example 22
Which of the following can be the beginning address of a
block that contains 1024 addresses?
205.16.37.32
190.16.42.0
17.17.32.0
123.45.24.52

Solution
To be divisible by 1024(=4X256), the rightmost
byte of an address should be 0 and the second
rightmost byte must be divisible by 4. Only the
address 17.17.32.0 meets this condition.

Mask
In classless addressing, when an address is given, the
block the address belongs to cannot be found unless we
have the mask. The addresses must be accompanied by
the mask.
The mask is given in CIDR notation. X.Y.Z.T/n , where
n defines the number of bits that are the same in every
address in the block. So if n=20, it means the 20
leftmost bits are identical in each address with 12 bits
not the same. The number n is known as prefix length.
(32-n) is known as suffix length. There is a one-to-one
relationship between a mask and a prefix length.

Mask
/n

Mask

/n

Mask

/n

Mask

/n

Mask

/1

128.0.0.0

/9

255.128.0.0

/17

255.255.128.0

/25

255.255.255.12
8

/2

192.0.0.0

/10

255.192.0.0

/18

255.255.192.0

/26

255.255.255.19
2

/3

224.0.0.0

/11

255.224.0.0

/19

255.255.224.0

/27

255.255.255.22
4

/4

240.0.0.0

/12

255.240.0.0

/20

255.255.240.0

/28

255.255.255.24
0

/5

248.0.0.0

/13

255.248.0.0

/21

255.255.248.0

/29

255.255.255.24
8

/6

252.0.0.0

/14

255.252.0.0

/22

255.255.252.0

/30

255.255.255.25
2

/7

254.0.0.0

/15

255.254.0.0

/23

255.255.254.0

/31

255.255.255.25
4

/8

255.0.0.0

/16

255.255.0.0

/24

255.255.255.0

/32

255.255.255.25
5

Classful addressing is a special case of classless addressing.

Finding the First Address


In classless addressing, the size of the block that is
assigned to an organization varies according to the
needs of the organization.
As the addresses in classless addressing are
guaranteed to be contiguous and the prefix
determines the number of 1s, we can AND the mask
and the address to find the first address. Just keep the
first n bits and change the rest of bits to 0s.

Finding the First Address


What is the first address in the block if one of the addresses is
167.199.170.82/27?
Solution

The prefix length is 27, which means that we must keep


the first 27 bits as in and change the remaining bits(5) to
0s.
Address in binary: 10100111 11000111 10101010
01010010
Keep the left 27 bits: 10100111 11000111 10101010
01000000 First Address
Result in CIDR notation: 167.199.170.64/27

Finding the number of Addresses in the Block


The total number of addresses in the block is 2^(32-n).
A small organization is given a block with the
beginning
address
and
the
prefix
length
205.16.37.24/29 (in slash notation). What is the range
of the block?
Solution

The prefix length is 29. The number of addresses in the


block is 2^(32-29) = 2^3=8
There are only 8 addresses in this block.

Finding the Last Address


To find the last address of the block, we add the first
address to the complement of the mask.

Finding the Last Address


What is the last address in the block if one of the
addresses is 140.120.84.24/20?
Solution

The prefix length is 20, which means that the mask has
20 1s and 12 0s. The complement of the mask is
00000000 00000000 00001111 11111111 or 0.0.15.255.
We add the mask complement to the beginning address
to find the last address.
Address in binary:
00011000

10001100 01111000 01010100

Finding the Last Address


What is the last address in the block if one of the
addresses is 140.120.84.24/20?
Solution

Keep the left 20 bits: 10001100 01111000 01010000


00000000
Beginning address:
Complement of the Mask:
The last address is :

140. 120. 80. 0


0. 0. 15. 255
140.120.95.255/20

Assignments
1. What is the procedure to find the Subnet Mask and range of
addresses in the subnet for variable length blocks? Give example
and discuss.
2. An ISP is granted a block of addresses starting with 188.88.0.0/16 .
The ISP wants to distribute these blocks to 1000 customers as
follows:
The first group has 20 medium-size businesses, each needs 64
addresses
The second group has 400 small businesses, each needs 16
addresses.
The third group has 200 households, each with 4 addresses.
Design the sub-blocks and give the slash notation for each subblock. Find out how many addresses are still available after
these allocations.

You might also like