Computer Communication and Networks & Lab
Lecture 05
Network Layer:
Subnetting
BAWAR ABID ABDALLA
LECTURER
Mask or Default Mask
▪ The masks for classes A, B, and C are shown in Table below.
▪ The concept does not apply to classes D and E.
Default masks for classful addressing
CIDR : Classless InterDomain Routing
▪The mask can help us to find the netid and the hostid.
▪ For example, the mask for a class A address has eight 1s, which means
▪ the first 8 bits of any address in class A define the netid.
▪ the next 24 bits define the hostid.
Subnetting and Supernetting
▪Subnetting
▪ If an organization was granted a large block in class A or B, it could divide
the addresses into several contiguous groups and assign each group to smaller
networks (called subnets) or, in rare cases, share part of the addresses with
neighbors.
▪ Subnet: Sub network: A part of a network.
▪Supernetting
▪ A several networks are combined to create a super network or a supernet. Or
a network formed from two or more smaller networks.
Address Depletion
▪ The flaws in classful addressing scheme combined with the fast growth
of the Internet led to the near depletion of the available addresses.
▪ Yet the number of devices on the Internet is much less than the 232 address
space.
▪ We have run out of class A and B addresses, and a class C block is too small
for most midsize organizations. One solution that has alleviated the problem
is the idea of classless addressing.
Classful addressing, which is almost obsolete,
is replaced with classless addressing.
Classful addressing vs Classless
addressing
▪Classful addressing:
▪ An IPv4 addressing mechanism in which the IP address space is divided into
5 classes: A, B, C, D, and E. Each class occupies some part of the whole
address space.
▪Classless addressing:
▪ An addressing mechanism in which the IP address space is not divided into
classes.
Classless addressing
▪ Classless addressing
▪ To overcome address depletion and give more organizations access to the
Internet, classless addressing was designed and implemented. In this scheme,
there are no classes, but the addresses are still granted in blocks.
▪Address Blocks
▪ In classless addressing, when an entity, small or large, needs to be connected to the
Internet, it is granted a block (range) of addresses.
▪ The size of the block (the number of addresses) varies based on the nature and size of
the entity.
▪ For example, a household may be given only two addresses;
▪ a large organization may be given thousands of addresses.
▪ An ISP, as the Internet service provider, may be given thousands or hundreds of thousands based
on the number of customers it may serve.
Restriction
▪ To simplify the handling of addresses, the Internet authorities impose
(assume) three restrictions on classless address blocks:
1. The addresses in a block must be contiguous, one after another.
2. The number of addresses in a block must be a power of 2 (1, 2,4,8,.etc)
3. The first address must be evenly divisible by the number of addresses.
▪ Figure below [Next Slide] shows a block of addresses, in both binary
and dotted-decimal notation, granted to a small business that needs 16
addresses.
Restriction
▪ We can see that the restrictions are applied to this block:
▪ The addresses are contiguous.
▪ The number of addresses is a power of 2 (16 = 24), and
▪ the first address is divisible by 16 (32/16).
Mask
▪ A better way to define a block of addresses is to select any address in
the block and the mask.
▪ A mask is a 32-bit number in which the n leftmost bits are 1s and the
32 - n rightmost bits are 0s.
▪However, in classless addressing the mask for a block can take any value
from 0 to 32.
▪ It is very convenient to give just the value of n preceded by a slash (CIDR
notation).
In IPv4 addressing, a block of
addresses can be defined as
x.y.z.t /n
in which x.y.z.t defines one of the addresses and the /n defines the mask.
n 32-n
Mask: 11111111 11111111 11111111 00000000
Mask
▪ The address and the /n notation completely define the whole block (the
first address, the last address, and the number of addresses).
▪First Address
▪ The first address in the block can be found by setting the 32 - n rightmost bits
in the binary notation of the address to 0s.
Mask
▪ Example:
▪A block of addresses is granted to a small organization. We know that one
of the addresses is [Link]/28. What is the first address in the block?
▪ Solution
▪ The binary representation of the given address is
▪ 11001101 00010000 00100101 00100111
▪ If we set 32−28 rightmost bits to 0, we get
▪ 11001101 00010000 00100101 00100000
▪ or
[Link]
Mask
▪ Last Address
▪ The last address in the block can be found by setting the 32 - n rightmost bits in
the binary notation of the address to 1s.
▪Example
▪ Find the last address for the block.
▪[Link]/28
▪Solution
▪ The binary representation of the given address is
▪ 11001101 00010000 00100101 00100111
▪ If we set 32 − 28 rightmost bits to 1, we get
▪ 11001101 00010000 00100101 00101111
▪ or
▪ [Link]
Mask
▪ Number of Addresses
▪ The number of addresses in the block can be found by using the
formula
▪ 232−n
▪ Example
▪ Find the number of addresses in Example [Link]/28
▪ Solution
▪ The value of n is 28, which means that number
of addresses is 2 32−28 or 16.
▪ [Link]→[Link]
Mask
▪ Another way to find the first address, the last address, and the number of
addresses is to represent the mask as a 32bit binary (or 8-digit hexadecimal)
number.
▪ This is particularly useful when we are writing a program to find these
pieces of information.
▪ Example: the [Link]/28 , /28 can be represented as (Mask Definition)
11111111 11111111 11111111 11110000
(twenty-eight 1s and four 0s).
▪ Find
A. The first address
B. The last address
C. The number of addresses.
Mask
▪ Solution
a. The first address can be found by ANDing the given
addresses with the mask. ANDing here is done bit by
bit. The result of ANDing 2 bits is 1 if both bits are 1s;
the result is 0 otherwise.
[Link]
Mask
b. The last address can be found by ORing the given addresses with the
complement of the mask. Oring here is done bit by bit. The result of ORing 2 bits
is 0 if both bits are 0s; the result is 1 otherwise. The complement of a number is
found by changing each 1 to 0 and each 0 to 1.
Mask
c. The number of addresses can be found by complementing the mask,
interpreting it as a decimal number, and adding 1 to it.