Tag: Basics of Computer Networks

Classless Addressing | CIDR in Networking

IP Addressing-

 

There are two systems in which IP Addresses are classified-

 

 

  1. Classful Addressing System
  2. Classless Addressing System

 

In this article, we will discuss about Classless Addressing System.

Learn about Classful Addressing System.

 

Classless Addressing-

 

  • Classless Addressing is an improved IP Addressing system.
  • It makes the allocation of IP Addresses more efficient.
  • It replaces the older classful addressing system based on classes.
  • It is also known as Classless Inter Domain Routing (CIDR).

 

CIDR Block-

 

When a user asks for specific number of IP Addresses,

  • CIDR dynamically assigns a block of IP Addresses based on certain rules.
  • This block contains the required number of IP Addresses as demanded by the user.
  • This block of IP Addresses is called as a CIDR block.

 

Rules For Creating CIDR Block-

 

A CIDR block is created based on the following 3 rules-

 

Rule-01:

 

  • All the IP Addresses in the CIDR block must be contiguous.

 

Rule-02:

 

  • The size of the block must be presentable as power of 2.
  • Size of the block is the total number of IP Addresses contained in the block.
  • Size of any CIDR block will always be in the form 21, 22, 23, 24, 25 and so on.

 

Rule-03:

 

  • First IP Address of the block must be divisible by the size of the block.

 

REMEMBER

 

If any binary pattern consisting of (m + n) bits is divided by 2n, then-

  • Remainder is least significant n bits
  • Quotient is most significant m bits

 

So, any binary pattern is divisible by 2n, if and only if its least significant n bits are 0.

 

Examples-

 

Consider a binary pattern-

01100100.00000001.00000010.01000000

(represented as 100.1.2.64)

  • It is divisible by 25 since its least significant 5 bits are zero.
  • It is divisible by 26 since its least significant 6 bits are zero.
  • It is not divisible by 27 since its least significant 7 bits are not zero.

 

CIDR Notation-

 

CIDR IP Addresses look like-

a.b.c.d / n

 

  • They end with a slash followed by a number called as IP network prefix.
  • IP network prefix tells the number of bits used for the identification of network.
  • Remaining bits are used for the identification of hosts in the network.

 

Example-

 

An example of CIDR IP Address is-

182.0.1.2 / 28

 

It suggests-

  • 28 bits are used for the identification of network.
  • Remaining 4 bits are used for the identification of hosts in the network.

 

PRACTICE PROBLEMS BASED ON CLASSLESS INTER DOMAIN ROUTING-

 

Problem-01:

 

Given the CIDR representation 20.10.30.35 / 27. Find the range of IP Addresses in the CIDR block.

 

Solution-

 

Given CIDR representation is 20.10.30.35 / 27.

 

It suggests-

  • 27 bits are used for the identification of network.
  • Remaining 5 bits are used for the identification of hosts in the network.

 

Given CIDR IP Address may be represented as-

00010100.00001010.00011110.00100011 / 27

 

So,

  • First IP Address = 00010100.00001010.00011110.00100000 = 20.10.30.32
  • Last IP Address = 00010100.00001010.00011110.00111111 = 20.10.30.63

 

Thus, Range of IP Addresses = [ 20.10.30.32 , 20.10.30.63]

 

Problem-02:

 

Given the CIDR representation 100.1.2.35 / 20. Find the range of IP Addresses in the CIDR block.

 

Solution-

 

Given CIDR representation is 100.1.2.35 / 20.

 

It suggests-

  • 20 bits are used for the identification of network.
  • Remaining 12 bits are used for the identification of hosts in the network.

 

Given CIDR IP Address may be represented as-

01100100.00000001.00000010.00100011 / 20

 

So,

  • First IP Address = 01100100.00000001.00000000.00000000 = 100.1.0.0
  • Last IP Address = 01100100.00000001.00001111.11111111 = 100.1.15.255

 

Thus, Range of IP Addresses = [ 100.1.0.0 , 100.1.15.255]

 

Problem-03:

 

Consider a block of IP Addresses ranging from 100.1.2.32 to 100.1.2.47.

  1. Is it a CIDR block?
  2. If yes, give the CIDR representation.

 

Solution-

 

For any given block to be a CIDR block, 3 rules must be satisfied-

 

Rule-01:

 

  • According to Rule-01, all the IP Addresses must be contiguous.
  • Clearly, all the given IP Addresses are contiguous.
  • So, Rule-01 is satisfied.

 

Rule-02:

 

  • According to Rule-02, size of the block must be presentable as 2n.
  • Number of IP Addresses in the given block = 47 – 32 + 1 = 16.
  • Size of the block = 16 which can be represented as 24.
  • So, Rule-02 is satisfied.

 

Rule-03:

 

  • According to Rule-03, first IP Address must be divisible by size of the block.
  • So, 100.1.2.32 must be divisible by 24.
  • 100.1.2.32 = 100.1.2.00100000 is divisible by 24 since its 4 least significant bits are zero.
  • So, Rule-03 is satisfied.

 

Since all the rules are satisfied, therefore given block is a CIDR block.

 

CIDR Representation-

 

We have-

  • Size of the block = Total number of IP Addresses = 24.
  • To have 24 total number of IP Addresses, total 4 bits are required in the Host ID part.
  • So, Number of bits present in the Network ID part = 32 – 4 = 28.

 

Thus,

CIDR Representation = 100.1.2.32 / 28

 

