OSPF vs BGP: IGP vs EGP, Route Selection and Scale
The internet is made up of interconnected ASes (autonomous systems), networks managed by organizations such as service providers, universities and companies. A protocol that exchanges routes inside an AS is called an IGP, and one that exchanges routes between ASes is called an EGP; OSPF is the typical IGP and BGP the typical EGP. OSPF automatically finds the shortest route from the link costs inside an AS and aims to switch quickly after a failure. BGP chooses routes between ASes based on attributes such as the sequence of ASes passed through (AS_PATH) and on each organization's policy, such as which neighbor to prefer. Because it handles routes for the entire internet, it is designed for stability and control rather than speed.
| Aspect | OSPF | BGP |
|---|---|---|
| Classification and scope | IGP; inside one AS (organization) | EGP; between ASes; also used between BGP routers inside the same AS (iBGP) |
| Protocol type | Link-state | Path vector |
| Route selection | Finds the route with the lowest total link cost using Dijkstra's algorithm | Compares attributes such as LOCAL_PREF, AS_PATH length and MED in a fixed order; attributes can be set to apply the organization's policy |
| Loop prevention | All routers in an area compute shortest paths from the same map | Discards a received route whose AS_PATH contains its own AS number |
| How neighbors connect | Runs directly over IP (protocol number 89); sends Hellos by multicast and discovers neighbors automatically | Connects over TCP port 179; each peer is configured by the administrator one by one |
| How updates are sent | When something changes, LSAs are spread through the area; Hellos check that neighbors are alive (every 10 seconds in the RFC 2328 example) | Sends the full set of routes first, then only changes in UPDATE messages; routes are not resent periodically, and KEEPALIVEs keep the session up |
| Convergence speed | Generally fast; recomputes right away once it notices a link failure | Generally slower; detecting a failure can mean waiting for the hold time (90 seconds suggested in RFC 4271), and there are many more routes |
| Number of routes and scale | Routes inside the organization; large networks are split into areas to limit computation and information | Can handle the very large number of routes of the whole internet; used between providers and by organizations connected to several providers |
Figures are typical orders of magnitude and vary by process generation and product.