Module 1 · Beginner · Start here

Network topologies: bus, star, ring and mesh

Network topologies explained: bus, star, ring, mesh, tree and hybrid, physical vs logical topology, pros and cons, and link failures tested in Python.

By theprogrammers team · · 10 min read

The Wi-Fi router in a café stops working and every laptop loses the internet. In a data centre, a switch fails and nobody notices, because traffic quietly takes another path. The difference isn't luck; it's the topology: the shape in which devices and links are connected. The shape decides how much cable you need, how easy the network is to grow, and, most importantly, what breaks when one part fails.

This lesson covers the classic network topologies (bus, star, ring and mesh) plus tree and hybrid, the difference between physical and logical topology, and where each is used today. You'll also test, in Python, what happens to each shape when a device or cable fails.

What you need first: types of networks: LAN, WAN, MAN and PAN.

Key terms

  • Topology: the arrangement of devices (nodes) and the links between them.
  • Physical topology: how cables and devices are actually laid out.
  • Logical topology: how data actually flows, which can differ from the physical layout.
  • Single point of failure: one part whose failure takes down all or much of the network.
  • Redundancy: extra links or devices, so there's another path when one fails.
  • Hub / switch: the central device in a star. A hub repeats data to every port; a switch sends it only where it's going.

The topologies at a glance

 Bus                      Star                    Ring
 A   B   C   D               A                    A ─── B
 │   │   │   │               │                    │     │
 ═══════════════      B ── [switch] ── C           E     C
 (one shared cable)          │                     ╲   ╱
                             D                       D

 Mesh (full)              Tree
   A ─── B                    [core]
   │ ╲ ╱ │                   /      \
   │ ╱ ╲ │             [switch]    [switch]
   C ─── D              /   \       /   \
                       A     B     C     D
TopologyShapeMain strengthMain weaknessWhere you see it today
BusEvery device on one shared cableVery little cableOne cable fault stops everything; only one device can send at a timeRare; old coaxial Ethernet, some car and factory networks (CAN bus)
StarEvery device to one central switchSimple, easy to add devices, one cable fault affects only one deviceThe central device is a single point of failureAlmost every home and office LAN
RingEach device to two neighbours in a loopPredictable, no collisionsOne break can stop a simple ringFibre rings in cities (usually dual rings)
MeshDevices with many links between themMany paths, survives failuresLots of links and costThe internet's core, data centres, mesh Wi-Fi
TreeStars connected in layersScales to big buildingsFailure of an upper switch cuts off a whole branchCampus and office networks
HybridA mix of the aboveFits real needsMore complexNearly every large network

Bus

All devices connect to one shared cable (the bus), with terminators at the ends. When one device sends, every other device receives it and keeps only what's addressed to it. Only one device can send at a time, or signals collide.

A bus needs very little cable, but a single break or loose connector takes the whole network down, and it gets slower as devices are added. Early Ethernet in the 1980s and 1990s used a coaxial bus; it's almost gone from office networks. The idea survives in cars, where the CAN bus connects the engine, brakes and dashboard controllers on shared wires.

Star

Every device has its own cable to a central device, today a switch (or a Wi-Fi access point for wireless devices). This is the topology of almost every home and office LAN.

  • Easy to manage: plug in a new device, and a faulty cable affects only one device.
  • The centre is critical: if the switch or router fails, every device loses the network. That's the café example.

The old central device, a hub, repeated every signal to every port, so a star with a hub behaved like a bus. A switch learns where each device is and sends data only to the right port, so many devices can talk at once. Cables, Wi-Fi and switches get their own module later in this course.

Ring

Each device connects to exactly two neighbours, forming a loop, and data travels around the ring from device to device. In a simple ring, one broken link or failed device breaks the loop.

Real rings use two rings running in opposite directions, so if one link is cut, traffic turns back and goes the other way round. ISPs and cities lay fibre in rings for exactly this reason: a digger cutting one cable doesn't cut off a whole neighbourhood. The old Token Ring and FDDI LAN technologies were rings.

Mesh

In a mesh, devices have links to several others, so there are many possible paths.

  • Full mesh: every device connects directly to every other. With n devices, that's n × (n − 1) ÷ 2 links, which grows very quickly.
  • Partial mesh: important devices have several links; others have fewer. This is what's actually built.
for n in [5, 10, 50, 100]:
    print(f"{n} devices need {n * (n - 1) // 2:,} links for a full mesh")
5 devices need 10 links for a full mesh
10 devices need 45 links for a full mesh
50 devices need 1,225 links for a full mesh
100 devices need 4,950 links for a full mesh

That's why full meshes are only used for a few critical devices. The internet's backbone, data-centre networks (where every "leaf" switch connects to every "spine" switch), and mesh Wi-Fi systems at home (where several access points link to each other) are all partial meshes.

Tree and hybrid

A tree (hierarchical star) connects stars in layers: a core switch connects to a switch on each floor, and each floor switch connects to its desks. It scales well, but if a floor switch fails, that whole floor is cut off. Large networks add redundant links between the upper layers to avoid this.

Most real networks are hybrids: stars at the edge (each office floor), a partial mesh in the core, and maybe a ring for the city links.

Testing failures in Python

You can model a network as a list of links and check whether every device can still reach every other one after a failure. This uses a breadth-first search: start at one device and keep visiting its neighbours until you run out.

from itertools import combinations