NOTE-

 

For writing the CIDR representation,

  • We can choose to mention any IP Address from the CIDR block.
  • The chosen IP Address is followed by a slash and IP network prefix.
  • We generally choose to mention the first IP Address.

 

Problem-04:

 

Consider a block of IP Addresses ranging from 150.10.20.64 to 150.10.20.127.

  1. Is it a CIDR block?
  2. If yes, give the CIDR representation.

 

Solution-

 

For any given block to be a CIDR block, 3 rules must be satisfied-

 

Rule-01:

 

  • According to Rule-01, all the IP Addresses must be contiguous.
  • Clearly, all the given IP Addresses are contiguous.
  • So, Rule-01 is satisfied.

 

Rule-02:

 

  • According to Rule-02, size of the block must be presentable as 2n.
  • Number of IP Addresses in given block = 127 – 64 + 1 = 64.
  • Size of the block = 64 which can be represented as 26.
  • So, Rule-02 is satisfied.

 

Rule-03:

 

  • According to Rule-03, first IP Address must be divisible by size of the block.
  • So, 150.10.20.64 must be divisible by 26.
  • 150.10.20.64 = 150.10.20.01000000 is divisible by 26 since its 6 least significant bits are zero.
  • So, Rule-03 is satisfied.

 

Since all the rules are satisfied, therefore given block is a CIDR block.

 

CIDR Representation-

 

We have-

  • Size of the block = Total number of IP Addresses = 26.
  • To have 26 total number of IP Addresses, 6 bits are required in the Host ID part.
  • So, Number of bits in the Network ID part = 32 – 6 = 26.

 

Thus,

CIDR Representation = 150.10.20.64 / 26

 

Problem-05:

 

Perform CIDR aggregation on the following IP Addresses-

128.56.24.0/24

128.56.25.0/24

128.56.26.0/24

128.56.27.0/24

 

Solution-

 

All the 4 given entities represent CIDR block in itself.

We have to now perform the aggregation of these 4 blocks.

 

Rule-01:

 

  • According to Rule-01, all the IP Addresses must be contiguous.
  • Clearly, all the IP Addresses are contiguous.
  • So, Rule-01 is satisfied.

 

Rule-02:

 

  • According to Rule-02, size of the block must be presentable as 2n.
  • Total number of IP Addresses = 28 + 28 + 28 + 28 = 22 x 28 = 210.
  • So, Rule-02 is satisfied.

 

Rule-03:

 

  • According to Rule-03, first IP Address must be divisible by size of the block.
  • So, 128.56.24.0 must be divisible by 210.
  • 128.56.24.0 = 128.56.00011000.00000000 is divisible by 210 since its 10 least significant bits are zero.
  • So, Rule-03 is satisfied.

 

Since all the 3 rules are satisfied, so they can be aggregated.

 

CIDR Representation-

 

We have-

  • Size of the block = Total number of IP Addresses = 210.
  • To have 210 total number of IP Addresses, 10 bits are required in the Host ID part.
  • So, Number of bits in the Network ID part = 32 – 10 = 22.

 

Thus,

CIDR Representation = 128.56.24.0/22

 

Problem-06:

 

Perform CIDR aggregation on the following IP Addresses-

200.96.86.0/24

200.96.87.0/24

200.96.88.0/24

200.96.89.0/24

 

Solution-

 

All the 4 given entities represent CIDR block in itself.

We have to now perform the aggregation of these 4 blocks.

 

Rule-01:

 

  • According to Rule-01, all the IP Addresses must be contiguous.
  • Clearly, all the IP Addresses are contiguous.
  • So, Rule-01 is satisfied.

 

Rule-02:

 

  • According to Rule-02, size of the block must be presentable as 2n.
  • Total number of IP Addresses = 28 + 28 + 28 + 28 = 22 x 28 = 210.
  • So, Rule-02 is satisfied.

 

Rule-03:

 

  • According to Rule-03, first IP Address must be divisible by size of the block.
  • So, 200.96.86.0 must be divisible by 210.
  • 200.96.86.0 = 200.96.01010110.00000000 is not divisible by 210 since its 10 least significant bits are not zero.
  • So, Rule-03 is unsatisfied.

 

Since all the 3 rules are not satisfied, so they can not be aggregated.

 

To gain better understanding about Classless Addressing,

Watch this Video Lecture

 

Next Article- Subnetting | Examples

 

Get more notes and other study material of Computer Networks.

Watch video lectures by visiting our YouTube channel LearnVidFun.

TCP Retransmission | TCP Duplicate ACK

Three Way Handshake-

 

Before you go through this article, make sure that you have gone through the previous article on Three Way Handshake.

 

We have discussed-

  • TCP uses Three Way Handshake to establish a connection between the sender and receiver.
  • Connection establishment using Three Way Handshake involves the steps as shown-

 

 

In this article, we will discuss how a lost TCP segment is retransmitted.

 

TCP Retransmission-

 

After establishing the connection,

  • Sender starts transmitting TCP segments to the receiver.
  • A TCP segment sent by the sender may get lost on the way before reaching the receiver.
  • This causes the receiver to send the acknowledgement with same ACK number to the sender.
  • As a result, sender retransmits the same segment to the receiver.
  • This is called as TCP retransmission.

 

When TCP Retransmission Occurs?

 

When sender discovers that the segment sent by it is lost,

it retransmits the same segment to the receiver.

 

