Network Layer Fundamentals

Network Layer Overview

The network layer is the third layer of the OSI reference model. It is mainly responsible for transferring packets between different networks and providing end-to-end communication.


1. Core Functions of the Network Layer

1.1 Heterogeneous Internetworking: the “Translator” of the Network World

Heterogeneous Internetworking

Heterogeneous internetworking means that the network layer can connect networks of different types, protocols, and technologies so that they can communicate with each other. Just as people from different countries need a translator to talk, different networks need the network layer to “translate”.

Why Is Heterogeneous Internetworking Needed?

Many kinds of network exist in the real world:

Network typeCharacteristicsApplication scenario
EthernetWired, high speed, low costHome and office LANs
Wi-FiWireless, flexible, highly mobileHomes and public places
Fiber networkUltra-high speed, long distance, costlyBackbone networks and data centers
Mobile network4G/5G, wide coverage, mobilityMobile internet access
Satellite networkGlobal coverage, high latency, costlyNavigation and remote areas

These networks are like different languages that cannot talk to each other directly. Through the uniform IP protocol, the network layer makes the languages interoperable.

The IP Protocol: the “Common Language” of the Network

Key Technologies for Heterogeneous Internetworking

1. Address translation

Different networks use different address formats:

  • Ethernet: MAC address (48 bits, for example 00:1A:2B:3C:4D:5E)
  • IP networks: IP address (32-bit IPv4 or 128-bit IPv6)
  • Telephone networks: telephone number

The network layer performs address translation through the ARP protocol: IP address → ARP protocol → MAC address, for example: 192.168.1.1 → query → 00:1A:2B:3C:4D:5E.

2. Data encapsulation

Different networks use different data formats, so the network layer encapsulates them uniformly:

Raw Data
IP Packet
Ethernet Frame
Wi-Fi Frame
Fiber Frame

Like a courier parcel:

  • the contents are the goods (raw data)
  • the outer layer is the courier box (the IP packet)
  • the outer layer of that is the transport container (the Ethernet frame)
  • the container changes with the transport method

3. Protocol conversion

The network layer converts between different protocols:

  • TCP/IP ↔ IPX/SPX
  • IPv4 ↔ IPv6
  • Wired ↔ wireless

1.2 Routing and Packet Forwarding: the “Navigation System” for Packets

Routing

Routing is the process of choosing the best path from source to destination for a packet. It is like navigation software planning the best route for you.

How Routing Works

An analogy with navigation software:

Navigation functionNetwork layer equivalent
Plan a routeThe routing algorithm (RIP, OSPF)
Choose a roadChoosing the router path
Avoid congestionAvoiding congested nodes
Update traffic conditionsUpdating the routing table
Multiple routesMulti-path routing

The routing process:

Read the destination IP
Look up the routing table
Choose the best path
Determine the next hop
Forward the packet

The Packet Forwarding Mechanism

Packet Forwarding

Packet forwarding moves a packet from one router to the next until it reaches the destination. It is like a parcel travelling through several transit stations on its way to the recipient.

A forwarding example:

Suppose you are sending a parcel from Beijing to Guangzhou:

NodeYour computerBeijing routerShijiazhuang routerWuhan routerGuangzhou server
Parcel analogyBeijing shipping stationShijiazhuang transit stationWuhan transit station—Guangzhou receiving station
IP address192.168.1.1010.1.1.110.2.2.210.3.3.3172.16.1.100

The packet leaves your computer and passes through the Beijing, Shijiazhuang, and Wuhan routers in turn before reaching the Guangzhou server.

The forwarding procedure at each router:

  1. Receive the packet
  2. Extract the destination IP address
  3. Look up the routing table
  4. Choose the next-hop router
  5. Encapsulate the packet
  6. Send it to the next hop

The Structure of the Routing Table

A router maintains a routing table that records information about the network topology:

Destination networkNext hopInterfacePriority
192.168.1.0/24Directly connectedeth00
10.0.0.0/810.1.1.1eth11
172.16.0.0/16172.16.1.1eth22
0.0.0.0/0192.168.1.1eth03 (default route)

