Achievable logoAchievable logo
CCNA
Sign in
Sign up
Purchase
Textbook
Practice exams
Support
How it works
Exam catalog
Mountain with a flag at the peak
Textbook
Introduction
1. Introduction to networking
2. Administering Ethernet LANs
3. IP connectivity
3.1 Understanding IP addresses
3.2 Calculating networks and hosts
3.3 Routers and IPv4 routing fundamentals
3.4 Static routing
3.5 Static vs. dynamic routing and OSPF fundamentals
3.6 Router redundancy in an Ethernet LAN using First Hop Redundancy Protocols (FHRPs)
3.7 Configuring Cisco Routers
4. Network services
5. IPv6
6. Wireless networking
7. Network management and administering network devices
8. Network security fundamentals
9. Network automation and programmability
Wrapping up
Achievable logoAchievable logo
3.3 Routers and IPv4 routing fundamentals
Achievable CCNA
3. IP connectivity
Our CCNA course is currently in development and is a work-in-progress.

Routers and IPv4 routing fundamentals

9 min read
Font
Discuss
Share
Feedback

As we discussed in Chapter 2.1 Wired Network Access, a router allows devices inside a LAN to communicate with devices outside that LAN. That’s the most common use of a router, so it’s worth understanding why it’s needed and how it makes those connections possible.

Routers take IP packets from one network and route them to another network. They make routing decisions by:

  • Looking at the destination IP address in the IP packet
  • Checking the router’s routing table for a matching destination network
  • Choosing the best available path for that packet

Each interface on a router (often called a router interface) creates a network boundary. Connecting this to Chapter 2.3 VLANs and Trunking: each router interface defines a broadcast domain. Every device connected to the same router interface is in the same network (broadcast domain). The diagram below shows how each router interface leads to a different network.

(Image 143)

Image Title - Router Interfaces leading to multiple networks

Because there’s a 1:1 relationship between router interfaces and networks, anything you connect to a given router interface becomes a member of that network. A different router interface leads to a different network.

A common question is: how do you connect multiple devices to a single router interface? You do it by connecting those devices to a switch, and then connecting the switch to the router. Each host in that network gets an IP address from that network’s address range, and the router interface also has an IP address in that same network.

(Image 144)

Image Title - Multiple hosts connecting to a Router Interface through a Switch

Why a router is needed in a LAN

A router is most commonly used as the gateway between hosts in one network and hosts in another network. From Chapter 2.3 VLANs and Trunking, remember that hosts can only send broadcasts and Ethernet frames directly to each other if they’re in the same broadcast domain (VLAN is synonymous with broadcast domain).

If two hosts aren’t in the same broadcast domain, they can’t use broadcasts to complete ARP with each other. That matters because ARP is how a host learns the destination MAC address it needs at Layer 2 to send an Ethernet frame.

This creates a problem: hosts often need to communicate with devices outside their own network. Routers solve this.

When a host needs to communicate with another host whose IP address is outside its own network, it sends the IP packet to the router. When the router receives the packet, it routes it toward the destination network. Even if the destination network is separated by multiple routers and networks, the packet can still get there - as long as each router along the path knows how to reach the destination.

(Image 145)

Image Title - Router receiving a packet from a host destined to a host in another network

The router interface that faces the hosts within a LAN is also assigned an IP address in the same network as those hosts. The IP address on the router that you configure on the hosts is called the default gateway.

(Image 146)

Image Title - Host configured with R1’s GigabitEthernet 0/0 Router Interface IP Address as its Default Gateway

A key detail is what happens at Layer 2. If a host is sending to a destination on another network, it can’t ARP for the destination host’s MAC address (ARP broadcasts don’t cross router interfaces). So what MAC address does it use in the destination MAC field of the Ethernet frame?

It uses the MAC address of its default gateway (the router). To do that, the host sends an ARP request for the MAC address associated with the default gateway’s IP address. Because the host and the router interface are in the same broadcast domain, the router receives the ARP request and replies directly with an ARP reply.

(Image 147)

Image Title - PC A sending an ARP Request to its Default Gateway

