Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 94

IP Addressing, Subnetting, and Routing Algorithms

Recommended resources

Welcome to our next lesson in the Computer Networks module. In our previous session, we established a strong foundation in the Data Link Layer (Layer 2), analyzing how protocols like GBN, SR, and CSMA/CD ensure reliable communication over a single physical link. Today, we ascend the network stack to the crucial Network Layer (Layer 3), the backbone of the internet.

This lesson focuses on two of the Network Layer's most fundamental responsibilities. First, we'll master the practical skill of IP addressing and subnetting, which allows us to logically divide large networks and efficiently manage addresses. Second, we'll delve into the core routing algorithms that routers use to determine the best path for data packets to travel across complex networks. Our goal is to equip you to calculate subnet masks and IP address ranges for given requirements and trace routing using Distance Vector and Link State algorithms. These topics are a consistent source of numerical and conceptual questions in the GATE exam.

Part 1: IP Addressing and Subnetting

At the heart of the Network Layer is the Internet Protocol (IP), and its addressing scheme is what gives every device on the internet a unique identity. An IPv4 address is a 32-bit number, commonly written in dotted-decimal notation (e.g., 192.168.1.1). This address has two parts: a Network ID that identifies the network the device belongs to, and a Host ID that identifies the specific device on that network.

The subnet mask is the tool we use to separate these two parts. In modern networking, we use Classless Inter-Domain Routing (CIDR), where the subnet mask is represented by a slash followed by a number (e.g., /24). This number indicates how many of the 32 bits are part of the Network ID.

Why Subnet?
Imagine an organization is given a large block of addresses, like 150.100.0.0/16. This single network can support hosts—over 65,000 devices! Placing them all in one broadcast domain would be a performance and security nightmare. Subnetting allows us to "borrow" some of the host bits to create multiple smaller, logical subnetworks. This improves organization, enhances security by isolating networks, and reduces broadcast traffic.

To succeed in GATE questions on this topic, you must be able to perform these key calculations for any given subnet:

  1. Network ID: The first address of the subnet.
  2. Broadcast ID: The last address of the subnet.
  3. Valid Host Range: The range of usable IP addresses between the Network ID and Broadcast ID.
  4. Subnet Mask: The mask corresponding to the CIDR notation.

The following video provides a comprehensive, step-by-step tutorial on how to perform these calculations.

SUBNETTING In Computer Network | How To Find Subnet Mask, Network ID, Host IP Address & Broadcast ID

This video from NETWORKING PLUS is an excellent tutorial that walks through a complete subnetting problem. It clearly explains how to derive the subnet mask, network ID, host range, and broadcast ID from a given IP address and requirement.

Watch the video from start to finish. The example provided covers the entire process you'll need to master. Pay close attention to how the "borrowed" bits for the subnet are used to create the new subnet mask and how the remaining bits define the host range.

Tying it Together: A GATE-Style Example

Let's consolidate the process with a typical problem.

Problem: An organization is assigned the network block 202.41.32.0/24. It needs to create 8 subnets. For the 5th subnet, find:
a) The subnet mask.
b) The Network ID.
c) The range of valid host IPs.
d) The Broadcast ID.

Solution:

  1. Find the new subnet mask:

    • The original block is /24, meaning 24 bits are for the network part.
    • To create 8 subnets, we need to borrow bits from the host part. The number of bits to borrow, , must satisfy . Here, bits are required ().
    • The new subnet mask will be the original 24 bits plus the 3 borrowed bits: . So, the new mask is /27.
    • In dotted-decimal, a /27 mask is 255.255.255.224 (since 27 ones are 11111111.11111111.11111111.11100000).
  2. Analyze the subnets:

    • With a /27 mask, there are bits left for hosts.
    • The number of hosts per subnet is . The block size (total addresses per subnet) is .
    • The subnets will start at multiples of 32 in the last octet:
      • Subnet 0: 202.41.32.0
      • Subnet 1: 202.41.32.32
      • Subnet 2: 202.41.32.64
      • Subnet 3: 202.41.32.96
      • Subnet 4 (the 5th subnet): 202.41.32.128
  3. Determine the addresses for the 5th subnet (Subnet 4):

    • Network ID: This is the starting address: 202.41.32.128.
    • Broadcast ID: This is the last address before the next subnet starts. The next subnet is at .160, so the broadcast ID is 202.41.32.159. (Alternatively, Network ID + Block Size - 1 = 128 + 32 - 1 = 159).
    • Valid Host Range: The addresses between the Network ID and Broadcast ID.
      • First Host IP: 202.41.32.129 (Network ID + 1)
      • Last Host IP: 202.41.32.158 (Broadcast ID - 1)
      • Range: 202.41.32.129 to 202.41.32.158.