def all_connected(nodes, links):
    nodes = set(nodes)
    if not nodes:
        return True
    neighbours = {n: set() for n in nodes}
    for a, b in links:
        if a in nodes and b in nodes:
            neighbours[a].add(b)
            neighbours[b].add(a)
    start = next(iter(nodes))
    seen, queue = {start}, [start]
    while queue:
        current = queue.pop(0)
        for nxt in neighbours[current] - seen:
            seen.add(nxt)
            queue.append(nxt)
    return seen == nodes

devices = ["A", "B", "C", "D", "E"]

star_nodes = devices + ["switch"]
star_links = [("switch", d) for d in devices]
ring_links = [("A", "B"), ("B", "C"), ("C", "D"), ("D", "E"), ("E", "A")]
mesh_links = list(combinations(devices, 2))

print("Star, all working:   ", all_connected(star_nodes, star_links))
print("Star, switch fails:  ", all_connected(devices, star_links))
print("Ring, one link cut:  ", all_connected(devices, ring_links[1:]))
print("Ring, two links cut: ", all_connected(devices, [ring_links[1], ring_links[2], ring_links[4]]))
print("Mesh, three links cut:", all_connected(devices, mesh_links[3:]))
Star, all working:    True
Star, switch fails:   False
Ring, one link cut:   True
Ring, two links cut:  False
Mesh, three links cut: True
  • The star works perfectly until its centre fails; then no device can reach any other.
  • A ring survives one cut (traffic goes the other way round) but not two.
  • The 5-device full mesh still connects everyone after losing 3 of its 10 links.

Network engineers think exactly like this: "what's the single point of failure, and what happens when it goes?"

Physical vs logical topology

The physical layout and the way data flows can differ:

  • An office with every desk cabled to a switch is a physical star. But all devices on it can be one shared network, logically.
  • Old hub-based Ethernet was a physical star but a logical bus, because the hub repeated everything to everyone.
  • VLANs split one physical switch into several logical networks, as the switching module will show.
  • In the cloud, there's no physical topology you can see at all, only logical ones that you design.

Practice

  1. Which topology does a typical home Wi-Fi network use, and what's its single point of failure?
Show the answer

A star, with the Wi-Fi router at the centre. The router is the single point of failure: if it stops working, every device loses the network.

  1. How many links does a full mesh of 8 devices need? Check in Python.
Show the answer
print(8 * 7 // 2)
28
  1. Why do ISPs lay city fibre as rings instead of stars?
Show the answer

A ring gives every location two paths. If one fibre is cut, traffic goes the other way round the ring. In a star, a cut cable would cut off that location completely.

  1. Using all_connected, check whether the star stays connected if only the cable between the switch and device A is cut.
Show the answer
def all_connected(nodes, links):
    nodes = set(nodes)
    neighbours = {n: set() for n in nodes}
    for a, b in links:
        if a in nodes and b in nodes:
            neighbours[a].add(b)
            neighbours[b].add(a)
    start = next(iter(nodes))
    seen, queue = {start}, [start]
    while queue:
        current = queue.pop(0)
        for nxt in neighbours[current] - seen:
            seen.add(nxt)
            queue.append(nxt)
    return seen == nodes

devices = ["A", "B", "C", "D", "E"]
star_links = [("switch", d) for d in devices]
print(all_connected(devices + ["switch"], star_links[1:]))
print(all_connected(["B", "C", "D", "E", "switch"], star_links[1:]))
False
True

The network as a whole is no longer fully connected, because A is cut off. But every other device can still reach the rest: one cable fault in a star only affects one device.

  1. What's the difference between physical and logical topology? Give an example.
Show the answer

Physical topology is how cables and devices are laid out; logical topology is how data actually flows. A hub-based network was cabled as a star (physical) but behaved like a bus (logical), because the hub repeated every message to every device.

Interview questions

What are the main network topologies, and which is most common?

Bus, star, ring, mesh, tree and hybrid. Star is the most common for LANs, using a central switch or access point. Real networks are usually hybrids: stars at the edge with partial-mesh or redundant cores.

What is a single point of failure, and how do you avoid it?

A component whose failure takes down the whole system or a large part of it, such as the central switch in a star. Avoid it with redundancy: duplicate devices and links, multiple paths (mesh or dual rings), and failover protocols.

Key takeaways

  • Topology is how devices and links are arranged; it decides cost, growth, and what fails when a part breaks.
  • Star is the standard LAN layout, simple to manage, but its central device is a single point of failure.
  • Rings (usually dual) survive one cut; meshes survive many, but a full mesh needs n(n − 1)/2 links.
  • Real networks are hybrids: stars at the edge, partial meshes in the core.
  • Physical topology is the cabling; logical topology is how data flows.

Frequently asked questions

Which topology is best?

It depends on the job. Star is best for most LANs because it's simple and cheap. Mesh is best where staying up matters most, like the internet's core or a data centre. Large networks combine them.

What topology does the internet use?

A huge partial mesh: many networks connected to several others, so data can take many paths. Inside, each network has its own mix of topologies.

What is mesh Wi-Fi?

A home Wi-Fi system with several access points that connect to each other wirelessly, forming a mesh. It covers larger homes evenly, and if one point is moved or switched off, the others can still route around it.

What to learn next

  1. Learn the words you'll meet throughout the course in networking terms every beginner should know.
  2. Start the network models module with the OSI model, layer by layer.
  3. Revise network sizes in types of networks.