Now that the host (PC A in this case) has resolved it’s default gateway’s (R1’s) associated MAC address, it can then send the actual packet that it intended to send to the destination host, towards the router.

Once the router receives the Ethernet frame containing the data to be routed, it de-encapsulates the frame and extracts the IP packet. Then it looks up the destination network in its routing table. If it finds a matching route, it builds a new Ethernet frame for the next hop, using the outgoing router interface in the direction of the destination network.

(Image 148)

Image Title - R1 performing L2 Rewrite on IP Packet destined to PC B

Pay very close attention to the Source and Destination IP addresses within the IP packet from PC A. The packet is coming from PC A and destined to Server B’s IP address. The IP packet will always contain the “end-to-end” addresses (this will never change by default).

The Destination MAC Address of the original frame however, is addressed to PC A’s default gateway (R1’s GigabitEthernet0/0), so that it can be delivered to R1, in order for R1 to route the packet along the path to it’s destination.

Once R1 has determined where to route the packet (which “exit” interface to use), it must then re-write the Source and Destination MAC address of the frame, since it will be forwarded to a new Ethernet segment, where only those MAC addresses are relevant. This is what is known as “Layer 2 Re-write”.

How to read a routing table

As a CCNA and network administrator, you’ll need to read a routing table on a Cisco router. A routing table lists the networks the router knows how to reach and tells the router which interface to send packets out of to reach those networks.

When a router receives an IP packet, it inspects the destination IP address:

  • If the destination IP address belongs to the router itself, the router processes the packet locally (and responds if needed).
  • If the destination IP address is in a different network, the router looks in its routing table for:
    • A route to the destination host address, or
    • A route to the destination network where that host address belongs

Unlike a switch, if a router can’t find a matching host route or network route, it drops the packet.

By default, routers neither generate nor forward broadcasts. That’s why router interfaces are broadcast domain boundaries: broadcasts don’t get forwarded from one router interface to another.

When you configure an IP address on a router interface, the router automatically adds a routing table entry for the network that interface belongs to. That entry is called a route.

(Image 149)

Image Title - R1 Routing Table displaying the route to 192.168.1.0/24

Let’s break down what the routing table entry is saying:

  • C - means that this is a Directly Connected network on the router. Directly Connected means that the router has an interface configured with an IP address and subnet mask within this network.
  • 192.168.1.0/24 - This is the destination network that the route is targeting.
  • GigabitEthernet0/0 - This is the router interface that packets with destination IP addresses in this network would be sent out of.

The “L” entry in the routing table (192.168.1.1/32) is referring to the “Local” IP address that is locally configured on the router’s interface. In this case, it’s the IP address configured on GigabitEthernet0/0.

Choosing the best route and the longest prefix match

Suppose a router has three routes in its routing table that overlap, but use different subnet masks (different prefix lengths):

  • 172.31.0.0/16
  • 172.31.0.0/24
  • 172.31.0.0/27

They may look similar, but they represent three different networks. Because the prefix lengths differ, the address ranges differ - even though the networks overlap.

Network Address Assignable Range Broadcast Address
172.31.0.0/16 172.31.0.1 - 172.31.255.254 172.31.255.255
172.31.0.0/24 172.31.0.1 - 172.31.0.254 172.31.0.254
172.31.0.0/27 172.31.0.1 - 172.31.0.30 172.31.0.31

Please review Chapter 3.2 Subnetting and Variable Length Subnet Masks (VLSM) if you are having trouble following this concept.

Now say the router receives an IP packet destined to 172.31.0.20. Which route does it choose?

The router chooses 172.31.0.0/27 because it has the longest prefix length of the three routes. This is the primary tie-breaker in routing: the route with the longest prefix length is the most preferred. That rule is called longest prefix match.

Here are the subnet masks in dotted-decimal notation:

  • 255.255.0.0
  • 255.255.255.0
  • 255.255.255.224

In practice, this means the router prefers the subnet mask (prefix length) with the most on-bits (1s), because it describes the most specific destination.