This methodical approach is key to solving any subnetting question accurately.


Part 2: Routing Algorithms

Once we have our addresses, how do packets find their way from a source IP to a destination IP, possibly traversing dozens of networks? This is the job of routing algorithms, which run on routers to build and maintain routing tables. These tables tell the router which outgoing interface to use for any given destination network. We'll focus on the two main classes of dynamic routing algorithms: Distance Vector and Link State.

The video below explains both approaches with clear examples and concludes with a crucial comparison.

CN 20 : Distance Vector VS Link State Routing | Examples

This tutorial by Vrushali from "CS & IT Tutorials" provides an excellent comparative analysis of Distance Vector and Link State routing. It explains the underlying logic, walks through an example for each, and summarizes their key differences.

To get the most out of this video, please watch it in three parts: Distance Vector Routing: Focus on the core idea of sharing routing tables with immediate neighbors. Notice how the routing table is built iteratively based on information from adjacent routers. The algorithm mentioned, Bellman-Ford, is the theoretical basis for this approach. Link State Routing: Grasp the concept of "flooding" Link State Packets (LSPs). Each router builds a complete map of the network topology and then uses an algorithm like Dijkstra's to compute the shortest path from itself to all other nodes. Final Comparison: This section summarizes the critical differences in knowledge, algorithm, convergence speed, and traffic overhead. This is a high-yield summary for your exam notes.

Distilling the Concepts: Distance Vector vs. Link State

Let's summarize the key distinctions you've just seen, which are essential for GATE.

Distance Vector (DV) Routing

  • Analogy: "Routing by rumor" or knowing the way from a signpost.
  • Knowledge: Each router has local knowledge. It knows the cost (distance) to its immediate neighbors, but relies on those neighbors' routing tables for information about the rest of the network. It doesn't have a view of the entire network topology.
  • Mechanism: Routers periodically exchange their entire routing tables with their directly connected neighbors. Upon receiving a table, a router updates its own table if a neighbor has found a shorter path to a destination.
  • Underlying Algorithm: Bellman-Ford algorithm. This is why it can handle negative edge weights (though not negative cycles) but is susceptible to the count-to-infinity problem, where bad news (like a link failure) propagates very slowly through the network.
  • Example Protocol: RIP (Routing Information Protocol).

Link State (LS) Routing

  • Analogy: "Everyone has the full map."
  • Knowledge: Each router has global knowledge. Through a process called flooding, every router receives information about every other router and every link in the network. This allows each router to construct an identical, complete map of the network topology.
  • Mechanism:
    1. Routers discover their neighbors and the cost to reach them.
    2. This information is packaged into a Link State Packet (LSP).
    3. The LSP is "flooded" (broadcast) to all other routers in the network.
    4. Each router independently runs Dijkstra's algorithm on its complete map to calculate the shortest path to every other destination.
  • Underlying Algorithm: Dijkstra's algorithm. This is computationally more intensive but provides faster convergence and is more robust than DV.
  • Example Protocol: OSPF (Open Shortest Path First).
Feature Distance Vector (e.g., RIP) Link State (e.g., OSPF)
Knowledge Local (only knows about neighbors) Global (knows entire topology)
Information Shared Entire routing table Only link state changes (LSPs)
Sharing With neighbors only With all routers (flooding)
Algorithm Bellman-Ford Dijkstra's
Convergence Slow, prone to count-to-infinity Fast
Complexity Simple logic, less computation More complex, CPU/memory intensive
Scalability Poor, not suitable for large networks Good, suitable for large networks

Conclusion

Today, we journeyed into the core of the internet's architecture—the Network Layer. You learned the indispensable skill of subnetting, which is fundamental for network design and a frequent source of marks in GATE. You also dissected the two primary strategies routers use to navigate the internet's vast web of connections.

Here are your key takeaways:

  • Subnetting: A CIDR address (e.g., /27) tells you the size of the network portion. You can borrow host bits to create subnets. For any subnet, you must be able to calculate its Network ID, Broadcast ID, and the valid host range. The block size () is your key to moving between subnets.
  • Distance Vector (DV): Routers share their entire tables with neighbors. It's simple but converges slowly. Think "routing by rumor" and Bellman-Ford.
  • Link State (LS): Routers share small updates about their local links with everyone. Each router builds a full map and runs Dijkstra's. It's complex but converges quickly. Think "everyone has the map."

In our previous lesson, we covered Layer 2. Today, we covered Layer 3. In our next lesson, we will continue up the stack to Layer 4 (Transport Layer), exploring how TCP and UDP provide end-to-end communication services. We will also look at essential helper protocols like ARP and ICMP that support the network layer, and deep-dive into the famous TCP 3-way handshake.