There are three use cases for virtual links:
- Fixing a “split brain” where your OSPF area 0 got broken up into two separate areas.
- Connecting areas to area 0 that are not directly connected.
- Fixing sub-optimal routing.
I’m guessing you learned about the first two options so let me give you an example for sub-optimal routing:
Above we have a simple network, all interfaces have a cost of 1 except the link between R1/R3 has a cost of 1000.
What route does R3 use when it wants to reach R1? You might think R3 > R4 > R2 > R1 since that’s the shortest path but that’s not the case here. OSPF will always prefer intra-area over inter-area so in this case, it means that R3 will use the direct link to R1 even though it’s not the shortest path.
One way to fix this is by using virtual links. If you create a virtual link between R2-R4 and R3-R4 then R3 will be able to use the path through R4 > R2 > R1.
Hope this helps!