අන්තර්ගතයට යන්න
mcqdinethlive

Layer 2 vs Layer 3 switch differences and real uses

How a Layer 2 switch and a Layer 3 switch differ, why each exists, where networks use them now and next, and the A/L ICT past paper questions that test them, with answers.

සිංහලෙන් කියවන්න

This post explains the difference between a Layer 2 switch and a Layer 3 switch in Unit 6. A Layer 2 switch forwards frames by MAC address inside one LAN. A Layer 3 switch also routes packets by IP address between networks, as a router does (6.5, 6.7).

The post has four parts:

  • The basis: what the syllabus, the Teachers' Guides and the papers give, and the layer each device works at (section 1).
  • The two devices: how a Layer 2 switch forwards, and what a Layer 3 switch adds (sections 2 and 3).
  • Why and where: why both kinds exist, with VLANs, and where networks use them now and next (sections 4 and 5).
  • The exam: past paper questions with answers, and questions to try (section 6).

1. Where switches and routers sit in the layers

The number in "Layer 2" and "Layer 3" is the OSI layer that the device reads. Layer 2 is the data link layer, with frames and MAC addresses. Layer 3 is the network layer, with packets and IP addresses (Syllabus 6.10, page 24) (විෂය නිර්දේශය 6.10, පිටු 22 සහ 23).

What the books give

