LABS · PROTOCOLS · NET PATH

IPv4: how a packet travels from one network to another

A ping from Vancouver to Montreal crosses two routers. See the IPv4 header byte by byte, how each router decides where to send it and what changes at every hop: the TTL, the checksum and the MACs. The IPs, on the other hand, travel untouched.

Level: beginner · 12 minutes

Interactive simulation

The animation needs JavaScript. The full lesson is written out below.

Download the capture and open it in Wireshark to keep exploring.

What IPv4 is

IPv4 (Internet Protocol version 4, RFC 791) carries packets from one network to another. Each device has a 32-bit address, written as four numbers from 0 to 255 (192.168.10.12), and a mask that separates the network part from the host part. Routers read the destination IP and decide, hop by hop, where to go next.

IP doesn't guarantee delivery: if a packet is lost, it doesn't resend it. That's left to TCP or the application. IP only handles addressing and routing.

The IPv4 header, field by field

FieldBitsIn the simulation
Version44
IHL (header length)45 32-bit words = 20 bytes
DSCP and ECN80: no priority
Total length1684 bytes (20 of header + 64 of ICMP)
Identification16Used to reassemble fragments
Flags and fragment offset3 + 13DF = 1: don't fragment
TTL864 when it leaves; 1 less at each router
Protocol81 = ICMP (6 = TCP, 17 = UDP)
Header checksum16Header only; each router recalculates it
Source address32192.168.10.12
Destination address3210.20.30.40

At each router only the TTL and the checksum change. The Ethernet frame around the packet, on the other hand, is new on every link.

How it works: hop by hop

Five steps: the laptop builds the packet, R1 and R2 forward it, the reply comes back and we review the routing table.

  1. The laptop builds the IPv4 packet

    The laptop applies its /24 mask: 192.168.10.12 is on network 192.168.10.0, and 10.20.30.40 on 10.20.30.0. They're different networks, so the packet goes to the default gateway, R1 (192.168.10.1). The IPv4 header carries the server's IP as destination, TTL 64, protocol 1 (ICMP) and the DF bit; the frame carries R1's MAC.

  2. R1 looks up the route and forwards

    R1 checks the checksum and looks up 10.20.30.40 in its table. Two routes match: the default 0.0.0.0/0 and the static 10.20.0.0/16. The longest prefix wins, /16, with next hop 10.0.12.2 out Gi0/0/0. R1 subtracts 1 from the TTL (64 → 63), recalculates the checksum and builds a new frame with its Gi0/0/0 MAC and R2's. The IPs don't change.

  3. R2 delivers on its connected network

    On R2, 10.20.30.40 matches the connected network 10.20.30.0/24 on Gi0/0/1: no more routers. R2 subtracts 1 from the TTL (63 → 62), takes the server's MAC from its ARP table and delivers the packet. The WAN link added about 31 ms: the distance between Vancouver and Montreal.

  4. The reply takes the reverse path

    The server answers with an Echo Reply to 192.168.10.12 and TTL 64. For it to arrive, R2 needs a route to 192.168.10.0/24: it has a static one via 10.0.12.1. Each router subtracts 1, so the laptop gets the reply with TTL 62 and R1's MAC as source. The round trip took about 62 ms.

  5. R1's routing table

    C are the connected networks and L each interface's own IP (/32). S are static routes, and S* is the default route (gateway of last resort). In brackets are the administrative distance and the metric: [1/0] is a static route. If several routes match a destination, the longest prefix wins; with the same prefix, the lowest administrative distance.

Addresses and masks

The /24 mask (255.255.255.0) says the first 24 bits are the network. A bitwise AND between the IP and the mask gives the network: 192.168.10.12 AND 255.255.255.0 = 192.168.10.0. If the destination gives a different network, the packet goes to the default gateway.

BlockRangeUse
Private (RFC 1918)10.0.0.0/8 · 172.16.0.0/12 · 192.168.0.0/16Internal networks; reach the Internet through NAT
Loopback127.0.0.0/8The device itself
Link-local (APIPA)169.254.0.0/16No DHCP: local segment only
Documentation192.0.2.0/24 · 198.51.100.0/24 · 203.0.113.0/24Examples, like R1's ISP
Multicast224.0.0.0/4Groups (OSPF uses 224.0.0.5)
Limited broadcast255.255.255.255The whole local network

How a router chooses a route

  • Longest prefix: among all routes that match the destination, the most specific wins. 10.20.0.0/16 beats 0.0.0.0/0.
  • Administrative distance: if two sources offer the same prefix, the lower AD wins. Connected 0, static 1, EIGRP 90, OSPF 110, RIP 120.
  • Metric: if one protocol offers several paths to the same prefix, the lowest metric wins (or traffic is shared if they tie).
  • Default route: 0.0.0.0/0 matches everything and is only used when nothing more specific exists.
  • No route: if nothing matches, the router drops the packet and tells the source with an ICMP Destination Unreachable.

See it on Cisco IOS XE

CommandWhat it shows or does
show ip interface briefThe interfaces, their IPs and their state.
show ip routeThe full routing table, with each route's source, AD and metric.
show ip route 10.20.30.40The route the router would use for that destination.
show ip cef 10.20.30.40The next hop and exit interface used for forwarding.
ip route 10.20.0.0 255.255.0.0 10.0.12.2Creates a static route to a network.
ip route 0.0.0.0 0.0.0.0 203.0.113.1Creates the default route.
ping 10.20.30.40 source Gi0/0/1Extended ping: tests the path out and back from another interface (topic 2.4).

What happens when it fails

  • Wrong or missing default gateway: the device talks to its network but can't leave it.
  • Wrong mask: the device thinks a remote destination is local (or vice versa) and doesn't use the gateway when it should.
  • Missing return route: the request arrives, but the reply is lost. Check the table on both sides.
  • Unreachable next hop: a static route is only installed if its next hop is reachable.
  • Duplicate address or wrong subnet: check it with show ip interface brief and the device's configuration (topic 1.3).
  • Routing loop: the packet goes around until the TTL reaches 0 and it's dropped.

Frequently asked questions

Why does the MAC change but not the IP?

The MAC identifies the card on one link and is only valid for that hop; the IP identifies the destination device across the whole network. Each router builds a new frame with the MACs of the next link.

What is the TTL for?

So a packet doesn't loop forever if there's a routing loop. Each router subtracts 1 and, if it reaches 0, drops it and reports it with an ICMP Time Exceeded. traceroute is based on that.

What is administrative distance?

How much a route's source is trusted: the lower, the better. It's only compared between routes with the same prefix.

What does [1/0] mean in show ip route?

Administrative distance 1 and metric 0: a static route.

What happens if there's no route?

The router drops the packet and sends an ICMP Destination Unreachable to the source. With a default route, everything unknown follows it.

Key takeaways

  • The IPv4 header is 20 bytes without options; at each router only the TTL and the checksum change.
  • With the mask, the device decides whether the destination is local or goes to the default gateway.
  • The router picks the longest-prefix route; with the same prefix, the lowest administrative distance.
  • IPs travel end to end; MACs change at every hop.
  • On Cisco IOS you see it with show ip route and configure it with ip route.

NEXT STEP

From this lesson to the Canadá Logística network

In the CCNA 2.0 Course you design Canadá Logística's addressing plan, configure static and default routes between sites and troubleshoot with show ip route and extended ping, in Packet Tracer or CML. We'll let you know when it opens.

Upcoming labs

Sources

Lesson prepared with AI assistance and checked against the sources cited. The bytes of every packet are generated according to the standard and verified with an independent tool.