What the routing table columns mean:

  • Destination network: the network address to be reached
  • Next hop: the address of the next router
  • Interface: the port the packet leaves through
  • Priority: the entry with the higher priority is chosen when several paths exist

1.3 Congestion Control: the “Traffic Controller” of the Network

Congestion Control

Congestion control is the set of mechanisms that prevent network performance from degrading under overload. It is like a traffic controller preventing congestion on the roads.

Causes of Congestion

An analogy with traffic congestion:

Network congestionTraffic congestion
Too many packetsToo many vehicles
Routers cannot keep upLimited capacity at an intersection
Buffer overflowThe car park is full
Packet lossVehicles stuck in traffic
Increased transmission delayLonger travel times

How congestion shows up:

  • 📉 The transmission rate drops
  • 📈 The packet loss rate rises
  • ⏱️ The delay increases
  • 🔁 The number of retransmissions grows

Congestion Control Strategies

1. Congestion detection

Monitor the state of the network:

  • router queue lengths
  • packet loss rate
  • average delay
  • link utilization

2. Congestion avoidance

Prevent congestion before it happens:

  • rate shaping: control the sending rate
  • load balancing: spread traffic over several paths
  • route optimization: steer traffic around congested areas
  • resource reservation: reserve bandwidth for important traffic

3. Congestion recovery

Handle the aftermath of a congestion event:

  • loss notification: ICMP source quench messages
  • rate reduction: the sender slows down
  • path switching: move to a different path
  • priority scheduling: handle important data first

4. Traffic shaping

Control the traffic entering the network:

  • token bucket: limit the sending rate
  • leaky bucket: smooth the traffic
  • Random Early Detection (RED): drop packets proactively to prevent congestion

2. Types of Service Offered by the Network Layer

2.1 Connectionless Service (Datagram Service)

Datagram Service

The datagram service is the connectionless service offered by the network layer. Each packet is transmitted independently, like posting a letter: every letter is sent on its own, with no guarantee about order or reliability.

Characteristic Analysis

An analogy with posting letters:

CharacteristicLetter analogyTechnical meaning
ConnectionlessNo need to confirm the recipient’s addressNo connection has to be established in advance
Independent transmissionEvery letter is sent on its ownEvery packet is routed independently
May be lostA letter may be lostA packet may be lost
May arrive out of orderSeveral letters may arrive in a different orderPackets may arrive out of order
Simple and efficientPosting a letter is quick and easyThe protocol is simple and the overhead is small

How It Works

Sender:

  1. Prepare the packet (adding the destination IP address)
  2. Send it straight to the network
  3. Do not wait for an acknowledgment

Network:

  1. Every router routes independently
  2. Packets may take different paths
  3. Packets may be lost, delayed, or reordered

Receiver:

  1. Receive the packet
  2. Check whether the destination address matches
  3. Process the data or discard the packet

Applicable Scenarios

Suitable for real-time applications:

  • 📞 Voice calls: a little packet loss does not affect call quality
  • 📹 Video streaming: a small amount of data loss can be tolerated
  • 🎮 Online games: real-time responsiveness matters more than reliability
  • 📡 Video conferencing: real-time interaction, latency sensitive

2.2 Connection-Oriented Service (Virtual Circuit Service)

Virtual Circuit Service

The virtual circuit service is the connection-oriented service offered by the network layer. A connection is established before data is transferred, which guarantees ordering and reliability. It is like making a phone call: dial first to establish the connection, then talk, and the voice stays continuous.

Characteristic Analysis

An analogy with making a phone call:

CharacteristicPhone call analogyTechnical meaning
Connection-orientedDial first to establish the connectionA virtual circuit has to be set up in advance
Fixed pathThe line stays fixed during the callAll packets follow the same path
Order guaranteedThe voice flows continuouslyPackets arrive in order
Reliable transferStable call qualityThe data is guaranteed to be transferred correctly
Complex overheadThere is a dialing and hanging up procedureThe protocol is complex and the overhead is large

