Card 05/ 10
OSPF vs BGP
One finds the shortest path inside one organisation's network, the other chooses between organisations' networks by policy.
OSPF and BGP are both routing protocols: they let routers tell each other which networks they can reach, so that routing tables fill themselves instead of being typed in by hand. OSPF (Open Shortest Path First) works inside one organisation's network. BGP (Border Gateway Protocol) works between networks run by different organisations, and it is what joins the internet together.
The line between them is the autonomous system, a set of networks under one organisation's control with one routing policy, identified by a number. An internet provider, a large cloud provider and a university each run one or more.
| Property | OSPF | BGP |
|---|---|---|
| Scope | Inside one autonomous system | Between autonomous systems |
| What each router knows | A map of every link in the area and its cost | Paths to each network as lists of autonomous systems, from its neighbours |
| How a route is chosen | Shortest total cost, computed from the map | Policy first, such as preferring a cheaper provider, then path length |
| Trust between routers | Full: one organisation runs all of them | Limited: each side filters what it accepts from the other |
| Typical size | Hundreds of routes | About a million IPv4 and IPv6 routes on the internet |
| Reacts to a failed link | Within seconds, by recomputing the map | More slowly, as withdrawals spread between networks |
The difference that matters most is what each one optimises. OSPF is a link-state protocol: every router learns the whole map of its area and computes the shortest path, so the fastest route wins. BGP is a path-vector protocol: it is told by each neighbour which networks it can reach through which chain of autonomous systems, and the network's operator decides which to prefer for business reasons, such as which provider is paid less. On the internet, the path traffic takes is a commercial decision as much as a technical one.
The word "border" in BGP refers to the border between organisations, not the edge of a building's network. A large organisation also runs BGP inside its own network to carry the routes it learns from outside, but its purpose is still between networks.
The rule for choosing. Use OSPF, or a similar interior protocol, to route between the networks one team controls. Use BGP where your network meets one you do not control: an internet provider, a cloud provider's dedicated connection, or a partner. Most application engineers configure neither directly, but meet BGP whenever a provider's routing fault takes part of the internet offline.
← → move through sections and cards