Open Shortest Path First (OSPF) is a link-state routing protocol used by routers to exchange information about network connectivity and calculate paths for forwarding packets. It is an interior gateway protocol: its principal scope is routing within an autonomous system, rather than exchanging reachability between independently administered networks. OSPF describes connectivity through link-state advertisements, distributes those advertisements within defined scopes, and uses Dijkstra’s algorithm to construct shortest-path trees.
Developed through the Internet Engineering Task Force (IETF), OSPF is an openly specified protocol implemented by many equipment and software vendors. OSPF version 2 primarily supports IPv4, while OSPF version 3 was originally designed for IPv6 and was subsequently extended to support additional address families. Its distinguishing features include explicit link costs, support for multiple equal-cost paths, reliable distribution of topology information, and a hierarchical area structure.
OSPF is widely used in enterprise, campus, and service-provider networks. Its operation depends on several interacting mechanisms: neighbor discovery establishes which routers can communicate; database synchronization gives adjacent routers consistent topology information; shortest-path calculations turn that information into routes; and area boundaries restrict the distribution of detailed topology. Understanding these mechanisms also explains the protocol’s convergence behavior, scaling properties, and security limitations.
Origins and standardization
OSPF emerged during the late 1980s as Internet networks were growing beyond the practical limits of early routing protocols. The Routing Information Protocol (RIP), standardized in RFC 1058 in 1988, used a distance-vector approach and a hop-count metric in which 16 represented an unreachable destination. Although simple to implement, this model imposed a small network diameter and offered limited control over paths with different capacities. Failures could also expose distance-vector protocols to slow propagation of unreachable-route information.
Link-state routing offered a different model. Instead of learning only a neighbor’s reported distance to a destination, each router could receive descriptions of the relevant topology and calculate paths independently. Shortest-path algorithms were already established, and link-state techniques had been used in other packet networks. OSPF adapted these ideas to the Internet Protocol environment, incorporating capabilities such as subnet masks, authentication, multicast transmission, and hierarchical organization.
The first OSPF specification appeared as RFC 1131 in October 1989, authored by John Moy. OSPF version 2 followed in RFC 1247 in July 1991. Subsequent specifications refined the protocol, culminating in RFC 2328, published in April 1998, which remains the foundational OSPFv2 specification. The progression was not simply a change in packet format: it clarified detailed rules governing database exchange, link-state advertisement processing, route calculation, and interactions between areas.
OSPFv2 became an Internet Standard, and later RFCs added capabilities without replacing its basic architecture. Important extensions include the not-so-stubby area mechanism, opaque link-state advertisements, cryptographic authentication enhancements, and mechanisms for graceful restart. OSPFv3 was initially specified in RFC 2740 in December 1999; RFC 5340, published in July 2008, superseded that specification. These versions are distinct protocols on the wire, even though their high-level routing model is closely related.
The word “open” refers to the availability and standardization of the protocol specification, not to an absence of security controls or to a requirement that implementations be open-source software. OSPF became one of the principal alternatives to Intermediate System to Intermediate System (IS-IS) for link-state interior routing. Meanwhile, Border Gateway Protocol (BGP) serves a different primary role: exchanging routes according to policy between autonomous systems, although it is also extensively used within them. A network may therefore run OSPF and BGP simultaneously, with each maintaining information for a different routing purpose.
Topology model, costs, and shortest-path calculation
Within an area, OSPF models the network as a directed graph. Routers are vertices, and some multiaccess networks are represented by additional network vertices. Links describe connectivity between these vertices, together with associated costs. The graph is directed because the cost advertised in one direction need not equal the cost in the reverse direction. Each router builds a shortest-path tree rooted at itself, so routers sharing the same topology database normally compute different trees but compatible forwarding decisions.
For a path containing a sequence of outgoing links, its cost is the sum of their individual costs:
The selected intra-area path minimizes this sum among eligible paths to the destination. This is an instance of the shortest-path problem, not a direct measurement of current packet delay, available bandwidth, or congestion. OSPF does not automatically divert traffic from a busy link merely because queues have become longer.
An interface’s output cost is an administratively assigned integer. Many implementations derive a default value from a reference bandwidth divided by interface bandwidth, subject to integer representation and implementation rules. A historically common reference bandwidth of 100 megabits per second gives many faster interfaces the same minimum cost. Consequently, a gigabit and a much faster interface may appear equivalent unless costs or the reference bandwidth are changed. This bandwidth-derived convention is not a universal formula mandated by the base protocol; consistent metric configuration is an operational matter.
Suppose router A can reach D through B with costs 10 and 10, or through C with costs 5 and 30. The corresponding total costs are 20 and 35, so the path through B is preferred despite the lower first-hop cost through C. If another path also totals 20, OSPF can retain multiple next hops through equal-cost multipath (ECMP). The number of installed paths and the method used to distribute packets or flows across them depend on the implementation and forwarding hardware.
The calculation proceeds in stages rather than treating every advertised destination as an undifferentiated vertex. A router first calculates intra-area reachability from the area topology, then processes inter-area and external information according to OSPF’s route-selection rules. Prefixes attached to a router or network are associated with the calculated topology. An area border router performs relevant calculations for each attached area.
OSPF’s topology database and its installed forwarding state are therefore different objects. The database records protocol information; the routing process derives candidate routes; and the system’s routing table may compare those candidates with routes from other protocols. The administrative distance or equivalent local preference used for that last comparison is an implementation policy, not part of OSPF’s shortest-path metric.
Link-state advertisements and reliable flooding
The central information unit in OSPF is the link-state advertisement (LSA). An LSA describes some portion of connectivity or reachability and carries identification, sequencing, aging, and integrity fields. A router’s link-state database is the collection of LSAs relevant to its participating areas and other applicable flooding scopes. Routers with synchronized databases in the same area possess the same area-scoped topology information, although their local interface states and calculated routes are not necessarily identical.
In OSPFv2, a Type 1 router-LSA describes a router’s links within an area. A Type 2 network-LSA, originated by the designated router on an eligible transit multiaccess network, lists routers attached to that network. Type 3 summary-LSAs advertise network reachability between areas, while Type 4 advertisements describe reachability to autonomous-system boundary routers. Type 5 advertisements carry external routes. Type 7 advertisements perform a related role inside not-so-stubby areas. Despite the name “summary-LSA,” a Type 3 advertisement need not represent an aggregated prefix; it may describe an individual network.
An LSA is identified using its type, link-state identifier, and advertising router within the applicable scope. Its header contains a sequence number and checksum, allowing routers to determine which instance is newer and detect corruption. The age field controls lifetime. In the base protocol, an originating router normally refreshes an LSA at 1,800 seconds, and an LSA reaches its maximum age at 3,600 seconds. These periodic refreshes maintain valid state even when the topology has not changed; they are not periodic retransmissions of the entire routing table.
Flooding is reliable through explicit acknowledgments, retransmission lists, and rules for handling duplicate or older instances. When a router receives a newer valid LSA, it installs it and propagates it over eligible adjacencies, subject to scope and flooding rules. Acknowledgments may be explicit or implicit, and an unacknowledged advertisement can be retransmitted. This reliability is implemented by OSPF itself rather than delegated to TCP.
OSPF defines five packet types: Hello, Database Description, Link State Request, Link State Update, and Link State Acknowledgment. Database Description packets summarize database contents during synchronization. Requests ask for particular advertisements, updates carry one or more complete LSAs, and acknowledgments confirm receipt. An LSA is therefore not synonymous with an OSPF packet: several advertisements can be carried within one update packet.
OSPF runs directly over the Internet Protocol using protocol number 89, without TCP or UDP port numbers. OSPFv2 uses the multicast addresses 224.0.0.5 for AllSPFRouters and 224.0.0.6 for AllDRouters on appropriate network types. Its packets normally remain link-local, although virtual links have special transport rules. This distinction matters when interpreting packet captures or filtering protocol traffic.
Neighbor discovery, adjacency, and multiaccess networks
OSPF routers discover and maintain neighbors through Hello packets. A Hello includes information such as the sending router’s identifier, relevant capabilities, timing parameters, and known neighbors. Bidirectional communication is established when a router sees its own router ID listed in a neighbor’s Hello. The router ID is a 32-bit identifier; although commonly displayed in dotted-decimal notation, it is not inherently the address used to forward packets to that router.
Neighbor relationships pass through a defined state machine. Important states include Down, Init, 2-Way, ExStart, Exchange, Loading, and Full; Attempt is additionally relevant to configured neighbors on certain nonbroadcast networks. Init indicates that a Hello has been received without confirmed bidirectionality. In ExStart and Exchange, routers negotiate database exchange and transfer database summaries. Loading covers the acquisition of missing or newer LSAs. Full indicates that the adjacency has completed synchronization.
Not every pair of neighbors becomes fully adjacent. On a broadcast network such as a shared Ethernet segment, OSPF elects a designated router (DR) and a backup designated router (BDR). Other routers establish full adjacencies with these two rather than forming a complete mesh with every participant. Two routers that are neither DR nor BDR may remain in the 2-Way state while operating normally.
The DR also originates the network-LSA representing the transit segment. This reduces the amount of adjacency management and gives the shared network an explicit representation in the topology graph. Without this approach, a segment containing routers could require pairwise adjacencies. The DR arrangement reduces the number of full adjacencies to a quantity that grows linearly with the number of routers.
Election depends on interface priority and router ID, with priority zero making an interface ineligible. The election is deliberately nonpreemptive: a newly arriving router with a higher priority does not automatically displace a functioning DR. The BDR is positioned to take over if the DR fails. These roles apply to the individual network segment, not to the whole area, and the DR is not a mandatory data-forwarding intermediary.
Network type changes neighbor behavior. Point-to-point links do not require a DR election. Nonbroadcast multiaccess networks may need explicit neighbor configuration, while point-to-multipoint operation represents connectivity differently and avoids the broadcast-network election model. Common broadcast defaults are a 10-second Hello interval and a 40-second dead interval, but defaults vary by network type and implementation.
Compatible parameters are necessary for a successful adjacency. Area identity, relevant options, authentication, and Hello/dead intervals must agree as required by the protocol. An interface maximum transmission unit mismatch can stop database exchange, often leaving neighbors in ExStart or Exchange. These failure modes illustrate why receiving Hellos alone does not prove that routing information is being exchanged successfully.
Areas, the backbone, and hierarchical organization
OSPF divides an autonomous system into areas to limit the scope of detailed topology information. Each area has a 32-bit identifier, commonly displayed in dotted-decimal form. An internal router has its OSPF interfaces within one area, whereas an area border router (ABR) connects areas and maintains separate link-state databases for them. Detailed router and network advertisements remain inside their area rather than being flooded unchanged throughout the autonomous system.
Area 0, also called the backbone area, provides the logical center of inter-area routing. In the standard hierarchy, nonbackbone areas connect to the backbone, and inter-area information passes through it. This is a two-level design, not an arbitrary hierarchy of recursively nested areas. A router calculating a route to another area generally sees advertised destination information and associated costs, rather than that area’s internal graph.
An ABR derives inter-area advertisements from its routing information. It can also aggregate selected address ranges into a smaller set of advertisements. For example, several appropriately allocated contiguous subnets may be represented by a covering prefix. Aggregation reduces routing information outside the originating area, but it hides details: a remote router cannot distinguish every internal failure or path variation. Where a covering advertisement remains present despite an unreachable component, implementations may use a discard route to prevent forwarding loops for the unmatched portion.
A stub area restricts external routing information. Standard stub areas do not admit Type 5 external LSAs, and an ABR supplies a default route for destinations outside the area. This reduces database size on internal routers but also limits the area’s routing role. In particular, ordinary external-route origination within a standard stub area is not supported. A stub area may still contain inter-area advertisements; the term does not mean that only a default route is present.
A not-so-stubby area (NSSA), specified in RFC 3101, permits external routes to be introduced locally using Type 7 LSAs. An eligible NSSA ABR can translate qualifying Type 7 advertisements into Type 5 advertisements for distribution elsewhere. This accommodates cases such as a branch area that needs both restricted incoming external information and local redistribution. “Totally stubby” and related terms usually describe implementation-supported variants that further suppress inter-area advertisements; they are not additional base OSPFv2 LSA types.
Virtual links provide a logical backbone connection through an eligible transit area. They can connect an otherwise disconnected backbone attachment or repair certain backbone discontinuities, but the transit area cannot be a stub area. A virtual link is a protocol mechanism with its own adjacency and transport behavior, not merely an address-space shortcut. Because its operation depends on connectivity through another area, it introduces dependencies that are absent from a direct backbone connection.
External routes, redistribution, and path preference
An autonomous-system boundary router (ASBR) introduces routing information from outside the OSPF routing domain. Sources may include another routing protocol, static routes, or selected connected networks. This process is called redistribution. The advertised route is external to OSPF’s topology model even when its destination belongs to the same organization or address allocation. “External” here describes how the route entered OSPF, not necessarily a geographic or administrative boundary.
OSPF distinguishes routes by class before comparing every possible cost as though all routes were equivalent. Intra-area routes are preferred over inter-area routes, and internal routes are preferred over external routes for the same destination. External Type 1 routes are preferred over External Type 2 routes. These rules operate within OSPF; competition with routes installed by other protocols is governed separately by the local routing system.
External Type 1, commonly written E1, adds the internal cost of reaching the external forwarding point to the advertised external metric:
This makes distance through the OSPF domain part of the total path cost. It is useful when the internal journey to an exit should influence route selection on the same metric scale as the external portion.
External Type 2, or E2, treats the external metric as the principal value. Internal cost is used to distinguish otherwise eligible routes with equal external metrics, subject to the detailed external-route selection rules. For example, an E2 advertisement with external metric 10 can be preferred to one with external metric 20 even if reaching the first exit requires a much longer internal path. E2 should therefore not be interpreted as simply another additive shortest-path calculation.
External LSAs can contain a forwarding address. When this address is zero, forwarding normally proceeds toward the advertising ASBR. A nonzero forwarding address instead identifies another forwarding destination whose reachability must satisfy OSPF’s rules. This permits traffic to avoid an unnecessary detour through the advertising router in suitable network configurations. Consequently, the LSA originator and the eventual forwarding next hop need not be the same device.
Redistribution also introduces problems that the internal shortest-path algorithm cannot resolve by itself. If two routing domains redistribute routes into one another, a route may return to its source with altered attributes. External route tags provide information that policy can use to identify such routes, but the tag does not automatically enforce loop prevention. Prefix selection, metric assignment, and policy determine what information crosses the boundary.
Default routes are a special but important application of these mechanisms. An ASBR can advertise a default as an external route, while stub-area defaults are supplied by ABRs through the area’s inter-area mechanism. These defaults have different origins and selection behavior, even though both describe the destination prefix of length zero.
OSPFv2, OSPFv3, and address-family support
OSPFv2 and OSPFv3 share the same basic architecture: neighbor discovery, adjacency formation, reliable flooding, area-based databases, and shortest-path calculation. They nevertheless differ in packet formats, LSA organization, addressing assumptions, and security integration. They cannot establish a single mixed-version adjacency. A device supporting both typically runs separate protocol instances or processes, with any exchange of routes between them requiring an additional mechanism.
OSPFv2 was designed around IPv4. Its advertisements combine topology and address information in ways that reflect that environment. Router-LSAs, for example, may describe stub networks as part of the router’s topology information. OSPFv3 separates topology from prefixes more explicitly. Router-LSAs and network-LSAs describe connectivity, while other advertisement types carry address-prefix information.
In OSPFv3, link-LSAs communicate link-local information, including the router’s link-local address and prefixes associated with the link. Intra-area-prefix-LSAs associate IPv6 prefixes with router or network topology information. Inter-area-prefix-LSAs and inter-area-router-LSAs perform roles corresponding broadly to OSPFv2’s inter-area network and ASBR advertisements. This separation reduces the extent to which a prefix-only change has to alter the core topology description.
OSPFv3 ordinarily uses IPv6 link-local addresses for communication between neighboring routers. Its multicast groups include ff02::5 for AllSPFRouters and ff02::6 for AllDRouters. Router IDs and area IDs remain 32 bits; moving to IPv6 did not make these identifiers 128-bit IPv6 addresses. The protocol also includes an Instance ID field, supporting separation of instances on a link under the applicable specification rules.
Flooding scope is encoded more systematically in the OSPFv3 LSA type. The design distinguishes link-local, area, and autonomous-system scope and defines handling for unrecognized LSA types. Extensibility is important because different routers may support different optional functions. OSPFv2’s opaque-LSA extension, specified in RFC 5250, provides another extensible container, with Types 9, 10, and 11 corresponding to link-local, area, and autonomous-system flooding scopes.
Although OSPFv3 began as an IPv6 routing protocol, RFC 5838, published in 2010, defined support for multiple address families, including IPv4 unicast. Thus, “OSPFv2 for IPv4 and OSPFv3 for IPv6” is a useful historical simplification rather than a complete description of current capabilities. Address-family support depends on the implementation and deployment configuration.
Security also differs between versions. OSPFv2 includes authentication-related fields in its packet structure. OSPFv3 removed the corresponding built-in authentication design, initially relying on IPv6 IPsec mechanisms; a later authentication-trailer specification provided another way to protect OSPFv3 packets. These are distinct security arrangements, not evidence that one version automatically authenticates traffic whenever it is enabled.
Convergence, scaling, and routing applications
Convergence is the process by which routers detect a change, distribute updated information, calculate replacement routes, and update forwarding state. These are separate stages. A network may detect a failed physical link almost immediately but still require time to originate advertisements, complete calculations, and program forwarding hardware. Conversely, a silent forwarding failure may persist until a liveness mechanism detects it, even when subsequent routing calculations are fast.
Hello and dead timers provide protocol-level neighbor failure detection. Physical interface status can provide a faster signal for local link failures. Bidirectional Forwarding Detection (BFD), where supported and associated with the OSPF adjacency, can detect forwarding-path failures independently of the normal Hello interval. BFD accelerates failure detection; it does not replace OSPF’s topology distribution or route computation.
Implementations commonly pace LSA origination and schedule shortest-path calculations to balance responsiveness against stability. Recalculating immediately after every event can waste processing capacity during a burst of changes. Excessive delay, however, prolongs stale routing. SPF throttling, LSA pacing, incremental calculations, and implementation-specific optimizations address different portions of this trade-off. There is no single convergence time inherent to all OSPF networks.
Even a correct link-state protocol can experience transient forwarding loops during convergence. Routers do not all install their new routes at exactly the same instant. For a short period, one router may forward according to the new topology while another still uses the old topology, causing packets to circulate. Fast-reroute mechanisms, including loop-free alternates where applicable, can provide precomputed repairs, but their coverage depends on topology and the particular mechanism.
Scaling depends on more than the number of destination prefixes. Relevant factors include routers and links per area, adjacency count, LSA volume, change frequency, external-route population, and the processing capacity of participating devices. Hierarchical areas contain topology changes, while summarization can reduce information crossing boundaries. A single broadcast segment with many routers creates a different load from the same routers distributed across point-to-point links.
Graceful-restart mechanisms allow a restarting router to preserve forwarding while neighbors temporarily assist its control-plane recovery. For OSPFv2, RFC 3623 defines a standardized mechanism using grace-LSAs. The benefit depends on assumptions about topology stability and retained forwarding state; graceful restart does not make every control-plane failure harmless.
Beyond basic reachability, OSPF can distribute information for traffic engineering. Extensions advertise attributes such as link bandwidth and administrative groups, allowing a separate path-computation mechanism to consider constraints beyond ordinary OSPF cost. Such information has been used with Multiprotocol Label Switching (MPLS). Segment routing extensions likewise advertise identifiers and capabilities used to construct forwarding paths. These extensions enrich the information carried by OSPF without making the base shortest-path algorithm inherently bandwidth-reserving or congestion-aware.
Authentication, attack exposure, and operational boundaries
OSPF influences where packets travel, making its control traffic a security-sensitive part of network operation. A forged adjacency or false topology advertisement can change forwarding, create black holes, or consume control-plane resources. Its usual link-local transmission limits routine exposure, but it is not an authorization mechanism. A device connected to an OSPF-enabled segment may be in a position to send protocol packets unless other controls restrict participation.
The original OSPFv2 specification defines null authentication, simple password authentication, and cryptographic authentication. Simple authentication carries a password without cryptographic confidentiality and does not provide strong protection against an observer on the link. Cryptographic authentication uses a shared secret and a packet authentication value to provide integrity and evidence that the sender possesses the key. Authentication does not normally conceal topology contents.
Early cryptographic deployments commonly used keyed MD5. RFC 5709 added HMAC-SHA authentication for OSPFv2, and RFC 7474 further addressed replay protection and related security behavior. For OSPFv3, IPsec-based protection and the authentication trailer specified in RFC 7166 provide standardized mechanisms with different deployment characteristics. Successful interoperability requires agreement on the applicable mechanism, keys, algorithms, and relevant parameters.
Packet authentication must be distinguished from the LSA checksum. The checksum detects accidental corruption but is not a cryptographic proof of origin. Sequence numbers and age fields support freshness and database consistency, but by themselves do not stop an attacker capable of injecting acceptable protocol traffic. Similarly, a shared authentication key proves membership in a key-sharing group rather than independently certifying the correctness of every route originated by a member.
An authenticated router can still advertise incorrect information because of misconfiguration, software defects, or compromise. OSPF’s database synchronization spreads accepted information consistently; it does not establish that the underlying claim is true. External-route redistribution is particularly important in this respect because a boundary router can introduce large numbers of destinations or an unintended default route.
OSPF also presents a denial-of-service surface. Excessive Hellos, adjacency churn, malformed traffic, or rapid LSA changes can consume processing and memory even without sustained user-data traffic. Implementations therefore combine protocol validation with operational controls such as control-plane policing, restricted interface participation, and limits on selected resources. A passive interface commonly allows an attached prefix to be advertised without sending Hellos or forming neighbors on that interface, although precise behavior is implementation-dependent.
Operational diagnosis separates several kinds of evidence: neighbor state shows adjacency progress, the link-state database shows received protocol information, the routing table shows selected routes, and the forwarding table shows programmed packet handling. A Full adjacency alone does not prove that an expected external prefix was redistributed, and a route in the routing table does not prove successful end-to-end forwarding. Each represents a different boundary between OSPF’s control-plane operation and the network carrying actual traffic.