OSPF is a dynamic routing protocol that uses a link-state algorithm (Dijkstra), as opposed to protocols (such as RIP) that use a distance-vector algorithm. It is an interior gateway protocol (IGP) and operates in a single autonomous system (AS).
In OSPF, each router advertises the state of its own links, or connections, in a link-state advertisement (LSA), which it then multicasts to other routers on the network. In addition, each router uses the LSAs that it receives from other routers to construct a directed graph with itself as the root representing the network topology.
To build its routing table, the router applies Dijkstra’s Shortest Path First algorithm within an area to find the best path through the graph to each network in the topology that is within the area. This “shortest path tree” becomes the basis of the routing table. OSPF is hierarchical. In OSPF, the network is divided into “areas.” Within each area, routers possess only local routing information. Routing information about other areas is calculated by using distance vector protocol and forming summarized routes. This reduces the amount of network topology information that routers have to generate and maintain, making OSPF a good choice for larger networks.