Here are those subnet masks in binary:

  • 11111111 11111111 00000000 00000000
  • 11111111 11111111 11111111 00000000
  • 11111111 11111111 11111111 11100000

One more important point: the destination IP address in the packet must actually fall within the destination network of the route. If it doesn’t, that route isn’t usable.

For example, if the router receives a packet destined to 172.31.0.20 and the routing table only contains this route:

  • C 172.16.1.0/24 is Directly Connected, GigabitEthernet0/0

Would the Router be able to route the packet?

(spoiler)

No

Router basics and routing decisions

  • Routers move IP packets between networks based on destination IP address
  • Uses routing table to find matching destination network, picks best path
  • Each router interface = one network = one broadcast domain (1:1 relationship) and is the boundary of a network

Connecting multiple hosts to a router interface

  • Multiple devices reach a single router interface via a switch
  • Hosts and router interface share same network address range
  • Router interface facing hosts gets an IP in that network — called the default gateway

Why a router is needed in a LAN

  • Hosts in different broadcast domains can’t ARP each other directly
  • Router acts as gateway between networks; forwards packets toward destination
  • Router interface facing hosts = default gateway IP for those hosts
  • Multiple routers/networks can be traversed if each router knows the path

Layer 2 behavior when routing across networks

  • Host can’t ARP for a remote host’s MAC (when it resides in a different network); instead ARPs for default gateway’s MAC
  • Host sends frame addressed (Layer 2) to router MAC, but Layer 3 (IP) addresses remain end-to-end (source/destination unchanged)
  • Router de-encapsulates frame, checks routing table, re-encapsulates with new Layer 2 addressing for next hop
  • This re-addressing process = Layer 2 Re-write

Reading a routing table

  • Table lists known networks + exit interface to reach them
  • If destination is local, router processes it; if remote, looks for matching route
  • No matching route = packet is dropped (unlike switches)
  • Routers don’t forward broadcasts between interfaces
  • Configuring an IP on an interface auto-creates a route:
    • C = directly connected network
    • Network/prefix = destination network
    • Interface = exit interface for that network
    • L = local host route for the interface’s own IP (/32)

Longest prefix match (best route selection)

  • Overlapping routes with different prefix lengths represent different address ranges
  • Router prefers route with longest prefix (most specific match)
  • Longest prefix = subnet mask with most “1” bits
  • Destination IP must actually fall within the route’s network range to be usable
  • If no route matches the destination, packet is dropped

Sign up for free to take 10 quiz questions on this topic

Previous
Next  | 3.4 Static routing
All rights reserved ©2016 - 2026 Achievable, Inc.

Routers and IPv4 routing fundamentals

As we discussed in Chapter 2.1 Wired Network Access, a router allows devices inside a LAN to communicate with devices outside that LAN. That’s the most common use of a router, so it’s worth understanding why it’s needed and how it makes those connections possible.

Routers take IP packets from one network and route them to another network. They make routing decisions by:

  • Looking at the destination IP address in the IP packet
  • Checking the router’s routing table for a matching destination network
  • Choosing the best available path for that packet

Each interface on a router (often called a router interface) creates a network boundary. Connecting this to Chapter 2.3 VLANs and Trunking: each router interface defines a broadcast domain. Every device connected to the same router interface is in the same network (broadcast domain). The diagram below shows how each router interface leads to a different network.

(Image 143)

Image Title - Router Interfaces leading to multiple networks

Because there’s a 1:1 relationship between router interfaces and networks, anything you connect to a given router interface becomes a member of that network. A different router interface leads to a different network.

A common question is: how do you connect multiple devices to a single router interface? You do it by connecting those devices to a switch, and then connecting the switch to the router. Each host in that network gets an IP address from that network’s address range, and the router interface also has an IP address in that same network.

(Image 144)

Image Title - Multiple hosts connecting to a Router Interface through a Switch

Why a router is needed in a LAN

A router is most commonly used as the gateway between hosts in one network and hosts in another network. From Chapter 2.3 VLANs and Trunking, remember that hosts can only send broadcasts and Ethernet frames directly to each other if they’re in the same broadcast domain (VLAN is synonymous with broadcast domain).

