When a router receives a packet, it looks at the destination IP address and forwards the packet out of the correct physical port. But how does the router know which port leads to the correct destination? It consults its Routing Table.
The process of building and maintaining this routing table dynamically as the network changes (links go down, new routers are added) is governed by Routing Algorithms.
In Distance Vector routing, each router maintains a table containing the best known distance (cost) to every other destination in the network, and which link to use to get there.
How it works (The Bellman-Ford Algorithm):
Pros: Very simple to configure and requires minimal memory and CPU. Cons:
Protocol Implementation: RIP (Routing Information Protocol).
Link State routing is vastly superior and is the standard for modern internal networks. Instead of blindly trusting its neighbors' routing tables, every router independently maps out the entire network topology.
How it works (Dijkstra's Algorithm):
Pros: Fast convergence. Because every router has a complete map of the network, routing loops are impossible. Cons: Requires significant CPU processing to run Dijkstra's algorithm, and requires more memory to store the topological database.
Protocol Implementation: OSPF (Open Shortest Path First).
While OSPF is used inside an organization's network (Intra-Domain Routing), it cannot scale to the size of the global Internet. For routing between massive autonomous networks (like AT&T routing to Comcast), Path Vector Routing is used.
How it works: Instead of tracking the exact cost (distance) to a destination, BGP tracks the exact path (a list of Autonomous Systems) the packet must travel through.
Protocol Implementation: BGP (Border Gateway Protocol). BGP is the duct tape that holds the global Internet together. If BGP fails (as happened to Facebook in 2021), the entire company disappears from the Internet.