Sender discovers that the TCP segment is lost when-

  1. Either Time Out Timer expires
  2. Or it receives three duplicate acknowledgements

 

1. Retransmission After Time Out Timer Expiry-

 

Each time sender transmits a TCP segment to the receiver, it starts a Time Out Timer.

Now, following two cases are possible-

 

Case-01:

 

  • Sender receives an acknowledgement for the sent segment before the timer goes off.
  • In this case, sender stops the timer.

 

Case-02:

 

  • Sender does not receives any acknowledgement for the sent segment and the timer goes off.
  • In this case, sender assumes that the sent segment is lost.
  • Sender retransmits the same segment to the receiver and resets the timer.

 

Also Read- Time Out Timer

 

Example-

 

 

2. Retransmission After Receiving 3 Duplicate Acknowledgements-

 

  • Consider sender receives three duplicate acknowledgements for a TCP segment sent by it.
  • Then, sender assumes that the corresponding segment is lost.
  • So, sender retransmits the same segment without waiting for its time out timer to expire.
  • This is known as Early retransmission or Fast retransmission.

 

Example-

 

Consider-

  • Sender sends 5 TCP segments to the receiver.
  • The second TCP segment gets lost before reaching the receiver.

 

The sequence of steps taking place are-

 

  • On receiving segment-1, receiver sends acknowledgement asking for segment-2 next.

(Original ACK)

  • On receiving segment-3, receiver sends acknowledgement asking for segment-2 next.

(1st duplicate ACK)

  • On receiving segment-4, receiver sends acknowledgement asking for segment-2 next.

(2nd duplicate ACK)

  • On receiving segment-5, receiver sends acknowledgement asking for segment-2 next.

(3rd duplicate ACK)

 

Now,

  • Sender receives 3 duplicate acknowledgements for segment-2 in total.
  • So, sender assumes that the segment-2 is lost.
  • So, it retransmits segment-2 without waiting for its timer to go off.

 

 

NOTE

After receiving the retransmitted segment-2,

  • Receiver does not send the acknowledgement asking for segment-3 or 4 or 5.
  • Receiver sends the acknowledgement asking for segment-6 directly from the sender.
  • This is because previous segments have been already received and acknowledgements for them have been already sent (although wasted in asking for segment-2).

 

Important Points-

 

Point-01:

 

  • Consider time out timer expires before receiving the acknowledgement for a TCP segment.
  • This case suggests the stronger possibility of congestion in the network.

 

Point-02:

 

  • Consider sender receives 3 duplicate acknowledgements for the same TCP segment.
  • This case suggests the weaker possibility of congestion in the network.

 

Point-03:

 

  • Consider receiver does not receives 3 duplicate acknowledgements for the lost TCP segment.
  • In such a case, retransmission occurs only after time out timer goes off.

 

Point-04:

 

  • Retransmission on receiving 3 duplicate acknowledgements is a way to improve the performance over retransmission on time out.

 

Also Read- TCP Congestion Control

 

PRACTICE PROBLEM BASED ON TCP RETRANSMISSION-

 

Problem-

 

Consider a TCP connection in a state where there are no outstanding ACKs. The sender sends two segments back to back. The sequence numbers of the first and second segments are 230 and 290 respectively. The first segment was lost but the second segment was received correctly by the receiver.

Let X be the amount of data carried in the first segment (in bytes) and Y be the ACK number sent by the receiver.

The values of X and Y are-

  1. 60 and 290
  2. 230 and 291
  3. 60 and 231
  4. 60 and 230

 

Solution-

 

It is given that sender sends two segments where-

  • 1st segment contains the sequence number 230 and gets lost.
  • 2nd segment contains the sequence number 290 and is received correctly.

 

Amount Of Data Sent In First Segment-

 

Given-

  • Sequence number of 1st segment = 230
  • Sequence number of 2nd segment = 290

 

From here, range of sequence numbers contained in the 1st segment = [230,289].

 

Now,

  • Total number of sequence numbers contained in the 1st segment = 289 – 230 + 1 = 60.
  • TCP assigns one sequence number to each byte of data.
  • Thus, Amount of data contained in the first segment = 60 bytes.

 

ACK Number Sent By Receiver-

 

On receiving the 2nd segment,

  • Receiver sends the acknowledgement asking for the first segment only.
  • This is because it expects the 1st segment first.
  • Receiver keeps sending this ACK number until it receives the first segment correctly.
  • Thus, Acknowledgement number = Sequence number of the 1st segment = 230.

 

Thus, Option (D) is correct.

 

Next Article- TCP Connection Termination

 

Get more notes and other study material of Computer Networks.

Watch video lectures by visiting our YouTube channel LearnVidFun.

Subnet Mask | Practice Problems

Subnet Mask-

 

Before you go through this article, make sure that you gone through the previous article on Subnet Mask.

 

We have discussed-

  • Subnet mask is a 32 bit number consisting of a sequence of 1’s and 0’s.
  • It is used to identify the subnet to which the given IP Address belongs.

 

In this article, we will discuss practice problems based on subnet mask.

 

PRACTICE PROBLEMS BASED ON SUBNET MASK-

 

Problems-01 to 09:

 

Consider the following subnet masks-

  1. 255.0.0.0
  2. 255.128.0.0
  3. 255.192.0.0
  4. 255.240.0.0
  5. 255.255.0.0
  6. 255.255.254.0
  7. 255.255.255.0
  8. 255.255.255.224
  9. 225.255.255.240

 