The English Teachers' Guide gives the job of the data link layer as "Access to media", and the job of the network layer as "Addresses and best path". It gives frames and packets as their data units (Teachers' Guide 6.10, page 162) (ගුරු අත්පොත 6.10, පිටුව 187). Both Guides match the data link layer to the TCP/IP network access layer, and the network layer to the internet layer (Teachers' Guide 6.10, page 163) (ගුරු අත්පොත 6.10, පිටුව 187).

For devices, the Guides say that a switch "forwards the data only on the outgoing connection which connects to the destination device". A hub forwards to all its connections (Teachers' Guide 6.5, page 152) (ගුරු අත්පොත 6.5, පිටුව 168). Routers find a path between networks with routing tables (Teachers' Guide 6.7, page 157) (ගුරු අත්පොත 6.7, පිටුව 176).

What the books do not give

Neither the syllabus nor the Teachers' Guides use the words "Layer 2 switch", "Layer 3 switch" or "VLAN". The books teach one kind of switch and one router. One paper went further: 2019 (New Syllabus) P-I Q35 talks about VLAN settings and a switch that uses "frames and packets". Section 6 explains that question.

Book errors to know

  • The English Guide says the network access layer "consists of routing for accessing physical network" (Teachers' Guide 6.10, page 161). This layer does not route. The Sinhala Guide is right here: it says the layer gives access to the physical network (ගුරු අත්පොත 6.10, පිටුව 186).
  • The English Guide gives "Bytes" as the data unit of the physical layer (Teachers' Guide 6.10, page 162). The syllabus says "packet, frame and bit" (Syllabus 6.10, page 24). Learn bits.
  • The Sinhala Guide's OSI table gives the network layer the job "ස්විච්කරණය" (switching) (ගුරු අත්පොත 6.10, පිටුව 187). That word means packet switching (6.7), not the switch device. The switch in the syllabus is a data link device.
  • The Sinhala Guide's data link row says only that the layer turns packets into bits and back (ගුරු අත්පොත 6.10, පිටුව 187). It leaves out MAC addresses and frames, which the syllabus lists (Syllabus 6.6, page 21) (විෂය නිර්දේශය 6.6, පිටුව 20).
  • The Sinhala books use different words for one device. The Sinhala syllabus says "සුවිච" (විෂය නිර්දේශය 6.5, පිටුව 20), the Sinhala Guide says "ජාලකරණ ස්විච්ය" (ගුරු අත්පොත 6.5, පිටුව 168), and the papers say "ජාල ස්විචය" (2025 P-I Q19) or "ස්විචය" (2023 (held 2024) P-I Q19). The Sinhala Guide calls a router "මංහසුරුව" (ගුරු අත්පොත 6.7, පිටුව 176).

2. What a Layer 2 switch does

A Layer 2 switch reads the destination MAC address in each frame and sends the frame out of one port only. It does not read the IP address (6.5, 6.6).

Learn forward and flood

The switch keeps a MAC address table. Each row joins one MAC address to one port. The switch does three things:

  1. Learn: a frame arrives. The switch writes the source MAC address and the arrival port into the table.
  2. Forward: the table has the destination MAC address. The switch sends the frame out of that one port.
  3. Flood: the table does not have the destination, or the frame is a broadcast. The switch sends the frame out of every port except the arrival port.

A hub always floods (Teachers' Guide 6.5, page 152) (ගුරු අත්පොත 6.5, පිටුව 168). A switch floods only until it learns. That is why the Guide calls a switch "a more intelligent device than a hub".

One LAN and one broadcast domain

All the devices on a group of Layer 2 switches are in one LAN, and a broadcast frame reaches all of them. The syllabus lists broadcasting and unicasting under the MAC protocol (Syllabus 6.6, page 21) (විෂය නිර්දේශය 6.6, පිටුව 20). For example, a new computer sends its DHCP request as a broadcast, because it does not know the server yet (6.7). The network access layer also "maps IP addresses to physical addresses in Ethernet" (Teachers' Guide 6.10, page 161) (ගුරු අත්පොත 6.10, පිටුව 186), and that lookup is a broadcast too.

A bigger flat LAN puts more broadcasts on every port. That cost is the reason for Layer 3 devices inside large LANs (section 4).

What a Layer 2 switch cannot do

A Layer 2 switch cannot move a packet to another IP network. A computer in 192.168.10.0/24 that sends to 192.168.20.5 gives the frame to its gateway (6.7). With no router and no Layer 3 switch, the two networks cannot talk, even when their cables meet at one Layer 2 switch.

3. What a Layer 3 switch adds

A Layer 3 switch is a switch with a router inside. Inside one network, it forwards frames by MAC address, like a Layer 2 switch. Between networks, it reads the destination IP address of the packet and routes it with a routing table, like a router (6.7).

What changes at a Layer 3 hop

A packet crosses a Layer 3 device inside a new frame. The IP addresses stay the same from end to end. The MAC addresses change at each Layer 3 hop:

  • IP header: source computer A and destination computer B, on both sides.
  • Frame in LAN 1: source MAC A, and destination MAC of the gateway port on LAN 1.
  • Frame in LAN 2: source MAC of the gateway port on LAN 2, and destination MAC B.

A Layer 2 switch does not change the MAC addresses in a frame. A router and a Layer 3 switch build a new frame for the next network. This one fact answers a whole Paper II question (section 6).

Layer 3 switch and router compared

Both route packets by IP address. They differ in where they work and in their other jobs:

  • Ports: a Layer 3 switch has many Ethernet ports, often 24 or 48. A router usually has a few.
  • Speed: a Layer 3 switch routes in special chips (ASICs), at the full speed of each port. Many small routers route in software on a general processor.
  • Place: a Layer 3 switch routes between networks inside one site. A router joins the site to other sites and to the ISP (6.12).
  • Other jobs: a router usually does NAT, firewall rules and VPNs, and has WAN links such as fibre, DSL or 4G. A Layer 3 switch usually has few or none of these.

So a large school puts a Layer 3 switch at the centre of its LAN and still keeps a router at the edge. The books teach a router as the device between two LANs (Teachers' Guide 6.7, page 157) (ගුරු අත්පොත 6.7, පිටුව 176). Draw a router in Paper II unless the question names a Layer 3 switch.

4. Why both kinds exist

Layer 2 switching is cheap and fast, but all its devices share one broadcast domain. Layer 3 routing splits a network into smaller networks, but it needs more work for each packet. So networks use both: Layer 2 near the users, and Layer 3 where networks meet.

The problem with one flat LAN

Think of a school with 400 devices on one Layer 2 network. That is one broadcast domain of 400 devices, so every broadcast reaches every port. A loop or a virus in one lab can reach the office too. The office, the labs and the Wi-Fi also share one network, so it is hard to keep them apart for security.

VLANs split one switch into many LANs

A VLAN (virtual LAN) is a group of switch ports that acts as a separate LAN. The office ports can be VLAN 10, the lab ports VLAN 20 and the staff Wi-Fi VLAN 30. Each VLAN is its own broadcast domain, and usually its own IP subnet (6.7).

Between switches, one trunk cable carries many VLANs, and each frame carries a VLAN tag. The tag standard is IEEE 802.1Q. The VLAN ID has 12 bits, so it has 2 to the power 12 = 4,096 values, and 4,094 of them are usable (3.1).

VLANs are a Layer 2 tool. A frame in VLAN 10 cannot reach VLAN 20 at Layer 2. To join them, a Layer 3 device must route between the two subnets.

Two ways to route between VLANs

  • A router on one trunk link ("router on a stick"): one router port carries all the VLANs. Every packet between VLANs goes up to the router and back down the same cable. This is cheap, but that one link becomes a bottleneck.
  • A Layer 3 switch: the switch has one virtual interface for each VLAN, with the gateway IP address of that subnet. It routes between the VLANs inside its own chips, at the full speed of its ports.

This is the main reason Layer 3 switches exist: fast routing between many subnets inside one site. The router stays at the edge for NAT and for the link to the ISP (6.12).

5. Where networks use them now and next

Almost every network today uses Layer 2 switches at the edge and Layer 3 devices in the middle. The mix changes with the size of the network.

Uses today

  • Home: the home "router" box is three devices in one. It holds a router with NAT, a small Layer 2 switch for the LAN ports, and a Wi-Fi access point. An extra low-cost switch at home is an unmanaged Layer 2 switch.
  • School and office: the access switches near users are Layer 2, often managed with VLANs. Many of them also power Wi-Fi access points, IP phones and cameras through the same cable, with Power over Ethernet (PoE). A Layer 3 switch at the core routes between the VLANs, and a router or firewall joins the site to the ISP.
  • Data centres and cloud: large data centres use a leaf and spine design. Every leaf switch connects to every spine switch, and each link is a routed Layer 3 link. Traffic between two servers can take one of many equal paths, so no single link is a bottleneck. Here almost every switch is a Layer 3 switch.
  • Factories and vehicles: industrial Ethernet switches connect sensors, machines and controllers (Unit 11). Time-Sensitive Networking (TSN) adds timing guarantees, so a control message arrives on time.

What comes next

  • Overlay networks: a data centre runs a Layer 3 network underneath and carries Layer 2 networks inside it for virtual machines. VXLAN is described in RFC 7348, and EVPN in RFC 7432.
  • Programmable switches and SDN: in Software-Defined Networking, a central program decides the forwarding rules, and the switches follow them. Languages such as P4 program the switch chip itself.
  • Faster Ethernet for AI: AI training joins thousands of GPUs with very fast links. IEEE 802.3df (2024) defines 800 Gb/s Ethernet. The Ultra Ethernet Consortium published its first specification in 2025 for AI and high-performance networks.
  • Faster edge ports: Wi-Fi 7 (IEEE 802.11be) access points can need more than 1 Gb/s. So new access switches have 2.5 and 5 Gb/s ports (IEEE 802.3bz) and stronger PoE (IEEE 802.3bt, up to 90 W at the switch port).
  • IPv6: Layer 3 switches and routers route IPv6 as well as IPv4. An IPv6 address has 128 bits, against 32 bits for IPv4 (6.7).

6. Past paper questions on switches and routers

The papers test this topic in three ways. They ask the job of a switch, the layer and address of each device, and the path of a packet between LANs. Each answer below names its source.

Paper I

  • 2019 (New Syllabus) P-I Q35 gives four statements on hubs and switches. The official key is (1): A, B and C. B is true for a managed switch, which has port and VLAN settings. C says a switch "uses frames and packets". That is true only for a switch with Layer 3 functions, because a Layer 2 switch uses frames only. D is wrong: a hub shares one bandwidth among all its ports, so it is not faster. A is a weak statement, because a hub also connects networked devices, but the official key accepts it.
  • 2025 P-I Q19 asks the basic job of a network switch. The official key is (2): it connects devices in a LAN and forwards frames by MAC address. Option (1), to amplify and regenerate the signal, is a repeater at the physical layer. Option (3), to connect several networks and direct traffic between them, is the job of a router. A Layer 3 switch can also do (3), but the question asks for the basic job of a switch. Option (4) is encryption, and option (5) is DNS.
  • 2026 P-I Q14 asks in what form a switch in a school lab LAN sends data. Our own worked answer, not official: (4), frames. A Layer 2 switch reads MAC addresses, and MAC addresses are in frames. Packets are the Layer 3 unit, and bits are the physical layer unit.
  • 2022 (held 2023) P-I Q16 gives three statements on MAC and IPv4 addresses. The key from a third-party scheme is (5), B and C. A MAC address has 48 bits and is used at the data link layer. An IPv4 address has 32 bits and is used at the network layer. Statement A is wrong on both points.
  • 2023 (held 2024) P-I Q19 matches five devices to their jobs. The key is (4), from a third-party copy of the official key. The switch (E) is 3: it sends a message only to the port of the destination computer. The hub (B) is 5: it broadcasts to all ports. The router (C) is 2: it connects a LAN and a WAN.

Paper II

  • 2016 Paper II, B, Q2 (old syllabus) joins LANs L1 and L2 with router R, and machine P sends an IP packet to machine Q. Part (b) asks whether the destination IP address in L1 is that of Q or R. Part (c) asks whether the source MAC address of the frame in L2 is that of P or R. Our own worked answer, not official: (b) Q, because IP addresses stay the same from end to end. (c) R, because R builds a new frame for L2 (section 3). The question itself says "An IP address is recognized by the network layer but it is not recognized by the data link layer". That one sentence is the Layer 2 and Layer 3 split.
  • 2024 Paper II, B, Q6(b) gives two department LANs, A and B, with a shared server. It asks for the network diagram, the reason for each device, and the path of data from C1 to C6. Our own worked answer, not official: put a switch in each department and one router that joins the two LANs and the Internet. The path is C1, switch of A, router, switch of B, C6. In a real building a Layer 3 switch could join the two departments, but the Internet link still needs a router. In the exam, draw a router, because the books teach the router (section 3).

More questions to try

These questions have no answers in this post.

  • 2024 P-I Q21: what a hub does with a frame (section 2).
  • 2025 P-I Q20: statements on the MAC protocol (section 2).
  • 2023 (held 2024) Paper II, B, Q6(a): a star topology with a switch (section 2).
  • 2022 (held 2023) Paper II, B, Q6(c)(ii): the functions of a router (section 3).
  • 2020 Paper II, A, Q3(b)(iii): the TCP/IP layer for addressing and routing (section 1).
  • 2024 Paper II, B, Q6(e): the TCP/IP layer for each job (section 1).
  • 2019 (New Syllabus) Paper II, B, Q2(c): a network diagram with switches, a router, a firewall and servers (section 4).

Sources

  • G.C.E. (A/L) Information and Communication Technology Syllabus, National Institute of Education, 2017, levels 6.5 to 6.10, English and Sinhala medium.
  • Grade 12 Information and Communication Technology Teachers' Guide, National Institute of Education, English and Sinhala medium.
  • G.C.E. (A/L) ICT question papers 2016 to 2026, Department of Examinations, Sri Lanka.
  • IEEE 802.1Q (VLAN tags), IEEE 802.3bz (2.5 and 5 Gb/s Ethernet), IEEE 802.3bt (PoE), IEEE 802.3df (800 Gb/s Ethernet) and IEEE 802.11be (Wi-Fi 7).
  • RFC 7348 (VXLAN) and RFC 7432 (EVPN), Internet Engineering Task Force.
  • Ultra Ethernet Specification 1.0, Ultra Ethernet Consortium, 2025.

මේ Explained එක බෙදාගන්න

A/L ICT කරන යාළුවෙකුට යවන්න.

මේ ලිපියට link කරන ලිපි

  1. English

    Layer 2 and Layer 3 switches 101

    A Layer 2 switch forwards frames by MAC address inside one LAN, and a Layer 3 switch also routes packets by IP address between networks. Why both exist, where they work today, and the past paper questions that test them.

තවත් Explained

  1. A/L ICT second attempt study plan for 2027 by unit weight and past papers

    A study plan for students who sit A/L ICT again in 2027. It covers the 2026 results, the units that carry most marks, a lesson method with past papers, a month by month timeline and the free papers on this site.

    Englishපියවර 7ක්
  2. Python functions with lists of tuples and sequential search in 2026 Paper II Q9

    2026 Paper II Q9 worked part by part. The fine rule and its two readings, a function with if and elif, a list of tuples built with a loop, a sequential search that returns -1, and the same skills in Paper I.

    Englishපියවර 7ක්
  3. Normalisation by spotting dependencies from 1NF to 3NF

    One four-step method for every A/L ICT Paper II normalisation question. Find the key, draw the dependencies, name the normal form and split the table, proved on all eight papers from 2019 to 2026.

    Englishපියවර 6ක්
All Explained