diagram.mmd — flowchart
IP Packet Routing flowchart diagram

IP packet routing is the process by which routers examine a packet's destination IP address and forward it hop-by-hop through the network toward its destination, using routing tables to make forwarding decisions at each hop.

IP (Internet Protocol) is connectionless and stateless: each packet is forwarded independently, and routers hold no per-flow state. This design makes the internet robust — packets can take different paths, and routing dynamically adapts to failures.

Routing Table Lookup: Each router maintains a routing table — a set of prefix-to-next-hop mappings. When a packet arrives, the router performs a longest prefix match: it finds the most specific routing table entry whose prefix contains the destination IP. The matched entry specifies the next-hop IP and outgoing interface.

Local Delivery vs. Forwarding: If the destination IP is on a directly connected subnet, the router delivers the packet locally (using ARP to find the MAC address; see ARP Resolution). Otherwise, it forwards to the next-hop router, decrementing the IP TTL field by 1.

TTL and Loop Prevention: The TTL (Time to Live) field is decremented at each hop. If TTL reaches 0, the packet is discarded and an ICMP "Time Exceeded" message is sent back to the source. This prevents packets from circling the network indefinitely. Traceroute exploits this behavior to map network paths.

Routing Protocols: Routing tables are built dynamically by protocols like OSPF (within an AS) and BGP (between autonomous systems). BGP is the "glue" of the internet, enabling anycast routing and inter-domain traffic engineering.

Fragmentation: If a packet exceeds the MTU of the outgoing link, IPv4 routers may fragment it (IPv6 requires the source to handle fragmentation). See Packet Fragmentation.

Free online editor
Edit this diagram in Graphlet
Fork, modify, and export to SVG or PNG. No sign-up required.
Open in Graphlet →

Frequently asked questions

IP packet routing is the process by which routers examine a packet's destination IP address and forward it hop-by-hop through the network toward its destination. Each router independently makes a forwarding decision based on its routing table, with no per-flow state. This stateless, connectionless design makes the internet inherently resilient — packets dynamically reroute around failures.
The router performs a longest prefix match against its routing table: it finds the most specific entry whose network prefix contains the destination IP. The matched entry specifies the next-hop router or directly connected interface. If TTL reaches 0 during forwarding, the router discards the packet and sends an ICMP Time Exceeded message to the source.
Within an autonomous system (AS), OSPF or IS-IS build routing tables using link-state or distance-vector algorithms. Between autonomous systems, BGP (Border Gateway Protocol) exchanges reachability information. BGP is the protocol that enables anycast routing and global internet routing.
Common issues include routing loops (mitigated by TTL), black holes (packets dropped silently with no ICMP), and asymmetric routing (forward and return paths differ). Traceroute is the standard tool to diagnose routing paths — it exploits TTL-exceeded ICMP messages to map each hop.
mermaid
flowchart LR Src([Source Host\n10.0.0.5]) --> R1 R1[Router 1\n10.0.0.1] --> RT1{Lookup dst IP\nin routing table} RT1 -->|Local subnet| ARP[ARP for MAC\ndeliver locally] RT1 -->|Next hop: 172.16.0.1| TTL1[Decrement TTL\nUpdate src MAC] TTL1 --> R2 R2[Router 2\n172.16.0.1] --> RT2{Longest prefix\nmatch lookup} RT2 -->|Next hop: 203.0.113.1| TTL2[Decrement TTL] TTL2 --> R3 R3[Router 3\n203.0.113.1] --> RT3{Lookup dst IP} RT3 -->|Directly connected| Deliver[Deliver to\ndestination LAN] Deliver --> Dst([Destination Host\n203.0.113.50]) TTL1 -->|TTL = 0| ICMP[Discard packet\nSend ICMP Time Exceeded\nto source] RT3 -->|No route found| Drop[Discard packet\nSend ICMP\nDest Unreachable]
Copied to clipboard