For each subnet mask, find-

  1. Number of hosts per subnet
  2. Number of subnets if subnet mask belongs to class A
  3. Number of subnets if subnet mask belongs to class B
  4. Number of subnets if subnet mask belongs to class C
  5. Number of subnets if total 10 bits are used for the global network ID

 

Solutions-

 

All the problems are solved below one by one-

 

Solution-01:

 

Given subnet mask is 255.0.0.0

So,

  • Number of Net ID bits + Number of Subnet ID bits = 8
  • Number of Host ID bits = 24

 

Part-A:

 

Since number of Host ID bits = 24, so-

 

Number of hosts per subnet = 224 – 2

 

Part-B:

 

If the given subnet mask belongs to class A, then number of Net ID bits = 8.

Substituting in the above equation, we get-

Number of Subnet ID bits = 8 – 8 = 0

Thus,

 

Number of subnets = 20 = 1

 

Thus, there will be only one single network.

 

Part-C:

 

  • First two octets of the subnet mask are not completely filled with 1’s.
  • So, given subnet mask can not belong to class B.

 

Part-D:

 

  • First three octets of the subnet mask are not completely filled with 1’s.
  • So, given subnet mask can not belong to class C.

 

Part-E:

 

  • First 10 bits of the subnet mask are not completely filled with 1’s.
  • So, given subnet mask can not use 10 bits for the Network ID.

 

NOTE-

 

  • 255.0.0.0 is the default mask for class A.

 

Solution-02:

 

Given subnet mask is 255.128.0.0

So,

  • Number of Net ID bits + Number of Subnet ID bits = 9
  • Number of Host ID bits = 23

 

Part-A:

 

Since number of Host ID bits = 23, so-

 

Number of hosts per subnet = 223 – 2

 

Part-B:

 

If the given subnet mask belongs to class A, then number of Net ID bits = 8.

Substituting in the above equation, we get-

Number of Subnet ID bits = 9 – 8 = 1

Thus,

 

Number of subnets = 21 = 2

 

Part-C:

 

  • First two octets of the subnet mask are not completely filled with 1’s.
  • So, given subnet mask can not belong to class B.

 

Part-D:

 

  • First three octets of the subnet mask are not completely filled with 1’s.
  • So, given subnet mask can not belong to class C.

 

Part-E:

 

  • First 10 bits of the subnet mask are not completely filled with 1’s.
  • So, given subnet mask can not use 10 bits for the Network ID.

 

Solution-03:

 

Given subnet mask is 255.192.0.0

So,

  • Number of Net ID bits + Number of Subnet ID bits = 10
  • Number of Host ID bits = 22

 

Part-A:

 

Since number of Host ID bits = 22, so-

 

Number of hosts per subnet = 222 – 2

 

Part-B:

 

If the given subnet mask belongs to class A, then number of Net ID bits = 8.

Substituting in the above equation, we get-

Number of Subnet ID bits = 10 – 8 = 2

Thus,

 

Number of subnets = 22 = 4

 

Part-C:

 

  • First two octets of the subnet mask are not completely filled with 1’s.
  • So, given subnet mask can not belong to class B.

 

Part-D:

 

  • First three octets of the subnet mask are not completely filled with 1’s.
  • So, given subnet mask can not belong to class C.

 

Part-E:

 

Given 10 bits are used for the Net ID part.

Substituting in the above equation, we get-

Number of Subnet ID bits = 10 – 10 = 0

Thus,

 

Number of subnets = 20 = 1

 

Thus, there will be only one single network.

 

Solution-04:

 

Given subnet mask is 255.240.0.0

So,

  • Number of Net ID bits + Number of Subnet ID bits = 12
  • Number of Host ID bits = 20

 

Part-A:

 

Since number of Host ID bits = 20, so-

 

Number of hosts per subnet = 220 – 2

 

Part-B:

 

If the given subnet mask belongs to class A, then number of Net ID bits = 8.

Substituting in the above equation, we get-

Number of Subnet ID bits = 12 – 8 = 4

Thus,

 

Number of subnets = 24 = 16

 

Part-C:

 

  • First two octets of the subnet mask are not completely filled with 1’s.
  • So, given subnet mask can not belong to class B.

 

Part-D:

 

  • First three octets of the subnet mask are not completely filled with 1’s.
  • So, given subnet mask can not belong to class C.

 

Part-E:

 

Given 10 bits are used for the Net ID part.

Substituting in the above equation, we get-

Number of Subnet ID bits = 12 – 10 = 2

Thus,

 

Number of subnets = 22 = 4

 

Solution-05:

 

Given subnet mask is 255.255.0.0

So,

  • Number of Net ID bits + Number of Subnet ID bits = 16
  • Number of Host ID bits = 16

 

Part-A:

 

Since number of Host ID bits = 16, so-

 

Number of hosts per subnet = 216 – 2

 

Part-B:

 

If the given subnet mask belongs to class A, then number of Net ID bits = 8.

Substituting in the above equation, we get-

Number of Subnet ID bits = 16 – 8 = 8

Thus,

 

Number of subnets = 28

 

Part-C:

 

If the given subnet mask belongs to class B, then number of Net ID bits = 16.

Substituting in the above equation, we get-

Number of Subnet ID bits = 16 – 16 = 0

Thus,

 

Number of subnets = 20 = 1

 

Part-D:

 

  • First three octets of the subnet mask are not completely filled with 1’s.
  • So, given subnet mask can not belong to class C.

 