If two hosts aren’t in the same broadcast domain, they can’t use broadcasts to complete ARP with each other. That matters because ARP is how a host learns the destination MAC address it needs at Layer 2 to send an Ethernet frame.

This creates a problem: hosts often need to communicate with devices outside their own network. Routers solve this.

When a host needs to communicate with another host whose IP address is outside its own network, it sends the IP packet to the router. When the router receives the packet, it routes it toward the destination network. Even if the destination network is separated by multiple routers and networks, the packet can still get there - as long as each router along the path knows how to reach the destination.

(Image 145)

Image Title - Router receiving a packet from a host destined to a host in another network

The router interface that faces the hosts within a LAN is also assigned an IP address in the same network as those hosts. The IP address on the router that you configure on the hosts is called the default gateway.

(Image 146)

Image Title - Host configured with R1’s GigabitEthernet 0/0 Router Interface IP Address as its Default Gateway

A key detail is what happens at Layer 2. If a host is sending to a destination on another network, it can’t ARP for the destination host’s MAC address (ARP broadcasts don’t cross router interfaces). So what MAC address does it use in the destination MAC field of the Ethernet frame?

It uses the MAC address of its default gateway (the router). To do that, the host sends an ARP request for the MAC address associated with the default gateway’s IP address. Because the host and the router interface are in the same broadcast domain, the router receives the ARP request and replies directly with an ARP reply.

(Image 147)

Image Title - PC A sending an ARP Request to its Default Gateway

Now that the host (PC A in this case) has resolved it’s default gateway’s (R1’s) associated MAC address, it can then send the actual packet that it intended to send to the destination host, towards the router.

Once the router receives the Ethernet frame containing the data to be routed, it de-encapsulates the frame and extracts the IP packet. Then it looks up the destination network in its routing table. If it finds a matching route, it builds a new Ethernet frame for the next hop, using the outgoing router interface in the direction of the destination network.

(Image 148)

Image Title - R1 performing L2 Rewrite on IP Packet destined to PC B

Pay very close attention to the Source and Destination IP addresses within the IP packet from PC A. The packet is coming from PC A and destined to Server B’s IP address. The IP packet will always contain the “end-to-end” addresses (this will never change by default).

The Destination MAC Address of the original frame however, is addressed to PC A’s default gateway (R1’s GigabitEthernet0/0), so that it can be delivered to R1, in order for R1 to route the packet along the path to it’s destination.

Once R1 has determined where to route the packet (which “exit” interface to use), it must then re-write the Source and Destination MAC address of the frame, since it will be forwarded to a new Ethernet segment, where only those MAC addresses are relevant. This is what is known as “Layer 2 Re-write”.

How to read a routing table

As a CCNA and network administrator, you’ll need to read a routing table on a Cisco router. A routing table lists the networks the router knows how to reach and tells the router which interface to send packets out of to reach those networks.

When a router receives an IP packet, it inspects the destination IP address:

  • If the destination IP address belongs to the router itself, the router processes the packet locally (and responds if needed).
  • If the destination IP address is in a different network, the router looks in its routing table for:
    • A route to the destination host address, or
    • A route to the destination network where that host address belongs

Unlike a switch, if a router can’t find a matching host route or network route, it drops the packet.

By default, routers neither generate nor forward broadcasts. That’s why router interfaces are broadcast domain boundaries: broadcasts don’t get forwarded from one router interface to another.

When you configure an IP address on a router interface, the router automatically adds a routing table entry for the network that interface belongs to. That entry is called a route.

(Image 149)

Image Title - R1 Routing Table displaying the route to 192.168.1.0/24

Let’s break down what the routing table entry is saying:

  • C - means that this is a Directly Connected network on the router. Directly Connected means that the router has an interface configured with an IP address and subnet mask within this network.
  • 192.168.1.0/24 - This is the destination network that the route is targeting.
  • GigabitEthernet0/0 - This is the router interface that packets with destination IP addresses in this network would be sent out of.

The “L” entry in the routing table (192.168.1.1/32) is referring to the “Local” IP address that is locally configured on the router’s interface. In this case, it’s the IP address configured on GigabitEthernet0/0.