How It Works

Connection establishment:

  1. The sender sends a call request
  2. The network establishes the virtual circuit (assigning a virtual circuit number)
  3. Every router on the path records the virtual circuit information
  4. The receiver confirms the connection

Data transfer:

  1. Every packet carries the virtual circuit number
  2. Routers forward based on the virtual circuit number
  3. All packets follow the same path
  4. Order and reliability are guaranteed

Connection release:

  1. The sender sends a release request
  2. The network releases the virtual circuit resources
  3. The routers on the path clear their entries
  4. The connection ends

Applicable Scenarios

Suitable for applications that need reliable transfer:

  • 📁 File transfer: FTP and file downloads, where data must not be lost
  • 🌐 Web browsing: HTTP and HTTPS, which need complete pages
  • 📧 Mail transfer: SMTP and POP3, where message content must stay intact
  • 📂 Database synchronization: data has to be exactly right

2.3 Comparison of the Two Services

CharacteristicDatagram serviceVirtual circuit service
Connection establishmentNot requiredA connection must be established
RoutingEvery packet is routed independentlyAll packets follow one path
OrderingNot guaranteedArrival in order is guaranteed
ReliabilityNot guaranteedReliable transfer is guaranteed
Failure handlingAdaptive routingThe connection must be re-established
OverheadSmallLarge
FlexibilityHighLow
Suitable forReal-time applicationsFile transfer
Typical exampleThe IP protocolX.25, ATM

3. The Main Protocols of the Network Layer

3.1 The IP Protocol: the Foundation of the Internet

IP Protocol (Internet Protocol)

The IP protocol is the core protocol of the network layer. It carries packets across the Internet and makes global interconnection possible.

Characteristics of the IP Protocol

Connectionless:

  • every packet is handled independently
  • no connection has to be established in advance
  • as simple as posting a letter

Best effort:

  • the data is delivered with the greatest effort possible
  • reliability is not guaranteed
  • packets may be lost, delayed, or reordered

Uniform addressing:

  • every device has a unique IP address
  • a globally scoped address system
  • support for IPv4 and IPv6

The Structure of an IP Packet

IP packet = IP header + data portion

IP Header Structure (20-60 bytes)

Version4 bit
Header Length4 bit
Type of Service8 bit
Total Length16 bit
ID/Flags/Fragment Offset32 bit
TTL8 bit
Protocol8 bit
Header Checksum16 bit
Source IP Address32 bit
Destination IP Address32 bit
OptionsOptional

The data portion carries application layer data (a TCP or UDP segment)

The key fields:

FieldMeaningPurpose
VersionThe IP version numberIPv4=4, IPv6=6
TTLTime To LivePrevents endless looping, the maximum hop count
ProtocolThe upper layer protocolTCP=6, UDP=17
Source IP addressThe sender’s addressUsed for replies
Destination IP addressThe receiver’s addressUsed for routing and forwarding

3.2 Supporting Protocols: the “Helpers” of IP

The ARP Protocol: Address Resolution

ARP (Address Resolution Protocol)

The ARP protocol converts an IP address into a MAC address, like a courier finding the exact door number from the recipient’s address.

How it works:

Scenario: the computer wants to send data to the server with the IP address 192.168.1.100.

  1. The computer knows the destination IP: 192.168.1.100
  2. But it does not know the MAC address (the physical address)
  3. It broadcasts an ARP request: “Who is 192.168.1.100? Tell me your MAC address”
  4. The server receives the ARP request and replies with an ARP response: “I am 192.168.1.100, and my MAC address is 00:1A:2B:3C:4D:5E”
  5. The computer receives the response and records the IP-to-MAC mapping
  6. It can then send data directly

The courier analogy:

  • IP address = the recipient’s address (the name of the residential complex)
  • MAC address = the exact door number (building and unit)
  • The ARP protocol = the process of looking up the door number

