COMPUTER NETWORKING LAB
CSE/ELE- 6TH / 7TH SEM
IP Addressing
1 Dr. J Nath
CONTENTS
• INTRODUCTION
• CLASSFUL ADDRESSING - STATIC
• Different Network Classes
• Subnetting
• Classless Addressing - DYNAMIC
• Supernetting
•CIDR (classless Interdomain Routing)
2 Dr. J Nath
INTRODUCTION
3 Dr. J Nath
What is an IP Address?
An IP address is a
32-bit
address.
The IP addresses
are
unique.
4 Dr. J Nath
Address space rule
…………..
addr1 …………..
addr15
Theaddr2 …………..
address space in a protocol
…………..
…………..
that uses N-bits to define an
address is: addr41 addr226
addr31 N
………….. 2 …………..
5 Dr. J Nath
IPv4 address space
The address space of IPv4 is
232
or
4,294,967,296.
6 Dr. J Nath
IP Address in Binary
Notation
01110101 10010101 00011101 11101010
7 Dr. J Nath
Figure 4-1
Dotted-decimal Notation
8 Dr. J Nath
Hexadecimal Notation
0111 0101 1001 0101 0001 1101 1110 1010
75 95 1D EA
0x75951DEA
9 Dr. J Nath
Example 1
128 1 128
Change the following IP address from 64 0 0
binary notation to dotted-decimal 32 1 32
notation. 16 0 0
10000001 00001011 00001011 11101111 8 1 8
4 0 0
2 0 0
[Link] 1 0 0
168
10 Dr. J Nath
Example 2
Change the following IP address
from dotted-decimal notation to
binary notation:
[Link]
Solution
01101111 00111000 00101101
11
01001110
Dr. J Nath
Example 3
Find the error in the following IP Address
[Link]
Solution
There are no leading zeroes in
Dotted-decimal notation (045)
12 Dr. J Nath
Example 3 (continued)
Find the error in the following IP Address
[Link]
Solution
In decimal notation each number <= 255
301 is out of the range
13 Dr. J Nath
Example 4
Change the following binary IP address
Hexadecimal notation
10000001 00001011 00001011 11101111
Solution
0X810B0BEF or 810B0BEF16
14 Dr. J Nath
CLASSFUL
ADDRESSING
15 Dr. J Nath
In classful addressing the address space is
divided into 5 classes:
A, B,
B, C,
C, D,, and E.
E.
16 Dr. J Nath
Figure 4-3
Finding the class in binary notation
17 Dr. J Nath
Figure 4-4
Finding the address class
18 Dr. J Nath
Example 5
Show that Class A has
231 = 2,147,483,648 addresses
19 Dr. J Nath
Example 6
Find the class of the following IP addresses
00000001 00001011 00001011 11101111
11000001 00001011 00001011 11101111
Solution
• 00000001 00001011 00001011 11101111
1st is 0, hence it is Class A
• 11000001 00001011 00001011 11101111
1st and 2nd bits are 1, and 3rd bit is 0 hence, Class C
20 Dr. J Nath
Figure 4-5
Finding the class in decimal notation
21 Dr. J Nath
Example 7
Find the class of the following addresses
[Link]
[Link]
Solution
• [Link]
1st byte = 158 (128<158<191) class B
• [Link]
1st byte = 227 (224<227<239) class D
22 Dr. J Nath
IP address with appending port
number (Socket Address)
[Link]:25
the four octet before colon is the IP address
The number of colon (25) is the port number
23 Dr. J Nath
Figure 4-6
NetId and HostId
24 Dr. J Nath
Figure 4-7
Blocks in Class A
25 Dr. J Nath
Millions of class A addresses
are wasted.
26 Dr. J Nath
Figure 4-8
Blocks in Class B
27 Dr. J Nath
Many class B addresses
are wasted.
28 Dr. J Nath
Figure 4-9
Blocks in Class C
29 Dr. J Nath
The number of addresses in
a class C block
is smaller than
the needs of most organizations.
30 Dr. J Nath
Class D addresses
are used for multicasting;
there is only
one block in this class.
31 Dr. J Nath
Class E addresses are reserved
for special purposes;
most of the block is wasted.
32 Dr. J Nath
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.
33 Dr. J Nath
In classful addressing,
the network address
(the first address in the block)
is the one that is assigned
to the organization.
34 Dr. J Nath
Example 8
Given the network address [Link], find the
class, the block, and the range of the addresses
Solution
The 1st byte is between 128 and 191.
Hence, Class B
The block has a netid of 132.21.
The addresses range from
[Link] to [Link].
35 Dr. J Nath
Masking
• A mask is a 32-bit binary number.
• The mask is ANDed with IP address to get
• The block address (Network address)
• Mask & IP address = Block Address
36 Dr. J Nath
Figure 4-10
Masking Concept
37 Dr. J Nath
Figure 4-11
AND Operation
38 Dr. J Nath
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.
39 Dr. J Nath
Default Mask
Class A default mask is [Link]
Class B default mask is [Link]
Class C Default mask [Link]
40 Dr. J Nath
Private IP Addresses
Most organizations have far more computers than available IP addresses. Using private IP
addresses to each internal computers, companies can have a single Internet gateway with a
public IP address. All of the other nodes have private IP addresses. The gateway uses a Network
Address Translation (NAT) server to translate the private IP addresses to an address that can be
routed across the Internet.
Class A : [Link] - [Link] (16,777,
216 IP addresses)
– Subnet Mask: [Link]
Class B :[Link]–[Link] (1,048,
576 IP addresses)
– Subnet Mask: [Link]
class C :[Link]–[Link] (65,
536 IP addresses)
– Subnet Mask: [Link]
41 Dr. J Nath
Subnetting &
Supernetting
42 Dr. J Nath
SUBNETTING
43 Dr. J Nath
IP addresses are designed with
two levels of hierarchy.
44 Dr. J Nath
Figure 5-1
A network with two levels of
hierarchy (not subnetted)
45 Dr. J Nath
Figure 5-2
A network with three levels of
hierarchy (subnetted)
46 Dr. J Nath
Note
Subnetting is done by borrowing bits from
the host part and add them the network part
47 Dr. J Nath
Figure 5-3
Addresses in a network with
and without subnetting
48 Dr. J Nath
Figure 5-5
Default mask and Subnet mask
49 Dr. J Nath
Finding the Subnet Address
Given an IP address, we can find the
subnet address the same way we found
the network address. We apply the
mask to the address. We can do this in
two ways: straight or short-cut.
50 Dr. J Nath
Rules
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.
51 Dr. J Nath
Example 9
What is the subnetwork address if the
destination address is [Link] and
the subnet mask is [Link]?
52 Dr. J Nath
Solution
11001000 00101101 00100010 00111000
11111111 11111111 11110000 00000000
11001000 00101101 00100000
0000 00000000
The subnetwork address is [Link].
53 Dr. J Nath
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.
54 Dr. J Nath
Example 10
What is the subnetwork address if the
destination address is [Link] and
the mask is [Link]?
Solution
next slide
55 Dr. J Nath
Figure 5-6
Solution
56 Dr. J Nath
Figure 5-7
Comparison of a default mask and
a subnet mask
57 Dr. J Nath
The number of subnets must be
a power of 2.
58 Dr. J Nath
Example 11
A company is granted the site address
[Link] (class C). The company needs
six subnets. Design the subnets.
Solution
The number of 1s in the default
mask is 24 (class C).
59 Dr. J Nath
Solution (Continued)
The company needs six subnets. This
number 6 is not a power of 2. The next
number that is a power of 2 is 8 (23). We
need 3 more 1s in the subnet mask. The
total number of 1s in the subnet mask is
27 (24 + 3).
The total number of 0s is 5 (32 27). The
60 mask is Dr. J Nath
Solution (Continued)
11111111 11111111 11111111
11100000
or
[Link]
The number of subnets is 8.
The number of addresses in each subnet is 25 (5
is the number of 0s) or 32.
61 See Next
Dr. Jslide
Nath
Figure 5-8
Example 11
62 Dr. J Nath
Example 12
A company is granted the site address
[Link] (class B). The company needs
1000 subnets. Design the subnets.
Solution
The number of 1s in the default mask is 16
(class B).
63 Dr. J Nath
Solution (Continued)
The company needs 1000 subnets. This
number is not a power of 2. The next
number that is a power of 2 is 1024 (210).
We need 10 more 1s in the subnet mask.
The total number of 1s in the subnet mask
is 26 (16 + 10).
The total number of 0s is 6 (32 26).
64 Dr. J Nath
Solution (Continued)
The mask is
11111111 11111111 11111111 11000000
or
[Link].
The number of subnets is 1024.
The number of addresses in each subnet is 26
(6 is the number of 0s) or 64.
See next slide
65 Dr. J Nath
Figure 5-9
Example 12
66 Dr. J Nath
Figure 5-10
Variable-length subnetting
67 Dr. J Nath
SUPERNETTING
68 Dr. J Nath
What is suppernetting?
Supernetting is the opposite of subnetting
In subnetting you borrow bits from the host
part
Supernetting is done by borrowing bits from
the network side.
And combine a group of networks into one
large supernetwork.
69 Dr. J Nath
Figure 5-11
A supernetwork
70 Dr. J Nath
Rules:
The number of blocks must be a power of 2 (1,
2, 4, 8, 16, . . .).
The blocks must be contiguous in the address
space (no gaps between the blocks).
The third byte of the first address in the
superblock must be evenly divisible by the
number of blocks. In other words, if the number of
blocks is N, the third byte must be divisible by N.
71 Dr. J Nath
Example
A company needs 600 addresses. Which of the following
set of class C blocks can be used to form a supernet for
this company?
[Link] [Link] [Link]
[Link] [Link] [Link] [Link]
[Link] [Link] [Link] [Link]
[Link] [Link] [Link] [Link]
72 Dr. J Nath
Solution
1: No, there are only three blocks.
2: No, the blocks are not contiguous.
3: No, 31 in the first block is not divisible by 4.
4: Yes, all three requirements are fulfilled.
73 Dr. J Nath
In subnetting,
we need the first address of the
subnet and the subnet mask to
define the range of addresses.
74 Dr. J Nath
In supernetting,
we need the first address of
the supernet
and the supernet mask to
define the range of addresses.
75 Dr. J Nath
Figure 5-12
Comparison of subnet, default,
and supernet masks
76 Dr. J Nath
Example
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
77 [Link] Dr. J Nath
Example
A supernet has a first address of [Link] and a
supernet mask of [Link]. A router receives
three packets with the following destination
addresses:
[Link]
[Link]
[Link]
Which packet belongs to the supernet?
78 Dr. J Nath
Solution
We apply the supernet mask to see if we can find the beginning
address.
[Link] AND [Link] [Link]
[Link] AND [Link] [Link]
[Link] AND [Link] [Link]
Only the first address belongs to this supernet.
79 Dr. J Nath
Example
A supernet has a first address of [Link] and a
supernet mask of [Link]. 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 23 or 8 blocks in this supernet. The blocks are
[Link] to [Link]. The first address is [Link]. The last
address is [Link].
80 Dr. J Nath
CLASSLESS
ADDRESSING
81 Dr. J Nath
Figure 5-13
Variable-length blocks
82 Dr. J Nath
Number of Addresses in a Block
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.
83 Dr. J Nath
Beginning Address
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.
84 Dr. J Nath
Example
Which of the following can be the beginning address of a
block that contains 1024 addresses?
[Link]
[Link]
[Link]
[Link]
Solution
To be divisible by 1024, the rightmost byte of an address
should be 0 and the second rightmost byte must be divisible
85 by 4. Only the address [Link] meets this condition.
Dr. J Nath
Figure 5-14
Slash notation
86 Dr. J Nath
Slash notation is also called
CIDR
notation.
87 Dr. J Nath
Example
A small organization is given a block with the
beginning address and the prefix length
[Link]/29 (in slash notation). What is
the range of the block?
88 Dr. J Nath
Solution
The beginning address is [Link]. To
find the last address we keep the first 29 bits
and change the last 3 bits to 1s.
Beginning: 11001111 00010000 00100101 00011000
Ending : 11001111 00010000 00100101 00011111
There are only 8 addresses in this block.
89 Dr. J Nath
Example cont’d
We can find the range of addresses in PREV
Example by another method. We can argue that
the length of the suffix is 32 29 or 3. So there
are 23 = 8 addresses in this block. If the first
address is [Link], the last address is
[Link] (24 + 7 = 31).
90 Dr. J Nath
A block in classes A, B, and C
can easily be represented in slash
notation as
A.B.C.D/ n
where n is
either 8 (class A), 16 (class B), or
24 (class C).
91 Dr. J Nath
Example
What is the network address if one of the addresses
is [Link]/27?
Solution
The prefix length is 27, which means that we
must keep the first 27 bits as is and change the
remaining bits (5) to 0s. The 5 bits affect only
the last byte. The last byte is 01010010.
Changing the last 5 bits to 0s, we get 01000000
or 64. The network address is
[Link]/27.
92 Dr. J Nath
Example
An organization is granted the block [Link]/26. The
organization needs to have four subnets. What are the subnet
addresses and the range of addresses for each subnet?
Solution
The suffix length is 6. This means the
total number of addresses in the block is
64 (26). If we create four subnets, each
subnet will have 16 addresses.
93 Dr. J Nath
Solution (Continued)
Let us first find the subnet prefix (subnet mask). We need four
subnets, which means we need to add two more 1s to the site
prefix. The subnet prefix is then /28.
Subnet 1: [Link]/28 to [Link]/28.
Subnet 2 : [Link]/28 to [Link]/28.
Subnet 3: [Link]/28 to [Link]/28.
Subnet 4: [Link]/28 to [Link]/28.
See Figure 5.15
94 Dr. J Nath
Figure 5-15
Example cont’d
95 Dr. J Nath
Example
An ISP is granted a block of addresses starting with [Link]/16. The ISP
needs to distribute these addresses to three groups of customers as follows:
1. The first group has 64 customers; each needs 256 addresses.
2. The second group has 128 customers; each needs 128 addresses.
3. The third group has 128 customers; each needs 64 addresses.
Design the subblocks and give the slash notation for each subblock. Find out how
many addresses are still available after these allocations.
96 Dr. J Nath
Solution
Group 1
For this group, each customer needs 256 addresses. This means the
suffix length is 8 (28 = 256). The prefix length is then 32 8 = 24.
01: [Link]/24 [Link]/24
02: [Link]/24 [Link]/24
…………………………………..
64: [Link]/24[Link]/24
Total = 64 256 = 16,384
97 Dr. J Nath
Solution (Continued)
Group 2
For this group, each customer needs 128 addresses. This means
the suffix length is 7 (27 = 128). The prefix length is then 32 7 = 25.
The addresses are:
001: [Link]/25 [Link]/25
002: [Link]/25 [Link]/25
………………..
128: [Link]/25 [Link]/25
Total = 128 128 = 16,384
98 Dr. J Nath
Solution (Continued)
Group 3
For this group, each customer needs 64 addresses. This means the
suffix length is 6 (26 = 64). The prefix length is then 32 6 = 26.
001:[Link]/26 [Link]/26
002:[Link]/26 [Link]/26
…………………………
128:[Link]/26 [Link]/26
Total = 128 64 = 8,192
99 Dr. J Nath
Solution (Continued)
Number of granted addresses: 65,536
Number of allocated addresses: 40,960
Number of available addresses: 24,576
10
0 Dr. J Nath