Part-E:

 

Given 10 bits are used for the Net ID part.

Substituting in the above equation, we get-

Number of Subnet ID bits = 16 – 10 = 6

Thus,

 

Number of subnets = 26 = 64

 

NOTE-

 

  • 255.255.0.0 is the default mask for class B.

 

Solution-06:

 

Given subnet mask is 255.255.254.0

So,

  • Number of Net ID bits + Number of Subnet ID bits = 23
  • Number of Host ID bits = 9

 

Part-A:

 

Since number of Host ID bits = 9, so-

 

Number of hosts per subnet = 29 – 2

 

Part-B:

 

If the given subnet mask belongs to class A, then number of Net ID bits = 8.

Substituting in the above equation, we get-

Number of Subnet ID bits = 23 – 8 = 15

Thus,

 

Number of subnets = 215

 

Part-C:

 

If the given subnet mask belongs to class B, then number of Net ID bits = 16.

Substituting in the above equation, we get-

Number of Subnet ID bits = 23 – 16 = 7

Thus,

 

Number of subnets = 27

 

Part-D:

 

  • First three octets of the subnet mask are not completely filled with 1’s.
  • So, given subnet mask can not belong to class C.

 

Part-E:

 

Given 10 bits are used for the Net ID part.

Substituting in the above equation, we get-

Number of Subnet ID bits = 23 – 10 = 13

Thus,

 

Number of subnets = 213

 

Solution-07:

 

Given subnet mask is 255.255.255.0

So,

  • Number of Net ID bits + Number of Subnet ID bits = 24
  • Number of Host ID bits = 8

 

Part-A:

 

Since number of Host ID bits = 8, so-

 

Number of hosts per subnet = 28 – 2

 

Part-B:

 

If the given subnet mask belongs to class A, then number of Net ID bits = 8.

Substituting in the above equation, we get-

Number of Subnet ID bits = 24 – 8 = 16

Thus,

 

Number of subnets = 216

 

Part-C:

 

If the given subnet mask belongs to class B, then number of Net ID bits = 16.

Substituting in the above equation, we get-

Number of Subnet ID bits = 24 – 16 = 8

Thus,

 

Number of subnets = 28

 

Part-D:

 

If the given subnet mask belongs to class C, then number of Net ID bits = 24.

Substituting in the above equation, we get-

Number of Subnet ID bits = 24 – 24 = 0

Thus,

 

Number of subnets = 20 = 1

 

Part-E:

 

Given 10 bits are used for the Net ID part.

Substituting in the above equation, we get-

Number of Subnet ID bits = 24 – 10 = 14

Thus,

 

Number of subnets = 214

 

NOTE-

 

  • 255.255.255.0 is the default mask for class C.

 

Solution-08:

 

Given subnet mask is 255.255.255.224

So,

  • Number of Net ID bits + Number of Subnet ID bits = 27
  • Number of Host ID bits = 5

 

Part-A:

 

Since number of Host ID bits = 5, so-

 

Number of hosts per subnet = 25 – 2

 

Part-B:

 

If the given subnet mask belongs to class A, then number of Net ID bits = 8.

Substituting in the above equation, we get-

Number of Subnet ID bits = 27 – 8 = 19

Thus,

 

Number of subnets = 219

 

Part-C:

 

If the given subnet mask belongs to class B, then number of Net ID bits = 16.

Substituting in the above equation, we get-

Number of Subnet ID bits = 27 – 16 = 11

Thus,

 

Number of subnets = 211

 

Part-D:

 

If the given subnet mask belongs to class C, then number of Net ID bits = 24.

Substituting in the above equation, we get-

Number of Subnet ID bits = 27 – 24 = 3

Thus,

 

Number of subnets = 23 = 8

 

Part-E:

 

Given 10 bits are used for the Net ID part.

Substituting in the above equation, we get-

Number of Subnet ID bits = 27 – 10 = 17

Thus,

 

Number of subnets = 217

 

Solution-09:

 

Given subnet mask is 255.255.255.240

So,

  • Number of Net ID bits + Number of Subnet ID bits = 28
  • Number of Host ID bits = 4

 

Part-A:

 

Since number of Host ID bits = 4, so-

 

Number of hosts per subnet = 24 – 2

 

Part-B:

 

If the given subnet mask belongs to class A, then number of Net ID bits = 8.

Substituting in the above equation, we get-

Number of Subnet ID bits = 28 – 8 = 20

Thus,

 

Number of subnets = 220

 

Part-C:

 

If the given subnet mask belongs to class B, then number of Net ID bits = 16.

Substituting in the above equation, we get-

Number of Subnet ID bits = 28 – 16 = 12

Thus,

 

Number of subnets = 212

 

Part-D:

 

If the given subnet mask belongs to class C, then number of Net ID bits = 24.

Substituting in the above equation, we get-

Number of Subnet ID bits = 28 – 24 = 4

Thus,

 

Number of subnets = 24

 

Part-E:

 

Given 10 bits are used for the Net ID part.

Substituting in the above equation, we get-

Number of Subnet ID bits = 28 – 10 = 18

Thus,

 

Number of subnets = 218

 

Problem-10:

 

Consider default subnet mask for a network is 255.255.255.0. How many number of subnets and hosts per subnet are possible if ‘m’ bits are borrowed from HID.

  1. 2m , 2(HID-m) – 2
  2. 2m , 2(HID-m)
  3. 2m – 1, 2(HID-m) – 2
  4. 2m , (HID-m) – 2

 