The DHCP Protocol: Dynamic Address Assignment

DHCP (Dynamic Host Configuration Protocol)

The DHCP protocol assigns IP addresses to devices automatically, like a hotel assigning room numbers to guests.

How it works:

A device joins the network (the four-step DHCP exchange):

  1. The device sends a DHCP Discover: “I am new here and need an IP address”
  2. The DHCP server sends an Offer: “I am a DHCP server and I can offer an IP address”
  3. The device sends a DHCP Request: “Please give me an IP address”
  4. The DHCP server sends an Acknowledge: “Your IP is 192.168.1.100, with a lease of 24 hours”
  5. The device starts using that IP
  6. The DHCP server records it: “192.168.1.100 has been allocated to this device”

Benefits:

  • ✅ Automatic configuration with no manual setup
  • ✅ Address reuse, which raises utilization
  • ✅ Central management, which avoids address conflicts
  • ✅ Mobility: a device that moves to another network obtains a new address automatically

The ICMP Protocol: Network Diagnostics

ICMP (Internet Control Message Protocol)

The ICMP protocol is used for network diagnostics and error reporting, like a physical examination for the network.

Common applications:

The ping command:

ping 192.168.1.100

Purpose: test whether the network is reachable
Process: send an ICMP request and receive an ICMP response
Result: display latency, packet loss rate, and related information

The traceroute command:

traceroute www.baidu.com

Purpose: trace the path of a packet
Process: send a series of ICMP packets and record every router
Result: display all the routers traversed and the latency at each hop

4. Network Layer Devices

4.1 Router: the “Traffic Hub” of the Network

Router

A router is the core device of the network layer. It connects different networks and forwards packets, like a traffic hub that joins different roads and guides vehicles onward.

Router Functions

1. Connecting different networks:

  • connecting LANs and WANs
  • connecting wired and wireless networks
  • connecting networks built on different technologies

2. Routing:

  • maintaining the routing table
  • choosing the best path
  • updating routing information dynamically

3. Packet forwarding:

  • receiving packets
  • looking up the routing table
  • sending them to the next hop

4. Other functions:

  • NAT address translation
  • ACL access control
  • QoS quality assurance
  • VPN support

How a Router Works

  1. Extract the destination IP address
  2. Look up the routing table
  3. Match the routing entries
  4. Choose the best route
  5. Check the TTL (decrement it by 1)
  6. Update the checksum
  7. Encapsulate it into a new frame
  8. Send it out of the designated interface

A routing table example:

Destination networkNetmaskNext hopInterface
192.168.1.0255.255.255.0Directly connectedeth0
10.0.0.0255.0.0.010.1.1.1eth1
172.16.0.0255.255.0.0172.16.1.1eth2
0.0.0.00.0.0.0192.168.1.1eth0 (default route)

Routing matching rules:

  • Longest match: choose the route with the longest (most specific) netmask
  • Priority: when several routes match, choose the one with the higher priority

4.2 Layer 3 Switch: a High-Performance Router

Layer 3 Switch

A layer 3 switch combines the functions of a switch and a router and performs routing and forwarding in hardware, which makes it much faster. It is like an intelligent toll gate on a highway that identifies vehicles quickly and directs them.

Characteristics of a Layer 3 Switch

Differences from a router:

CharacteristicRouterLayer 3 switch
Forwarding methodSoftware forwardingHardware forwarding
Forwarding speedRelatively slowVery fast
Number of interfacesFewMany
Suitable forWAN interconnectionLAN routing
PriceHigherLower
FeaturesRich feature setBasic routing functions

How it works:

The first packet:

  1. Software processing (like a router)
  2. Look up the routing table
  3. The hardware records the routing information

Subsequent packets:

  1. The hardware forwards them directly (like a switch)
  2. Forwarding is fast, using the hardware routing table
  3. No software processing is required

The defining characteristic is: “route once, switch many times”.


Practical Examples

Example 1: The Process of Visiting a Website

Consider the network layer steps involved in loading a web page in a browser:

