The layered model and IP addressing
The IP address and routing
An IP address identifies a device on a network, a bit like a postal address identifies a house. In IPv4, it is written as four numbers between 0 and 255 (for example 192.168.1.10). Part of the address designates the network, the other designates the host (the specific device) - it is the subnet mask that sets the boundary between the two. IPv6, more recent, uses much longer addresses (128 bits) to cope with the exhaustion of IPv4 addresses (32 bits, only about 4 billion addresses).
Routing is the way a packet finds its path to its destination. No device knows the full route in advance: each router looks only at the destination IP address and consults its routing table to decide which next router (the "next hop") to send the packet to. It is a local decision, repeated at each hop, until arrival.
PC (192.168.1.10) --- R1 --- R2 --- R3 --- Server (203.0.113.5)
(local network)(hop 1)(hop 2)(hop 3) (remote network)
Packet: source IP = 192.168.1.10 destination IP = 203.0.113.5
at the start (PC) : TTL = 64
after passing R1 : TTL = 63 (R1 consults its table, chooses R2 as next hop)
after passing R2 : TTL = 62 (R2 consults its table, chooses R3 as next hop)
after passing R3 : TTL = 61 (R3 delivers the packet directly to the server)
The TTL field (Time To Live) of the IP header is essential: each router crossed decrements it by 1. If it reaches 0, the packet is destroyed and an error is sent back to the sender. This mechanism prevents a misrouted packet from looping forever - it is the principle used by traceroute to reveal the path, hop by hop.
Common pitfall: believing that routing follows a fixed, unique path. In reality, two packets of the same flow can take different routes if the routing table changes in between (failure, congestion) - it is TCP that puts the data back in the right order on arrival, not the routing itself.
Another pitfall: confusing the IP address and the MAC address. The IP address guides the packet from network to network (routing), the MAC address is only used at the last hop, inside a single local network.