Solution-

 

  • Subnet mask = 255.255.255.0
  • Number of bits borrowed from Host ID part = m
  • So, number of subnets possible = 2m
  • Number of bits available for Hosts = HID – m
  • So, number of hosts that can be configured = 2(HID – m) – 2

 

Thus, Option (A) is correct.

 

Problem-11:

 

If default subnet mask for a network is 255.255.255.0 and if ‘m’ bits are borrowed from the NID, then what could be its supernet mask?

  1. 255.255.(28-m – 1) x 2m.0
  2. 255.255.(28-m) x 2m.0
  3. 255.255.(28-m-1) x 2m-1.0
  4. 255.255.(28-m) x 2m-1.0

 

Solution-

 

Given-

  • Subnet mask = 255.255.255.0
  • m bits are chosen from the NID part.

 

Clearly, given subnet mask belongs to class C.

If m = 4, then the subnet mask = 255.255.11110000.0

Now, let us check all the options one by one.

 

Option-A:

 

Given-

  • Supernet mask = 255.255.(28-m – 1) x 2m.0
  • Third octet = (28-m – 1) x 2m

 

On substituting m = 4, we get-

Third octet

= 15 x 24

= (1111)2 x 24

= 11110000 (Performing Left shift by 4 places)

 

Yes, this is what the third octet should be.

Thus, Option (A) is correct.

 

Option-B:

 

Given-

  • Supernet mask = 255.255.(28-m) x 2m.0
  • Third octet = (28-m) x 2m

 

On substituting m = 4, we get-

Third octet

= 16 x 24

= (10000)2 x 24

= 100000000 (Performing Left shift by 4 places)

 

This can not be true because these are 9 bits and octet can be only 8 bits.

Thus, Option (B) is incorrect.

Similarly, other options are also incorrect.

 

Finally, Option (A) is the only correct option.

 

To watch video solutions and practice more problems,

Watch this Video Lecture

 

Next Article- Routing Table | Arrangement of Subnets

 

Get more notes and other study material of Computer Networks.

Watch video lectures by visiting our YouTube channel LearnVidFun.

Subnet Mask | How to Calculate Subnet Mask

Subnetting in Networking-

 

Before you go through this article, make sure that you have gone through the previous article on Subnetting.

 

We have discussed-

  • Subnetting is a process of dividing a single network into multiple sub networks.
  • The number of sub networks created depends upon the requirements.

 

 

Subnet Mask-

 

Subnet mask is a 32 bit number which is a sequence of 1’s followed by a sequence of 0’s where-

  • 1’s represent the global network ID part and the subnet ID part.
  • 0’s represent the host ID part.

 

How to Calculate Subnet Mask?

 

For any given IP Address, the subnet mask is calculated-

  • By setting all the bits reserved for network ID part and subnet ID part to 1.
  • By setting all the bits reserved for host ID part to 0.

 

Subnet Mask Examples-

 

Now, let us discuss some examples on how to calculate subnet mask for any given network-

 

Example-01:

 

Consider we have a network having IP Address 200.1.2.0.

 

Clearly, this IP Address belongs to class C.

 

In class C-

  • 24 bits are reserved for the Network ID part.
  • 8 bits are reserved for the Host ID part.

 

Subnet mask is obtained-

  • By setting the first 24 bits to 1.
  • By setting the remaining 8 bits to 0.

 

So, Subnet mask

= 11111111.11111111.11111111.00000000

= 255.255.255.0

 

Example-02:

 

Consider a single network having IP Address 200.1.2.0 is divided into 4 subnets as shown-

 

 

Now, let us calculate the mask subnet for each subnet.

 

For each subnet-

  • 24 bits identify the global network.
  • 2 bits identify the subnet.
  • 6 bits identify the host.

 

For each subnet, subnet mask is obtained-

  • By setting the first 26 bits to 1.
  • By setting the remaining 6 bits to 0.

 

So, Subnet mask

= 11111111.11111111.11111111.11000000

= 255.255.255.192

 

NOTE

In fixed length subnetting,

All the subnets have same subnet mask since the size of each subnet is same.

 

Example-03:

 

Consider a single network having IP Address 200.1.2.0 is divided into 3 subnets as shown-

 

 

Now, let us calculate the subnet mask for each subnet.

 

For Subnet A-

 

For subnet A-

  • 24 bits identify the global network.
  • 1 bit identify the subnet.
  • 7 bits identify the host.

 

For subnet A, subnet mask is obtained-

  • By setting the first 25 bits to 1.
  • By setting the remaining 7 bits to 0.

 

So, Subnet mask

= 11111111.11111111.11111111.10000000

= 255.255.255.128

 

For Subnet B And Subnet C-

 

For subnet B and subnet C-

  • 24 bits identify the global network.
  • 2 bits identify the subnet.
  • 6 bits identify the host.

 

For subnet B and subnet C, subnet mask is obtained-

  • By setting the first 26 bits to 1.
  • By setting the remaining 6 bits to 0.

 

So, Subnet mask

= 11111111.11111111.11111111.11000000

= 255.255.255.192

 

NOTE

In variable length subnetting,

All the subnets do not have same subnet mask since the size of each subnet is not same.

 

Use of Subnet Mask-

 

  • Subnet mask is used to determine to which subnet the given IP Address belongs to.
  • To know more, Read here.

 