Your computer (192.168.1.10):

  1. You enter the address www.baidu.com
  2. DNS resolves it to an IP address: 220.181.38.148
  3. It builds the IP packet: source IP 192.168.1.10, destination IP 220.181.38.148, with an HTTP request as the data

The local router: 4. Receives the packet 5. Looks up the routing table; the destination IP is not on the local network 6. Selects the default route and forwards it to the upstream router 7. Converts the source IP to a public IP using NAT

The ISP routers (several of them): 8. Each router looks up its routing table 9. Each router selects the next hop 10. The packet is forwarded hop by hop toward the Baidu server

The Baidu server (220.181.38.148): 11. Receives the IP packet 12. Checks that the destination IP matches 13. Extracts the HTTP request 14. Processes the request and returns the page

The return path: 15. The server builds the response packet (source IP 220.181.38.148, destination IP your public IP) 16. It returns hop by hop through the routers 17. NAT converts it back to the private IP 18. Your computer receives the response

Example 2: Interconnecting Different Networks

A home network interconnected with a corporate network:

Home network:

  • Wi-Fi network: 192.168.1.0/24
  • Wired network: 192.168.2.0/24
  • Devices: phones, computers, televisions

Corporate network:

  • Office network: 10.0.0.0/8
  • Data center: 172.16.0.0/16
  • Devices: servers, workstations

The interconnection process:

  1. The home router connects to the ISP over fiber
  2. The ISP connects to the corporate network over a leased line
  3. The IP protocol encapsulates uniformly: home Wi-Fi frame → IP packet → fiber frame → ISP routing → IP packet → leased line frame → corporate router
  4. Communication across the different networks becomes possible

Exercises

Exercise 1

What is heterogeneous internetworking, and why is it needed?

Heterogeneous InternetworkingIP ProtocolAddress TranslationEncapsulation

Approach: give the definition, then the three reasons, and finish with a concrete example.

Steps:

The definition of heterogeneous internetworking: Heterogeneous internetworking means that the network layer can connect networks of different types, protocols, and technologies so that they can communicate with each other.

Why heterogeneous internetworking is needed:

  1. Practical need:

    • many network types exist in reality (Ethernet, Wi-Fi, fiber, 4G/5G, and so on)
    • different networks use different technologies and protocols
    • users need to communicate across networks
  2. Technical differences:

    • different networks use different address formats (MAC addresses, IP addresses, and so on)
    • different networks use different frame formats
    • different networks offer different transmission rates
  3. Unified communication:

    • the IP protocol provides a single communication standard
    • it makes interconnection possible on a global scale
    • it lets different networks behave like one “language”

An example:

  • A phone accesses the internet over Wi-Fi and reaches a server in a data center (a fiber network).
  • The data travels: Wi-Fi → router → fiber network → server.
  • The network types differ, yet communication works because every network uses the IP protocol.

Answer: heterogeneous internetworking is the network layer’s ability to connect different network types so they can communicate; it is needed because networks differ in address format, frame format, and speed, and the IP protocol provides the common standard that bridges them.

Exercise 2

What is the difference between routing and packet forwarding?

RoutingPacket ForwardingRouting TableNext Hop

Approach: define each term with its role, timing, and analogy, then state the relationship between them.

Steps:

Routing:

  • Definition: choosing the best path from source to destination for a packet
  • Role: deciding which path the packet should take
  • Timing: the route is planned before the packet is sent
  • Analogy: navigation software planning a route

Packet forwarding:

  • Definition: moving a packet from one router to the next
  • Role: the actual transmission of the packet
  • Timing: performed during transmission
  • Analogy: a parcel moving from one transit station to the next

The relationship:

  • Routing: the macro-level decision (choosing the path)
  • Packet forwarding: the micro-level execution (forwarding step by step)
  • The result of the routing decision guides packet forwarding

A walkthrough: Routing: Beijing → Shijiazhuang → Wuhan → Guangzhou (choosing the path) Packet forwarding: the Beijing router forwards to the Shijiazhuang router (actual forwarding) the Shijiazhuang router forwards to the Wuhan router the Wuhan router forwards to the Guangzhou router

