3 IP Addressing and Routing
Learn how IPv4 and IPv6 addressing, subnet design, route selection, and common routing protocols work together to move packets between networks.
Addressing and packet forwarding
IP addressing identifies network interfaces, while routing enables routers to forward packets between IP networks. A router examines a packet's destination address, consults its forwarding information, and sends the packet toward the next hop. If no usable route exists, the router drops the packet.
IPv4 addressing
An is a 32-bit address written conventionally as four decimal octets, such as 192.0.2.25. Its prefix length identifies how many leading bits describe the network. For example, 192.0.2.25/24 has 24 network bits and 8 host bits, with the subnet mask 255.255.255.0.
uses prefixes of varying lengths rather than relying on the older address classes. The familiar private IPv4 ranges are 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16. These ranges are intended for private networks and are not globally unique public addresses. Organizations commonly use Network Address Translation (NAT) when private hosts need access to the public IPv4 Internet.
IPv6 addressing
An is 128 bits long and is written as eight hexadecimal groups separated by colons, as in 2001:db8:1::25. Leading zeros in a group may be omitted, and one continuous run of zero groups may be compressed with :: once in an address. A prefix length follows a slash, as in 2001:db8:1::25/64.
IPv6 uses unicast, multicast, and anycast addressing, but has no broadcast addresses. Devices may use multiple IPv6 addresses on one interface. A /64 is the common subnet size for IPv6 LANs; in a subnet such as 2001:db8:1:2::/64, the prefix identifies the subnet and the remaining bits identify an interface.
Useful categories include:
Global unicast: Globally routable unicast addresses.
Link-local:
FE80::/10addresses used on a local link. Routers do not forward these addresses to other links.Unique local:
FC00::/7addresses intended for local communications and not globally routable.Multicast: Addresses beginning with
FF00::/8that identify groups of interfaces.
Subnet design
Subnetting divides an address block into smaller networks. A longer prefix reserves more bits for the network and leaves fewer bits for host addresses. For a conventional IPv4 subnet with host bits, the number of addresses is . Typically, two addresses are unavailable for host assignment because they identify the subnet and its broadcast address. The /31 point-to-point-link exception allows both addresses to be used as endpoints.
For example, dividing 192.168.10.0/24 into /26 subnets borrows two bits, producing subnets. Each /26 has six host bits, so it contains 64 addresses and conventionally supports 62 host addresses:
192.168.10.0/26: usable range192.168.10.1–192.168.10.62; broadcast192.168.10.63.192.168.10.64/26: usable range192.168.10.65–192.168.10.126; broadcast192.168.10.127.192.168.10.128/26: usable range192.168.10.129–192.168.10.190; broadcast192.168.10.191.192.168.10.192/26: usable range192.168.10.193–192.168.10.254; broadcast192.168.10.255.
Use to assign differently sized subnets according to need and conserve address space. Plan blocks so subnets do not overlap and can be summarized into larger prefixes where appropriate. For each subnet, identify its prefix, network address, usable range, broadcast address, and default gateway.
For IPv6, design a hierarchy of prefixes for sites and subnets. IPv6 does not use a broadcast address or the IPv4 network-and-broadcast host-count rule.
Routing tables and route selection
A records destination prefixes and how to reach them. Routes can be directly connected, manually configured as static routes, or learned through a dynamic routing protocol. A default route—0.0.0.0/0 for IPv4 or ::/0 for IPv6—matches destinations that have no more-specific route and is often used toward an upstream router.
When forwarding a packet, a router applies : it selects the matching route with the most network bits. For destination 10.0.2.1, a route to 10.0.2.0/24 is preferred over a route to 10.0.0.0/16 because /24 is more specific. These decisions populate the forwarding table used to forward packets.
If routes to the same prefix come from different sources, the router applies its route-source preference rules; implementations may also compare the protocol's . A measures route preference within a protocol: uses hop count, while uses cost. A lower is often preferred within that protocol, but metrics from different protocols are not necessarily comparable. Some platforms use a separate administrative-preference value to choose between routes to the same prefix learned from different sources. If supported, equal-cost routes may be installed together for load sharing.
Common routing protocols
Routing protocols differ in where they operate and how they exchange routing information.
(Routing Information Protocol): An interior gateway protocol (IGP) that uses distance-vector updates. RIPv2 uses hop count; 16 means a destination is unreachable, so usable paths are limited to 15 hops. 's simplicity suits small networks, but its hop limit and convergence behavior constrain its scale.
(Open Shortest Path First): A link-state IGP. Routers distribute link-state information, build a topology database, and calculate shortest paths. supports areas to organize larger routing domains.
IS-IS (Intermediate System to Intermediate System): A link-state IGP that calculates paths using the Shortest Path First algorithm. It can route IP traffic within an autonomous system.
(Border Gateway Protocol): The principal interdomain routing protocol, used to exchange reachability information between autonomous systems. is path-vector and supports policy-based path selection; its AS-path information also helps detect routing loops.
An IGP such as , , or IS-IS routes within an organization or autonomous system. An exterior gateway protocol, chiefly , exchanges routes between autonomous systems. Protocol choice depends on network scale, operational requirements, and routing policy.