Important Notes-

 

Note-01:

 

Default mask for different classes of IP Address are-

  • Default subnet mask for Class A = 255.0.0.0
  • Default subnet mask for Class B = 255.255.0.0
  • Default subnet mask for Class C = 255.255.255.0

 

Also Read- Classes of IP Address

 

Note-02:

 

  • Network size is the total number of hosts present in it.
  • Networks of same size always have the same subnet mask.
  • Networks of different size always have the different subnet mask.

 

Note-03:

 

  • For a network having larger size, its subnet mask will be smaller (number of 1’s will be less).
  • For a network having smaller size, its subnet mask will be larger (number of 1’s will be more).

 

PRACTICE PROBLEMS BASED ON SUBNET MASK-

 

Problem-01:

 

If the subnet mask 255.255.255.128 belongs to class C, find-

  1. Number of subnets
  2. Number of hosts in each subnet

 

Solution-

 

Given subnet mask

= 255.255.255.128

= 11111111.11111111.11111111.10000000

 

Since 25 bits contain the value 1 and 7 bits contain the value 0, so-

  • Number of Net ID bits + Number of Subnet ID bits = 25
  • Number of Host ID bits = 7

 

Now,

  • It is given that subnet mask belongs to class C.
  • So, Number of Net ID bits = 24.

 

Substituting in the above equation, we get-

Number of Subnet ID bits

= 25 – 24

= 1

 

Thus,

Number of subnets = 21 = 2

 

Since number of Host ID bits = 7, so-

 

Number of hosts per subnet = 27 – 2 = 126

 

Problem-02:

 

If a class B network has a subnet mask of 255.255.248.0, what is the maximum number of hosts per subnet?

  1. 1022
  2. 1023
  3. 2046
  4. 2047

 

Solution-

 

Given subnet mask

= 255.255.248.0

= 11111111.11111111.11111000.00000000

 

Since 21 bits contain the value 1 and 11 bits contain the value 0, so-

  • Number of Net ID bits + Number of Subnet ID bits = 21
  • Number of Host ID bits = 11

 

Since number of Host ID bits = 11, so-

 

Number of hosts per subnet = 211 – 2 = 2046

 

Thus, Option (C) is correct.

 

To gain better understanding about Subnet Mask,

Watch this Video Lecture

 

Next Article- Practice Problems On Subnet Mask

 

Get more notes and other study material of Computer Networks.

Watch video lectures by visiting our YouTube channel LearnVidFun.

Routing Table in Networking | Examples

Subnetting in Networking-

 

Before you go through this article, make sure that you have gone through the previous article on Subnetting.

 

We have discussed-

  • Subnetting is a process of dividing a single network into multiple smaller networks.
  • The number of sub networks created depends upon the requirement.

 

 

Arrangement Of Subnets-

 

  • All the subnets are connected to an internal router.
  • Internal router is connected to an external router.
  • The link connecting the internal router with a subnet is called as an interface.

 

Example-

 

 

Working-

 

When a data packet arrives,

  • External router forwards the data packet to the internal router.
  • Internal router identifies the interface on which it should forward the incoming data packet.
  • Internal router forwards the data packet on that interface.

 

Routing Table-

 

  • A table is maintained by the internal router called as Routing table.
  • It helps the internal router to decide on which interface the data packet should be forwarded.

 

Routing table consists of the following three fields-

  1. IP Address of the destination subnet
  2. Subnet mask of the subnet
  3. Interface

 

Also Read- Subnet Mask

 

Example-

 

Consider a network is subnetted into 4 subnets as shown in the above picture.

 

The IP Address of the 4 subnets are-

  1. 200.1.2.0 (Subnet A)
  2. 200.1.2.64 (Subnet B)
  3. 200.1.2.128 (Subnet C)
  4. 200.1.2.192 (Subnet D)

 

Then, Routing table maintained by the internal router looks like-

 

Destination Subnet Mask Interface
200.1.2.0 255.255.255.192 a
200.1.2.64 255.255.255.192 b
200.1.2.128 255.255.255.192 c
200.1.2.192 255.255.255.192 d
Default 0.0.0.0 e

Routing Table Example

 

When a data packet arrives to the internal router, it follows the following steps-

 

Step-01:

 

Router performs the bitwise ANDing of-

  • Destination IP Address mentioned on the data packet
  • And all the subnet masks one by one.

 

Step-02:

 

Router compares each result with their corresponding IP Address of the destination subnet in the routing table.

Then, following three cases may occur-

 

Case-01:

 

If there occurs only one match,

  • Router forwards the data packet on the corresponding interface.

 

Case-02:

 

If there occurs more than one match,

  • Router forwards the data packet on the interface corresponding to the longest subnet mask.

 

Case-03:

 

If there occurs no match,

  • Router forwards the data packet on the interface corresponding to the default entry.

 

Important Notes-

 

Note-01:

 

In fixed length subnetting,

  • All the subnets have the same subnet mask.
  • So, bitwise ANDing is performed only once.

 

If the result matches to any of the destination subnet IP Address,

  • Router forwards the data packet on its corresponding interface.
  • Otherwise, it is forwarded on the default interface.

 

Note-02:

 

In variable length subnetting,

  • All the subnets do not have the same subnet mask.
  • So, bitwise ANDing is performed once with each subnet mask.
  • Then, the above three cases are followed.

 

