Computer Network : Module 2(Part-2)
Subnetting :
What is a Subnet?
A subnet (short for subnetwork) is a smaller network that is created from a larger IP
network.
In simple terms:
A subnet is a section of an IP network where all the devices share the same network
address and communicate directly.
✅Why Subnetting?
Subnetting helps to:
Organize networks logically
Improve performance by reducing traffic
Enhance security (by isolating parts of a network)
Use IP address space more efficiently
Example:
Let’s say you are given a large network:
[Link]/24
This means:
IP range: [Link] to [Link]
256 addresses total
Usable for hosts: 254 (excluding .0 for network, .255 for broadcast)
Now you subnet it into two parts:
You apply a new subnet mask: /25
→ Which gives you:
Subnet 1:
Network: [Link]/25
Range: [Link] – [Link]
Usable IPs: 126
Subnet 2:
Network: [Link]/25
Range: [Link] – [Link]
Usable IPs: 126
This is subnetting: dividing a big network into smaller networks.
Subnet = Network + Subnet Mask
A subnet is always described by:
A Network Address (e.g., [Link])
A Subnet Mask (e.g., [Link] or /24)
Subnet Mask Role
A subnet mask tells:
Which part of an IP address is the network ID
Which part is the host ID
Example:
IP Address: [Link]
Subnet Mask: [Link] (/24)
→ Network ID: [Link]
→ Host ID: 10 (within the subnet)
✅Summary
Term Meaning
Subnet A smaller network within a larger one
Purpose Efficiency, security, traffic separation
Created by Applying a subnet mask
Example [Link]/24 → 1 subnet with 254 hosts
✅Yes, you absolutely can classify your local home network into subnets!
But whether you should depends on your needs. Let's break it down.
Your Home Network – Typical Setup:
Usually:
You have a router (e.g., from your ISP)
It gives IP addresses like 192.168.0.x or 192.168.1.x
All devices (laptops, phones, smart TVs, etc.) are on one subnet — e.g.,
[Link]/24
So everyone shares:
Same network ID ([Link])
Subnet mask: [Link]
This means all devices can freely communicate with each other inside the LAN.
Why Subnet at Home?
You can manually create subnets for:
Use Case Why it helps
Kids’ devices vs. adults Control access or filtering
Work vs. personal Separate sensitive work devices
IoT/smart home devices Extra security/isolation
Gaming consoles Prioritize traffic (QoS)
How to Create Subnets at Home
Option 1: Use VLANs (Virtual LANs)
Most modern routers/firewalls (like Ubiquiti, ASUS, MikroTik) support VLANs.
You can assign:
o [Link]/24 for phones/laptops
o [Link]/24 for IoT devices
Devices in one VLAN can’t see others (unless you allow them)
This gives real isolation between subnet groups.
Option 2: Use Static IP Ranges
Not true subnetting, but:
You manually assign ranges:
o [Link] - [Link] → Family devices
o [Link] - [Link] → Guests
Useful for basic organization or DHCP reservations
Option 3: Change Subnet Mask (advanced)
You can split [Link]/24 into smaller subnets (e.g., /25, /26)
Requires advanced router firmware (e.g., OpenWRT, pfSense)
Limitations
Challenge Notes
Consumer router support Most basic routers don't support VLANs
Complexity Subnetting adds config overhead
Benefit vs effort Only valuable if you need separation
✅Summary
Yes, you can subnet your home network
Use VLANs or custom subnet masks with supported routers
Helps in security, traffic control, and device management
Not necessary for basic use, but useful for tech-savvy setups
1. Subnet Masks Are Given or Chosen
In real-world scenarios, you don’t calculate the subnet mask from the IP address. Instead:
The network engineer or your ISP assigns the subnet mask.
Or, you choose the subnet mask based on how many devices (hosts) you need in your
network.
What is Subnet Mask?
A subnet mask determines how many bits in the IP address are used to identify the network and
how many for the host (device).
Example:
IP Address Subnet Mask CIDR
[Link] [Link] /24
Subnet mask: [Link] = Binary: 11111111.11111111.11111111.00000000
First 24 bits (1s) → Network portion
Last 8 bits (0s) → Host portion
So:
Network portion: 192.168.1
Host portion: 10 (out of possible 0–255)
What is Subnet ID (or Network ID)?
The subnet ID (or network address) is the first IP address in a subnet — it identifies the subnet.
How to find Subnet ID?
You AND the IP address with the subnet mask.
Example:
IP Address: [Link] → 11000000.10101000.00000001.00001010
Subnet Mask: [Link] → 11111111.11111111.11111111.00000000
---------------------------------------------------------
Subnet ID: [Link] → 11000000.10101000.00000001.00000000
So the subnet is [Link]/24
Subnet Table Example
Subnet Mask CIDR Hosts per Subnet No. of Subnets
[Link] /24 254 1
[Link] /25 126 2
[Link] /26 62 4
[Link] /27 30 8
[Link] /28 14 16
Formula to calculate:
Hosts per subnet = 2ⁿ - 2 (where n = number of 0s in subnet mask)
No. of subnets = 2^borrowed bits
Summary
Term Meaning
Subnet A smaller network within a larger network
Subnet Mask A 32-bit number to divide IP into network + host
Subnet ID The starting address of the subnet (first IP, all host bits set to 0)
No. of Subnets = 2^Borrowed Bits — What does it mean?
This formula is used when you subdivide a network (i.e., do subnetting). To create subnets, you
borrow bits from the host portion of the IP address and use them as network bits.
✅ Step-by-Step Explanation
Example Setup:
You are given a network:
Network: [Link]/24
Subnet Mask: [Link]
This is a Class C network. By default, it uses /24, which means:
First 24 bits = network
Last 8 bits = host (2⁸ = 256 addresses, 254 usable hosts)
Now, let’s say you want to create smaller subnets, e.g., subnets with 64 hosts.
✅Step 1: Determine how many bits to borrow
You want 64 hosts per subnet.
We use the formula:
Number of hosts per subnet = 2^n - 2 → (where n = host bits)
To get 64 hosts:
Total IP needed : 64+2=66
2^n - 2 = 64 → 2^n = 66 → n = 7
That means you need 7 bits for hosts.
Originally, we had 8 bits for hosts (in /24), and now we're using only 7.
So:
1 bit is borrowed from the host portion
New subnet mask = /25 (24 + 1)
✅Step 2: Calculate Number of Subnets
Now use:
Number of subnets = 2^borrowed bits = 2^1 = 2
So, subnetting /24 into /25 gives 2 subnets:
1. [Link]/25 → Hosts: [Link] – [Link]
2. [Link]/25 → Hosts: [Link] – [Link]
General Example
If you borrow 3 bits, then:
2^3 = 8 subnets
If you borrow 5 bits, then:
2^5 = 32 subnets
Why “borrow”?
In the original address, bits after the default subnet mask are meant for host addresses. When
you take some of these bits and start treating them as part of the network, you're “borrowing”
them to create subnets.
Summary
Borrowed Bits Resulting Subnets
1 2
2 4
3 8
4 16
5 32
6 64
Can we keep only one subnet with IP [Link]/25 ?
Let’s break it down.
IP: [Link]/25
IP address: [Link]
Subnet mask: /25 = [Link]
Binary mask: 11111111.11111111.11111111.10000000
That means:
First 25 bits = Network
Last 7 bits = Host
Total host addresses = 2⁷ = 128 → 126 usable (excluding network and broadcast)
Can we have only one subnet?
If you're using /25, then by definition, you've split a /24 (i.e., [Link]–[Link]) into
two subnets:
✅Two /25 subnets:
Subnet # Network Address Range of Usable IPs Broadcast Address
Subnet 1 [Link]/25 [Link] – [Link] [Link]
Subnet 2 [Link]/25 [Link] – [Link] [Link]
Your IP [Link] lies in the second subnet ([Link]/25).
So:
/25 always results in 2 subnets.
If you want only 1 subnet, you'd use /24 or something larger (e.g., /23, /22).
✅So the answer is:
No, if you're using /25, you inherently have 2 subnets.
If you want to keep the entire [Link]–[Link] range as one single subnet, then you'd
need to use /24 instead.
I want to divide/Classified the Network ([Link]/24 ) in such a way that every subnet
should consist of max 30 devices.
[Link]/24 → Total of 256 IPs (254 usable)
And your requirement is:
Each subnet should support 30 devices
Step 1: How many IPs are needed per subnet?
You need 30 usable IP addresses per subnet.
But every subnet also needs:
1 IP for network address
1 IP for broadcast address
So:
Total required IPs per subnet = 30 + 2 = 32
Step 2: Find the subnet size that gives at least 32 IPs
Use the formula:
Number of IPs per subnet = 2ⁿ (where n = number of host bits)
Try 2⁵ = 32
So you need 5 host bits → Remaining bits = 32 - 5 = 27
✅Therefore, required subnet mask = /27
Which gives:
2⁵ = 32 IPs total
30 usable IPs
Subnet mask: [Link]
Step 3: Subnet the /24 into /27 blocks
Since /27 gives 32 IPs, and /24 has 256 IPs:
Total number of subnets = 256 / 32 = 8 subnets
✅Final Subnets:
Subnet # Network Address Usable IP Range Broadcast Address
1 [Link]/27 [Link] – [Link] [Link]
2 [Link]/27 [Link] – [Link] [Link]
3 [Link]/27 [Link] – [Link] [Link]
4 [Link]/27 [Link] – [Link] [Link]
5 [Link]/27 [Link] – [Link] [Link]
6 [Link]/27 [Link] – [Link] [Link]
7 [Link]/27 [Link] – [Link] [Link]
8 [Link]/27 [Link] – [Link] [Link]
✅Summary
Original network: [Link]/24
Required: Subnets that support 30 devices
New subnet mask: /27 ([Link])
Usable IPs per subnet: 30
Total subnets created: 8
Great question! Let's walk through how to calculate the subnet mask step-by-step, starting
from the basics and then showing methods based on:
1. Number of required subnets
2. Number of hosts per subnet
✅1. What is a Subnet Mask?
A subnet mask defines which part of an IP address represents the network and which part
represents the host (device).
It’s a 32-bit binary number, written in dotted-decimal (like [Link]) or in CIDR
notation (like /24).
✅2. Subnet Mask Table (Quick Reference)
CIDR Subnet Mask Host Bits Hosts/Subnet
/24 [Link] 8 256 (254 usable)
/25 [Link] 7 128 (126 usable)
/26 [Link] 6 64 (62 usable)
/27 [Link] 5 32 (30 usable)
/28 [Link] 4 16 (14 usable)
/29 [Link] 3 8 (6 usable)
/30 [Link] 2 4 (2 usable)
✅3. Method A: Based on Number of Hosts Required
Formula:
To find the subnet mask for a given number of hosts:
2^n ≥ Number of required hosts + 2 → n = number of host bits
Example: Want 30 hosts?
2^n ≥ 30 + 2 = 32 → n = 5
Total host bits = 5 → So subnet mask is:
32 (total bits) - 5 (host bits) = 27
→ Subnet mask = /27
→ Dotted-decimal = [Link]
✅Result: /27 = [Link] allows for 30 usable hosts
✅4. Method B: Based on Number of Subnets Required
If instead you’re told to create N subnets, use this:
2^n ≥ Number of subnets needed (where, n = number of borrowed bits)
Then:
Add those n bits to the default subnet size of the original class (A, B, or C)
Result = new subnet mask
Example: You want to create 8 subnets from a Class C (/24) network.
2^n ≥ 8 So, n = 3 bits borrowed
So, new subnet mask = 24 + 3 = /27
→ Subnet mask = [Link]
✅5. Converting CIDR to Dotted Decimal
Each octet in binary (8 bits):
Bits Decimal
00000000 0
10000000 128
11000000 192
11100000 224
11110000 240
11111000 248
11111100 252
11111110 254
11111111 255
So:
/24 = [Link]
/27 = [Link]
/30 = [Link]
✅Summary
You Know This... You Use This...
You need X hosts Use 2^n ≥ X + 2, then /32 - n
You need Y subnets Use 2^n ≥ Y, then /Default + n
You have CIDR (e.g., /26) Convert bits to dotted decimal
What is Binary?
Binary is a number system with only two digits: 0 and 1, unlike the decimal system (base-10)
which has 0 to 9.
Each digit in a binary number is called a bit (short for binary digit).
Binary Place Values
Just like decimal place values are powers of 10, binary place values are powers of 2.
Binary Place 2⁷ 2⁶ 2⁵ 2⁴ 2³ 2² 2¹ 2⁰
Decimal Value 128 64 32 16 8 4 2 1
So:
Binary: 11000000
Decimal: 128 + 64 = 192
✅Converting Between Binary and Decimal
1 ⃣ Binary → Decimal
Just add up the values where there’s a 1.
Example:
Binary: 10101000
→ Positions with 1s:
2⁷ + 2⁵ + 2³ = 128 + 32 + 8 = 168
✅Answer: 168
2 ⃣ Decimal → Binary
Break the decimal number down by subtracting the largest powers of 2.
Example: Convert 200 to binary
200 ≥ 128 → 1 (remaining 72)
72 ≥ 64 → 1 (remaining 8)
8 ≥ 8 → 1 (remaining 0)
So the binary is:
128 64 32 16 8 4 2 1
1 1 0 0 1 0 0 0 → 11001000
✅200 = 11001000
➕Basic Binary Arithmetic
1. Addition
Same as decimal, but only two digits:
A B A+B Result Carry
0 0 0 0 0
1 0 1 1 0
1 1 2 0 1
1 + 1 + carry =3 1 1 carry
Example:
1011 (11)
+ 0110 (6)
-------
10001 (17)
2. Subtraction
Just like decimal borrowing.
Example:
1000 (8)
- 0011 (3)
-------
0101 (5)
Real-Life Use: IP Addressing
An IP address like [Link] is made of 4 bytes (octets), each 8 bits:
Octet Binary
192 11000000
168 10101000
1 00000001
1 00000001
So [Link] in binary is:
11000000.10101000.00000001.00000001
This is essential for subnetting, routing, and network calculations.
Summary
Concept What it Means
Binary Base-2 number system (0s and 1s)
Bit One binary digit
Byte 8 bits
Convert Binary ↔ Decimal Use powers of 2
Binary Math Follows rules similar to decimal math but with base 2
What is CIDR?
CIDR stands for Classless Inter-Domain Routing
Introduced in 1993 to replace the old classful IP addressing system.
Instead of dividing IPs into Class A, B, or C, CIDR allows flexible IP address allocation using
variable-length subnet masks.
CIDR Notation
CIDR uses the format:
<IP address>/<number of network bits>
Examples:
[Link]/24 → 24 bits for network, 8 bits for host
[Link]/16 → 16 bits for network, 16 bits for host
How CIDR Works
Example: [Link]/26
Subnet Mask: [Link]
Binary: 11111111.11111111.11111111.11000000
26 bits are used for network
Remaining 6 bits → for hosts
So:
Number of total IPs = 2⁶ = 64
Usable hosts = 64 - 2 = 62
Advantage of CIDR
Advantage Description
Efficient Allocation Assign only the IPs you actually need
Reduced Wastage Prevents over-allocation of unused IP addresses
Flexible Subnetting (VLSM) Different subnet sizes within one network
Route Aggregation Combines multiple routes into one (simplifies routing tables)
Better Routing Performance Smaller routing tables → faster routers
Supports Hierarchical Design Makes IP management easier for large orgs and ISPs
Extends IPv4 Life Delayed exhaustion of IPv4 addresses
CIDR vs. Classful Addressing
Feature Classful (Old) CIDR (Modern)
Fixed Network Sizes Yes (A/B/C classes) No, flexible via CIDR
IP Wastage High Low
Example [Link] (Class C → /24 only) [Link]/26, /27, /28, etc.
Subnetting Allowed Limited Fully supported
✅Benefits of CIDR
1. More Efficient IP Allocation
2. Reduces Waste of IPs
3. Improves Routing Table Size (Route Aggregation)
4. Essential for Modern Subnetting
CIDR Quick Reference Table
CIDR Subnet Mask Total IPs Usable Hosts
/24 [Link] 256 254
/25 [Link] 128 126
/26 [Link] 64 62
/27 [Link] 32 30
/28 [Link] 16 14
/29 [Link] 8 6
/30 [Link] 4 2
Summary
Term Meaning
CIDR Classless Inter-Domain Routing
Format <IP>/<prefix> e.g., [Link]/24
Purpose Flexible subnetting, efficient IP allocation
Benefit Replaces classful addressing; minimizes waste
What is a Demarcation Point (Demarc)?
The Demarcation Point is the physical point where the responsibility shifts from the service
provider to the customer.
Think of it as the official boundary between your network and your Internet Service Provider’s
(ISP) network.
Where is the Demarcation Point?
Usually found in offices, server rooms, or building wiring closets.
For homes, it could be:
o The router or modem installed by your ISP
o Or the network interface device (NID) box outside the building
Simple Analogy
Think of it like the main water valve to your house:
The water company is responsible up to the valve.
You are responsible after it — inside your house.
Similarly:
ISP manages everything up to the demarc
Your IT/network team manages everything after the demarc
What Devices Are Often at the Demarc Point?
Device Role
Modem / Router Translates ISP signal to internal network
Patch panel Connects ISP cable to your local cabling
Network Interface Device (NID) Used in buildings for phone/data demarcation
Summary
Term Meaning
Demarcation Point Physical and logical boundary between ISP and Customer network
Purpose Defines ownership and responsibility
Example Devices Modem, NID, Router, Hand-off switch
Location Office MDF, server room, or home junction box
Routing :
What is a Router?
A router is a network device that forwards data packets between networks based on their
destination IP address.
In simpler terms:
A router connects multiple networks together — like your home network to the Internet —
and decides where data should go.
Basic Role of a Router
Imagine you're sending a letter to someone in another city:
The router is like the post office
It checks the destination address and sends your letter down the right route
Common Real-Life Example
In your home:
You have phones, laptops, TVs all using Wi-Fi
They are connected to a home router
The router connects to your Internet Service Provider (ISP)
All internet requests go through the router
How Does a Router Work? (Step-by-Step)
Step 1: Receives a Data Packet
When a device (like your laptop) sends a packet to, say, [Link], the router receives that
packet.
Step 2: Checks the Destination IP
It looks at the destination IP address in the packet header.
Step 3: Uses a Routing Table
The router has a routing table — a list of networks and directions (called routes).
It checks the best route to reach that destination.
Step 4: Forwards the Packet
The router forwards the packet to the next-hop (another router or device) toward the final
destination.
Step 5: Repeat Until It Reaches Destination
Routers along the path keep doing the same until the packet reaches the final device (like
Google’s server).
Example: You Open YouTube on Your Phone
1. Your phone sends a request for [Link]
2. It goes to your home router
3. Router checks its table → sends it to your ISP
4. ISP’s router → Internet backbone → Google’s data center
5. The response travels back the same way
When we say:
"The router connects to your Internet Service Provider (ISP)",
we mean that the router acts as the gateway between your private network (home, office, etc.)
and the public internet, which is managed by your ISP.
Let’s break it down:
What is an ISP?
An Internet Service Provider (ISP) is a company that gives you access to the internet.
Examples include:
Jio, Airtel, BSNL (in India)
Comcast, AT&T (in the US)
The ISP owns infrastructure that connects to the global internet — such as fiber optics, data
centers, and core routers.
What Does the Router Connect To?
Router connects to the ISP’s modem or fiber terminal:
Home Setup Connection
Your devices (PC, phone) → Wi-Fi or LAN port on your router
Your router → ISP modem or fiber ONT (Optical Network Terminal)
Modem/ONT → ISP’s backbone network (then the internet)
Core Functions of a Router
Function Description
Routing Forwards packets between networks using IP addresses
NAT (Network Address Converts private IPs to public IPs (for internet access)
Translation)
DHCP Assigns IP addresses to devices in local network (optional
feature)
Firewall Blocks/filters malicious or unwanted traffic (in most
routers)
Wireless Access Point Some routers combine Wi-Fi access along with routing
(home routers)
Types of Routers
Type Where It's Used Example
Home Router Small offices, homes TP-Link, Netgear, D-Link, etc.
Edge Router Between enterprise & ISP Cisco ISR, Juniper Edge Router
Core Router At ISP or backbone level High-speed Internet routers
Virtual Router Software-based (in cloud) Virtual network in AWS, GCP
Summary
Concept Meaning
What is a Router A device that forwards data between networks using IPs
Main Job Routes data based on destination address
Uses IP Table Called a routing table, shows best path to each network
Real-world Use Your router connects all home devices to the internet
Bonus Features NAT, DHCP, Firewall, Wi-Fi, etc.
What Is a Routing Path?
A routing path is the sequence of routers and networks that a packet takes to go from the
source to the destination.
Think of it like Google Maps for data — each router decides the next turn (next hop) until it
reaches the final destination.
Example Scenario:
Let’s say:
You open your browser and visit [Link]
Your laptop is connected to Wi-Fi router, which is connected to your ISP
Google’s servers are somewhere in a data center
Step-by-Step: Basic Routing Path
Step 1: Host sends packet
Your laptop sends a packet to Google's IP (e.g., [Link]).
Destination IP is NOT on your local network
So the packet is sent to your default gateway (your router)
Step 2: Router receives the packet
Your home router receives the packet.
It checks its routing table
It finds a route for "any external IP" (usually via the WAN interface)
It forwards the packet to the ISP
Step 3: ISP forwards to next-hop router
Your ISP’s router receives the packet.
It uses BGP (Border Gateway Protocol) to find the best path
Forwards the packet to a backbone router (tier-1 or tier-2 ISP)
Step 4: Packet travels through internet backbone
The packet may pass through multiple routers across countries/data centers.
Each router checks the destination IP
Forwards to the next hop
This continues until it reaches Google’s edge router
Step 5: Destination network receives it
Google’s router receives the packet.
It routes it internally (possibly through a load balancer)
Finally, the correct server receives the packet
Step 6: Server responds
Google’s server sends back a response to your IP address.
This response packet follows a similar routing path in reverse
May or may not follow the exact same route (routing is dynamic)
Summary of Routing Path
Step Device Role
1 Laptop Creates packet for external IP
2 Home Router Forwards to ISP
3 ISP Router Routes to internet backbone
4 Core Internet Routers Hops across global networks
5 Destination Router Sends to actual server (e.g., Google)
6 Response Returns Reverse path from Google back to your device
Bonus: Use tracert or traceroute
You can see the routing path using a command:
tracert [Link] # On Windows
traceroute [Link] # On Linux/macOS
This will list each hop (router) your packet passes through.
Layer 3: Network Layer (Where the Router Lives)
A router is a Layer 3 device — it makes decisions based on IP addresses, not MAC addresses
(those are Layer 2).
What Happens at Layer 3 When a Packet Arrives at a
Router?
Let's say a packet arrives at a router interface...
Step 1: Read the IP Header
The router inspects:
Source IP (where it's coming from)
Destination IP (where it needs to go)
TTL (Time To Live)
Protocol field (e.g., TCP, UDP, ICMP)
Step 2: Check Routing Table
Router looks up the destination IP in its routing table.
Each routing table entry contains:
Network destination (e.g., [Link]/24)
Next-hop IP or interface
Metric/cost (if multiple paths exist)
It picks the longest prefix match — the most specific subnet that matches the destination IP.
Step 3: Decrement TTL
TTL (Time To Live) value is reduced by 1.
If TTL reaches 0 → router drops the packet and sends back an ICMP Time Exceeded message.
This prevents packets from looping infinitely in the network.
Step 4: Forward the Packet
Based on routing table:
If it's a directly connected network → router forwards it via that interface
If it's a remote network → router sends the packet to the next-hop router
At this point:
The Layer 3 (IP) header remains mostly unchanged
Layer 2 headers (Ethernet/MAC) are rewritten for the next hop
Summary: Layer 3 Processing Flow in Router
Step Action
Receive Packet Arrives on ingress interface
Inspect IP Header Reads destination IP, TTL, protocol
Lookup Routing Table Finds best route (longest prefix match)
Update TTL TTL - 1; discard if TTL = 0
Re-encapsulate Layer 2 Change Ethernet header for next hop
Forward to Next Hop Send out via appropriate interface
Protocols Used by Routers at Layer 3
Protocol Purpose Layer
IP Core protocol for addressing L3
ICMP Used for diagnostics (e.g., ping) L3
OSPF, BGP, EIGRP Routing protocols to share routing info L3
ARP Resolves IP to MAC (Layer 2 & 3 interaction) L2–L3
Real Example: Routing at Layer 3
Let’s say:
PC1 (IP: [Link]) sends packet to PC2 ([Link])
Both are on different subnets
What the router does:
1. Receives the packet on interface for [Link]/24
2. Reads destination IP: [Link]
3. Routing table says: send via interface for [Link]/24
4. TTL is reduced by 1
5. New Ethernet frame is created (L2), and the same IP packet (L3) is forwarded
A router can (and often does) have two or more different network interfaces, and this is one
of the core functions of a router.
✅Why Would a Router Have Multiple Interfaces?
Because a router’s job is to connect two or more different networks, it needs at least two
interfaces:
Interface Purpose
WAN Interface Connects to the ISP / internet
LAN Interface Connects to your local network (home, office, etc.)
Example: Basic Home Router
Interface IP Address Connected To
eth0 [Link] Your local devices
eth1 [Link] Your ISP’s network
One interface is part of the private network, the other is part of the public internet
What Is a Routing Table?
A routing table is a list maintained by a router that tells it where to forward packets based on
their destination IP address.
Think of it as a map or GPS that the router uses to decide the best "next hop" to reach a
destination network.
Structure of a Routing Table
Each entry (route) typically includes:
Field Description
Destination IP network (e.g., [Link]/24)
Next Hop IP of the next router to send the packet to
Interface Outgoing port (e.g., eth0, g0/0)
Metric/Cost Priority or efficiency of the route
Route Type Static, Dynamic (OSPF, BGP), or Connected
Multi-Router Routing Path — Example
Let’s say you have this network layout:
[PC A] → [Router 1] → [Router 2] → [Router 3] → [PC B]
You want to send a packet from PC A to PC B
How Routing Tables Work in This Scenario:
Router 1’s Routing Table
Destination Next Hop Interface
[Link]/24 (PC B) [Link] eth1
[Link]/0 [Link] eth1
For packets to PC B → Send to Router 2
Router 2’s Routing Table
Destination Next Hop Interface
[Link]/24 [Link] eth2
[Link]/24 [Link] eth0
For packets to PC B → Send to Router 3
Router 3’s Routing Table
Destination Next Hop Interface
[Link]/24 — (direct) eth1
Final router delivers it to PC B
✅Important Concepts in Multi-Router Routing
Term Meaning
Next Hop The next router's IP that will handle the packet
Best Path Selection Router picks the lowest-cost (shortest or fastest) path
Recursive Lookup A route may refer to another route’s next hop
Default Route ([Link]/0) Used if no specific match is found
Flow of the Packet
1. PC A sends a packet to [Link] (PC B)
2. Router 1 checks its routing table → sends to Router 2
3. Router 2 forwards to Router 3
4. Router 3 delivers it to PC B (since it’s directly connected)
Summary
Concept Description
Routing Table List of known routes (networks + how to reach them)
Multi-Router Path Packets hop from router to router using routing tables
Next Hop Address of the next router to forward to
Best Path Selected based on metrics (cost, hop count, etc.)
What are eth0, eth1, etc.?
These are network interfaces (also called ports) on a router.
Name Meaning
eth0 Ethernet port 0 (first network interface)
eth1 Ethernet port 1 (second network interface)
eth2 Ethernet port 2, and so on
Each of these interfaces connects the router to a different network or another router.
Breakdown of the Diagram’s Routing Tables
Router 1’s Routing Table (top)
Destination Next Hop Interface
[Link]/24 [Link] eth1
[Link]/0 [Link] eth1
Meaning:
If a packet is destined for 10.0.2.x, send it to [Link] via eth1
If there’s no match (default route [Link]/0), also send it to [Link] via eth1
Router 2’s Routing Table
Destination Next Hop Interface
[Link]/24 directly -
Meaning:
If a packet is for 10.0.3.x (where PC B lives), it’s directly connected, so send it out the
connected interface (e.g., eth1)
Router 3’s Routing Table (bottom left)
Destination Next Hop Interface
[Link]/24 [Link] eth2
[Link]/0 [Link] eth0
Meaning:
To reach the destination network, forward the packet via eth2
Use eth0 as the default route for anything else
Meaning of via eth1 or via eth2
When a routing table says:
Send to [Link] via eth1
It means:
The packet should be forwarded out of the router’s eth1 interface
That interface is connected to the next network or router in the path
The next-hop IP address (in this case, [Link]) is reachable through eth1
✅Example Breakdown:
Let’s say a router has two interfaces:
Interface IP Address Connected To
eth0 [Link] Internal LAN
eth1 [Link] Connected to another router ([Link])
Routing table:
Destination Next Hop Interface
[Link]/24 [Link] eth1
[Link]/0 [Link] eth1
What does this mean?
If the router receives a packet for [Link]:
o It sees that [Link]/24 is not directly connected
o The routing table says → send to next-hop [Link]
o The router sends the packet out of eth1 toward [Link]
If the packet is for any unknown IP address (say [Link]), it matches the default route:
[Link]/0 → also says send to [Link] via eth1
✅So both known ([Link]/24) and unknown (default) traffic are routed through eth1
Why Do Routers Have Multiple Interfaces Like eth0, eth1,
eth2?
Each interface connects to a different network:
Interface Connected Network
eth0 Local subnet (e.g., users, PCs)
eth1 Another router or WAN
eth2 DMZ, Internet, or another subnet
The router uses the correct interface based on:
Where the next-hop IP is located
What the routing table says
✅The router chooses the interface (e.g., eth0, eth1, eth2, etc.) based on the
destination IP address and the routing table.
The Logic: How a Router Decides Which Interface to Use
When a router receives a packet:
1. It checks the destination IP address of the packet.
2. It looks in the routing table for the most specific match (Longest Prefix Match).
3. The routing table entry tells:
o The next hop (could be another router)
o The outgoing interface (e.g., eth1, eth2)
The packet is then sent out through that interface.
So in summary:
"via eth1" means:
Send the packet out through the eth1 port
That’s the port connected to the next hop (e.g., [Link])
Router will re-encapsulate the packet in a new Ethernet frame using eth1’s MAC
address
What Is a Hop in a Router?
A hop is one step or jump that a data packet makes from one router to the next on its journey
from the source to the destination.
So:
If a packet goes through 3 routers before reaching its destination, that means it took 3
hops.
Why Is It Called a "Hop"?
Think of a data packet "hopping" from one router to another like stepping stones in a path.
Each hop represents one forwarding action between routers.
Example: Multi-Router Path
Let’s say you’re sending a packet from your home computer to a website:
[Your PC]
↓
[Home Router] → 1st hop
↓
[ISP Router] → 2nd hop
↓
[Internet Backbone Router] → 3rd hop
↓
[Web Server]
In this example:
The packet made 3 hops to reach the destination.
Each router that processed and forwarded the packet counted as 1 hop.
TTL (Time To Live) and Hop Count
Each IP packet has a TTL (Time To Live) value.
TTL is actually a hop counter:
o Starts at something like 64 or 128
o Each router that handles the packet reduces TTL by 1
o If TTL reaches 0, the packet is dropped and an error is returned.
This prevents infinite loops in case of routing errors.
You Can See Hops with traceroute
Try this in your terminal:
tracert [Link] # On Windows
traceroute [Link] # On Linux/macOS
It will show all the routers (hops) your packet passes through to reach Google.
Example output:
1 [Link] (Your router)
2 [Link] (ISP edge router)
3 [Link] (Backbone router)
...
10 [Link] (Google server)
→ So this route took 10 hops.
✅Summary
Term Meaning
Hop One router the packet passes through
1 hop One step between two routers
TTL Hop counter that prevents infinite loops
Traceroute Tool to see how many hops your packet takes
1. What Are Routing Protocols?
Routing protocols are used by routers to learn and share paths to different networks
automatically.
They are categorized into:
Type Purpose
IGP (Interior Gateway For routing within a single organization or autonomous system
Protocol) (AS)
EGP (Exterior Gateway For routing between different organizations or autonomous
Protocol) systems (ASes)
2. What is an Interior Gateway Protocol (IGP)?
Definition:
IGPs are routing protocols used inside a single Autonomous System (AS) — usually an
enterprise, ISP, or organization's internal network.
Examples of IGPs:
Protocol Type Description
RIP Distance Vector Simple, uses hop count, up to 15 hops
OSPF Link-State Calculates shortest path using Dijkstra
IS-IS Link-State Similar to OSPF, used in larger ISPs
EIGRP Hybrid (Cisco) Combines distance vector + link-state
Where IGPs are used:
Example: A company with 3 branch offices and data centers
[Office 1 LAN]
↕
[Router A] ←→ [Router B] ←→ [Router C]
↕
[Data Center]
All routers are part of the same AS
OSPF or EIGRP runs between them to manage internal routes dynamically
They use metrics like bandwidth or hop count to find best paths
3. What is an Exterior Gateway Protocol (EGP)?
Definition:
EGPs are routing protocols used to connect different autonomous systems — like between two
ISPs, or between a company and an ISP.
Example of EGP:
Protocol Description
BGP The only EGP in use today. It is a path-vector protocol that routes between different
ASes on the internet
Where BGP (EGP) is used:
Example: Your company connects to two ISPs:
[Your Company AS]
|
| (BGP)
↓
[ISP 1 AS] ←→ [Internet]
↑
| (BGP)
[ISP 2 AS]
Your company uses BGP to advertise its public IPs
You can load-balance or failover between ISP 1 and ISP 2 using BGP policies
This is inter-domain routing
Key Differences Between IGP and EGP
Feature IGP EGP (BGP)
Scope Inside an AS (enterprise or ISP) Between ASes (e.g., company ↔
ISP)
Examples RIP, OSPF, EIGRP, IS-IS BGP
Path calculation Shortest path (based on metric) Policy-based, AS path length
Convergence Fast (esp. OSPF) Slow (due to stability focus)
speed
Complexity Moderate High (used for global internet
routing)
Administrative Single organization Multiple organizations (inter-domain)
domain
✅A. Distance Vector Protocols
Concept Description
Shares routes by Distance (hop count) and direction
Router knows Only its neighbors' routes
Updates are Sent periodically to all neighbors
Slower convergence Yes
Loops possible? Yes, uses methods like split horizon or hold-down timers
Examples:
RIP (Routing Information Protocol)
IGRP (Cisco proprietary, obsolete)
✅B. Link-State Protocols
Concept Description
Shares routes by Advertising full topology (state of all links)
Router knows The entire network map
Updates are Sent only when changes occur, not periodically
Faster convergence Yes
Loops possible? Very unlikely (uses SPF algorithm)
Examples:
OSPF (Open Shortest Path First)
IS-IS (Intermediate System to Intermediate System)
Exterior Gateway Protocol (EGP)
These are used to connect different autonomous systems (AS) — for example:
Between two ISPs
Between a company and its ISP
✅BGP — Border Gateway Protocol
Feature Description
Type Path-vector protocol
Used for Internet-level routing (between ASes)
Metric Based on AS path length and policies
Very scalable? ✅Yes
Slow convergence? Yes (but it’s policy-driven and robust)
Example use Google → Airtel → Your ISP → You
Summary Table
Category Protocol Type Protocols Used Where
IGP Distance Vector RIP, IGRP Inside private networks
Link State OSPF, IS-IS Inside private networks
EGP Path Vector BGP Between different ASes (e.g., ISPs)
Visualization: How They Work
[IGP inside company]
└── Router A ←→ Router B ←→ Router C (using OSPF or RIP)
[EGP between companies]
└── Company A ←→ Company B (using BGP)
You’re asking:
If we already have routing protocols like OSPF or RIP (used inside a network), why do we
need BGP?
The short answer is:
BGP is designed for routing between different networks (Autonomous Systems), not within
them.
Let’s explain this fully.
First: Understand the Difference in Scope
Routing Protocol Purpose Scope
Type
IGPs (RIP, Route within a single organization or network Inside a company or ISP's
OSPF, IS-IS) (intra-domain) own network
BGP (EGP) Route between different Between ISPs, data
organizations/networks (inter-domain) centers, clouds, etc.