Devices within a given VLAN (e.g. VLAN 5) will all need to be on the same subnet. And devices in different VLANs (e.g. VLAN 5 vs VLAN 10) will need to be assigned to different subnets. Therefore in order for hosts on one VLAN (e.g. VLAN 5) to talk to hosts in a different VLAN (e.g. VLAN 10) we need to be able to route between them at layer 3. Remember VLANs are a Layer 2 concept whereas routing happens at Layer 3 – technically we don’t route between VLANs, we route between the subnets which the devices within the VLANs belong to!
Routers are Layer 3 devices which can route packets between the different subnets on a network. Therefore if a router is connected to multiple VLANs (each with devices on a different subnet) then it can route packets between them. In some cases, different VLANs may be connected to the router on different interfaces, potentially from multiple switches.
Sometimes in a network, there is just a single switch with multiple VLANs that we need to route between. In this case, we can use a VLAN trunk between the switch and the router to carry all of the VLANs we want to route between. This trunk (the ‘stick’ which the router is on) occupies only a single interface on the switch and router which frees up ports for more hosts! This topology, where the router has a single connection to a network, can also be called a one-armed router.
Originally, network switches were strictly Layer 2 devices. They would receive and forward Ethernet frames based on MAC address. There are still switches which operate just in this way and they can be referred to as layer 2 switches. Today it is possible to get switches which are able to route packets between VLANs and even perform functions all the way up to Layer 7. These switches are called multilayer switches, or sometimes layer 3 switches.
Multilayer switches can be thought of as having a virtual router built in. VLANs can then be connected to virtual interfaces on this built in router and then the packets can be routed between them at layer 3. This can remove the need to buy a dedicated router which can save money and simplify the network. For smaller networks multilayer switches can remove the need for dedicated routers. Multilayer switches don’t have the same routing capabilities as a full blown router –they’re likely to have smaller routing table capacities and be LAN focused as opposed to WAN focused like a router.