Answer: routing decides which path a packet should take, while packet forwarding is the hop-by-hop execution of that decision; the routing table produced by routing is what lets each router forward the next packet.

Exercise 3

What is the difference between the datagram service and the virtual circuit service, and what is each used for?

Datagram ServiceVirtual CircuitConnection-OrientedReliability

Approach: compare the two services on connection, routing, reliability, and overhead, then map each to its application areas.

Steps:

The main differences:

  1. Connection method:

    • Datagram: connectionless, no connection is established in advance
    • Virtual circuit: connection-oriented, a connection is established first
  2. Routing:

    • Datagram: every packet is routed independently
    • Virtual circuit: all packets follow the same path
  3. Reliability:

    • Datagram: no guarantee; packets may be lost or reordered
    • Virtual circuit: reliable, arriving in order
  4. Overhead:

    • Datagram: small overhead, simple and efficient
    • Virtual circuit: large overhead, since connections must be established and maintained

Applicable scenarios:

Datagram service:

  • real-time applications: voice calls, video streaming, online games
  • characteristics: strong timeliness requirements and high error tolerance
  • reason: a little packet loss does not affect the experience, and latency matters more

Virtual circuit service:

  • data transfer: file transfer, web browsing, mail transfer
  • characteristics: the integrity and accuracy of the data matter
  • reason: data loss is costly, and a retransmission can be waited for

Answer: the datagram service routes each packet independently with low overhead and suits latency-sensitive traffic, while the virtual circuit service establishes a fixed path that guarantees order and reliability and suits data that must arrive intact.

Exercise 4

What is the role of the ARP protocol? Briefly describe how it works.

ARPAddress ResolutionMAC AddressARP Cache

Approach: state the role in one sentence, then walk through the four stages of the exchange.

Steps:

The role of the ARP protocol: The ARP protocol converts an IP address into a MAC address, which solves the mapping problem between network layer addresses and data link layer addresses.

How it works:

  1. The sender sends an ARP request:

    • the device knows the destination IP address
    • but it does not know the corresponding MAC address
    • it broadcasts an ARP request: “Who has this IP address? Tell me your MAC address”
  2. The target device responds:

    • the target device receives the ARP request
    • it sees that its own MAC address is being queried
    • it sends an ARP response: “I have this IP address, and my MAC address is XXX”
  3. The mapping is recorded:

    • the sender receives the ARP response
    • it records the correspondence between the IP address and the MAC address
    • it stores the mapping in the ARP cache
  4. Data is sent using the address:

    • later transmissions use the recorded MAC address directly
    • no further ARP query is needed

The analogy: A courier knows the recipient’s address (the IP address) but has to find the exact door number (the MAC address), and obtains it by asking (the ARP request).

Answer: ARP maps an IP address to a MAC address through a broadcast request and a unicast response, and the result is cached so that later frames can be sent directly.


Glossary

TermAbbreviationExplanation
Network Layer-The third layer of the OSI model
Router-A network layer forwarding device
Packet-The protocol data unit of the network layer
Routing-Choosing the transmission path of a packet
Forwarding-Moving a packet from an input port to an output port
Heterogeneous Internetworking-Connecting networks of different types
Datagram Service-The connectionless service of the network layer
Virtual Circuit ServiceVCThe connection-oriented service of the network layer
Internet ProtocolIPThe core protocol of the network layer
Address Resolution ProtocolARPConverts an IP address into a MAC address
Internet Control Message ProtocolICMPNetwork layer error and control messages
Dynamic Host Configuration ProtocolDHCPAutomatic IP address assignment
Congestion Control-Prevents the network from being overloaded
Layer 3 Switch-A switch with routing capability
Maximum Transmission UnitMTUThe maximum data length in a link layer frame
Time To LiveTTLThe maximum hop count of a packet

Found an issue with this content?

Tell us what could be improved.