Choosing the best route and the longest prefix match

Suppose a router has three routes in its routing table that overlap, but use different subnet masks (different prefix lengths):

  • 172.31.0.0/16
  • 172.31.0.0/24
  • 172.31.0.0/27

They may look similar, but they represent three different networks. Because the prefix lengths differ, the address ranges differ - even though the networks overlap.

Network Address Assignable Range Broadcast Address
172.31.0.0/16 172.31.0.1 - 172.31.255.254 172.31.255.255
172.31.0.0/24 172.31.0.1 - 172.31.0.254 172.31.0.254
172.31.0.0/27 172.31.0.1 - 172.31.0.30 172.31.0.31

Please review Chapter 3.2 Subnetting and Variable Length Subnet Masks (VLSM) if you are having trouble following this concept.

Now say the router receives an IP packet destined to 172.31.0.20. Which route does it choose?

The router chooses 172.31.0.0/27 because it has the longest prefix length of the three routes. This is the primary tie-breaker in routing: the route with the longest prefix length is the most preferred. That rule is called longest prefix match.

Here are the subnet masks in dotted-decimal notation:

  • 255.255.0.0
  • 255.255.255.0
  • 255.255.255.224

In practice, this means the router prefers the subnet mask (prefix length) with the most on-bits (1s), because it describes the most specific destination.

Here are those subnet masks in binary:

  • 11111111 11111111 00000000 00000000
  • 11111111 11111111 11111111 00000000
  • 11111111 11111111 11111111 11100000

One more important point: the destination IP address in the packet must actually fall within the destination network of the route. If it doesn’t, that route isn’t usable.

For example, if the router receives a packet destined to 172.31.0.20 and the routing table only contains this route:

  • C 172.16.1.0/24 is Directly Connected, GigabitEthernet0/0

Would the Router be able to route the packet?

(spoiler)

No

Key points

Router basics and routing decisions

  • Routers move IP packets between networks based on destination IP address
  • Uses routing table to find matching destination network, picks best path
  • Each router interface = one network = one broadcast domain (1:1 relationship) and is the boundary of a network

Connecting multiple hosts to a router interface

  • Multiple devices reach a single router interface via a switch
  • Hosts and router interface share same network address range
  • Router interface facing hosts gets an IP in that network — called the default gateway

Why a router is needed in a LAN

  • Hosts in different broadcast domains can’t ARP each other directly
  • Router acts as gateway between networks; forwards packets toward destination
  • Router interface facing hosts = default gateway IP for those hosts
  • Multiple routers/networks can be traversed if each router knows the path

Layer 2 behavior when routing across networks

  • Host can’t ARP for a remote host’s MAC (when it resides in a different network); instead ARPs for default gateway’s MAC
  • Host sends frame addressed (Layer 2) to router MAC, but Layer 3 (IP) addresses remain end-to-end (source/destination unchanged)
  • Router de-encapsulates frame, checks routing table, re-encapsulates with new Layer 2 addressing for next hop
  • This re-addressing process = Layer 2 Re-write

Reading a routing table

  • Table lists known networks + exit interface to reach them
  • If destination is local, router processes it; if remote, looks for matching route
  • No matching route = packet is dropped (unlike switches)
  • Routers don’t forward broadcasts between interfaces
  • Configuring an IP on an interface auto-creates a route:
    • C = directly connected network
    • Network/prefix = destination network
    • Interface = exit interface for that network
    • L = local host route for the interface’s own IP (/32)

Longest prefix match (best route selection)

  • Overlapping routes with different prefix lengths represent different address ranges
  • Router prefers route with longest prefix (most specific match)
  • Longest prefix = subnet mask with most “1” bits
  • Destination IP must actually fall within the route’s network range to be usable
  • If no route matches the destination, packet is dropped

More from IP connectivity

  • Calculating networks and hosts
  • Static routing
  • Static vs. dynamic routing and OSPF fundamentals
  • Router redundancy in an Ethernet LAN using First Hop Redundancy Protocols (FHRPs)