Note-03:

 

  • A host may also be directly connected to the router.
  • In that case, there exists a host specific route from the router to the host.
  • Router saves the IP Address of that host in the “Destination Network” column.
  • Router saves 255.255.255.255 in the “Subnet Mask” column.
  • The ANDing of its destination address and subnet mask yields the IP Address of the host.
  • When a data packet arrives for that specific host, bitwise ANDing is performed.
  • When the result of ANDing is the IP Address of the host, packet is forwarded to its host specific route.

 

Note-04:

 

  • Subnet mask for default route = 0.0.0.0
  • Subnet mask for host specific route = 255.255.255.255

 

PRACTICE PROBLEMS BASED ON ROUTING TABLE-

 

Problem-01:

 

A router uses the following routing table-

 

Destination Mask Interface
144.16.0.0 255.255.0.0 eth0
144.16.64.0 255.255.224.0 eth1
144.16.68.0 255.255.255.0 eth2
144.16.68.64 255.255.255.224 eth3

 

A packet bearing a destination address 144.16.68.117 arrives at the router. On which interface will it be forwarded?

  1. eth0
  2. eth1
  3. eth2
  4. eth3

 

Solution-

 

Router performs the bitwise ANDing of-

  • Destination address mentioned on the data packet
  • And each subnet mask one by one.

 

1st Row-

 

144.16.68.117 AND 255.255.0.0

= 144.16.0.0

Since result is same as the given destination address, so a match occurs.

 

2nd Row-

 

144.16.68.117 AND 255.255.224.0

= 144.16.64.0

Since result is same as the given destination address, so a match occurs.

 

3rd Row-

 

144.16.68.117 AND 255.255.255.0

= 144.16.68.0

Since result is same as the given destination address, so a match occurs.

 

4th Row-

 

144.16.68.117 AND 255.255.255.224

= 144.16.68.96

Since result is not same as the given destination address, so a match does not occur.

 

Now,

  • Clearly, there occurs more than one match.
  • So, router forwards the packet on the interface corresponding to the longest subnet mask.
  • Out of all, 255.255.255.0 is the longest subnet mask since it has maximum number of 1s.

 

So,

  • Router forwards the packet on the interface corresponding to the subnet mask 255.255.255.0.
  • The corresponding interface is eth2.

 

Thus, Option (C) is correct.

 

Problem-02:

 

The routing table of a router is shown below-

 

Destination Mask Interface
128.75.43.0 255.255.255.0 eth0
128.75.43.0 255.255.255.128 eth1
192.12.17.5 255.255.255.255 eth3
default eth2

 

On which interfaces will the router forward packets addressed to destination 128.75.43.16 and 192.12.17.10 respectively?

  1. eth1 and eth2
  2. eth0 and eth2
  3. eth0 and eth3
  4. eth1 and eth3

 

Solution-

 

Router performs the bitwise ANDing of-

  • Destination address mentioned on the data packet
  • And each subnet mask one by one.

 

Packet With Destination Address 128.75.43.16-

 

1st Row-

 

128.75.43.16 AND 255.255.255.0

= 128.75.43.0

Since result is same as the given destination address, so a match occurs.

 

2nd Row-

 

128.75.43.16 AND 255.255.255.128

= 128.75.43.0

Since result is same as the given destination address, so a match occurs.

 

3rd Row-

 

128.75.43.16 AND 255.255.255.255

= 128.75.43.16

Since result is not same as the given destination address, so a match does not occur.

 

Now,

  • Clearly, there occurs more than one match.
  • So, router forwards the packet on the interface corresponding to the longest subnet mask.
  • Out of all, 255.255.255.128 is the longest subnet mask since it has maximum number of 1s.

 

So,

  • Router forwards the packet on the interface corresponding to the subnet mask 255.255.255.128.
  • The corresponding interface is eth1.

 

Packet With Destination Address 192.12.17.10-

 

1st Row-

 

192.12.17.10 AND 255.255.255.0

= 192.12.17.0

Since result is not same as the given destination address, so a match does not occur.

 

2nd Row-

 

192.12.17.10 AND 255.255.255.128

= 192.12.17.0

Since result is not same as the given destination address, so a match does not occur.

 

3rd Row-

 

192.12.17.10 AND 255.255.255.255

= 192.12.17.10

Since result is not same as the given destination address, so a match does not occur.

 

Now,

  • Clearly, there occurs no match.
  • So, router forwards the packet on the interface corresponding to the default entry.
  • The corresponding interface is eth2.

 

Thus, Option (A) is correct.

 

Problem-03:

 

Host specific route has a subnet mask of _____ in the routing table.

  1. 255.255.255.255
  2. 0.0.0.0
  3. 255.0.0.0
  4. 0.0.0.255

 

Solution-

 

Option (A) is correct.

 

Problem-04:

 

Default route has a subnet mask of _____ in the routing table.

  1. 255.255.255.255
  2. 0.0.0.0
  3. 255.0.0.0
  4. 0.0.0.255

 

Solution-

 

Option (B) is correct.

 

Problem-05:

 

Default route can be described as-

  1. Destination values of 0.0.0.0 in the routing table
  2. It can be used if network has only one next hop router
  3. It is useful in keeping routing table small
  4. All of the above

 

Solution-

 

Option (D) is correct.

 

To gain better understanding about Routing Table,

Watch this Video Lecture

 

Next Article- Use of Subnet Mask

 

Get more notes and other study material of Computer Networks.

Watch video lectures by visiting our YouTube channel LearnVidFun.