Layer 2 is the data link layer: switches forward Ethernet frames by MAC address inside one local network or VLAN. Layer 3 is the network layer: routers and Layer 3 switches forward IP packets between networks by IP address, using a routing table. ARP links the two layers by finding the MAC address for an IP address on the local network.
Key takeaways
- Layer 2 forwards by MAC address inside one network; Layer 3 forwards by IP address between networks.
- A Layer 3 switch does both jobs: it switches frames and routes packets between VLANs in hardware.
- ARP is the bridge between the layers, and VLANs are a Layer 2 feature that needs Layer 3 to cross.
Every packet on your network passes through both Layer 2 and Layer 3, usually without you noticing. A switch moves it across the room; a router moves it across the building, the city, or the internet. Understanding which layer does what makes troubleshooting, VLAN design, and buying decisions far simpler.
What is Layer 2?
Layer 2 is the data link layer of the OSI model. It moves Ethernet frames from one device to another on the same local network, using MAC addresses to decide where each frame goes.
A MAC address is a 48-bit hardware address, usually written as six pairs of hexadecimal digits, such as 00:1A:2B:3C:4D:5E. It is tied to a network interface and normally does not change. When a switch receives a frame, it looks at the destination MAC address, checks its MAC address table for which port leads to that address, and forwards the frame out of that port only.
If the switch does not know the destination, it floods the frame to all ports in the same VLAN, and learns from the reply. That learning is what makes a switch smarter than a hub: after a short time, most traffic goes only where it needs to go.
Layer 2 does not change the IP header. It does not decrement the time-to-live value, and it does not choose a path across networks. Its job is local delivery, and it does that job very fast, usually in hardware at wire speed.
What is Layer 3?
Layer 3 is the network layer of the OSI model. It moves IP packets between different networks, using IP addresses and a routing table to choose the best next hop toward the destination.
An IP address is a logical address assigned to a device, such as 192.168.10.25. It can change when the device moves to another network, which is why it is suited to routing: the address describes where the device is in the network, not which piece of hardware it is.
A router keeps a routing table that maps network prefixes to a next hop and an outgoing interface. When a packet arrives, the router looks up the destination network, picks the best matching route, decrements the IPv4 time-to-live or IPv6 hop limit, rewrites the Layer 2 header for the next link, and sends the packet on its way.
Routers do not forward broadcasts between networks. That separation is deliberate: it keeps broadcast traffic, such as ARP requests and service discovery, inside one network instead of flooding the whole internet. Each network a router connects is its own broadcast domain.
Layer 2 vs Layer 3: what is the difference?
Layer 2 forwards frames by MAC address inside one network, while Layer 3 forwards packets by IP address between networks. The difference is the question each layer asks: Layer 2 asks which device on this link, and Layer 3 asks which network, and which next hop gets there.
| Aspect | Layer 2 | Layer 3 |
|---|---|---|
| OSI layer | Data link | Network |
| Unit of data | Frame | Packet |
| Address used | MAC address, 48-bit | IP address, IPv4 or IPv6 |
| Table it builds | MAC address table: MAC to port | Routing table: network prefix to next hop |
| Scope | One local network or VLAN | Between networks |
| Broadcasts | Forwarded to all ports in the VLAN | Not forwarded between networks |
| Changes to packet | None to the IP header | Decrements TTL or hop limit; rewrites Layer 2 header |
| Typical device | Switch, bridge | Router, Layer 3 switch |
| Typical use | Connecting hosts on one floor or in one VLAN | Connecting subnets, sites, and the internet |
The simple rule that a switch is Layer 2 and a router is Layer 3 is incomplete. Modern switches often route, and modern routers also switch. The device name tells you what it usually does; the forwarding behavior tells you what it actually does. Check the datasheet of the model you are buying.
How does a Layer 2 switch forward a frame?
A Layer 2 switch forwards a frame in three steps: learn, look up, and forward. It learns by watching the source MAC address of each frame that arrives, and recording which port it came from in its MAC address table.
When a frame arrives, the switch looks up the destination MAC address in that table. If it finds a match, it forwards the frame out of the recorded port only. If it does not find a match, it floods the frame to all ports in the same VLAN except the one it arrived on.
Broadcast frames, addressed to FF:FF:FF:FF:FF:FF, are always flooded within the VLAN. That is how a device asks the whole local network a question, such as who has a given IP address. The answer comes back as a unicast frame, and the switch learns from it.
Entries in the MAC table age out after a period of inactivity, typically a few minutes, so the table stays current as devices move or disconnect. A full table, or a table poisoned by spoofed addresses, can cause flooding, which is one reason to monitor switch tables on busy networks.
How does a Layer 3 device route a packet?
A Layer 3 device routes a packet by looking up the destination IP address in its routing table, choosing the longest matching network prefix, and sending the packet to the next hop for that prefix.
The routing table is built from three sources: directly connected networks, static routes entered by an administrator, and dynamic routing protocols such as OSPF and BGP that exchange reachability information with neighboring routers. A small network may use only static routes; a large one needs dynamic routing to adapt when links fail.
Each time a router forwards a packet, it decrements the time-to-live value. When that value reaches zero, the packet is dropped. That rule prevents packets from looping forever if the routing table has an error.
The router then rewrites the Layer 2 header for the next link, because the destination MAC address on each link is the next hop, not the final destination. The IP address stays the same end to end; the MAC address changes at every hop. That distinction is the key to understanding both layers.
How does ARP link Layer 2 and Layer 3?
ARP, the Address Resolution Protocol defined in RFC 826, links the two layers by finding the MAC address for an IP address on the local network. A host that wants to send an IP packet to a neighbor first asks, by broadcast, who has that IP address.
The host with that address replies with its MAC address, and the sender stores the pair in its ARP cache. The next packet to the same host needs no new request. ARP cache entries expire, typically within minutes, so stale mappings do not linger.
ARP only works on the local subnet: it cannot cross a router. When a host sends a packet to a distant network, it ARPs for its default gateway instead, and the gateway takes over from there. That is why the gateway address matters so much in host configuration.
ARP has no built-in authentication, which is why ARP spoofing works: an attacker on the same LAN can answer ARP requests with its own MAC address and intercept traffic. Switch features such as Dynamic ARP Inspection, and end-to-end encryption with TLS, reduce what that attack can achieve. Cisco's ARP notes describe the request and reply exchange in detail, and RFC 826 is the original specification.
What are VLANs, and why do they need Layer 3?
A VLAN, or virtual LAN, splits one physical switch into several logical Layer 2 networks, using the IEEE 802.1Q standard. Devices in different VLANs cannot hear each other's broadcasts, even though they share the same hardware.
VLANs are a Layer 2 feature, and they solve a Layer 2 problem: keeping traffic separate, limiting broadcast domains, and grouping devices by function rather than by location. A finance VLAN and a guest VLAN can live on the same switch without seeing each other.
Routing between VLANs is a Layer 3 job. Each VLAN is a separate IP subnet, so traffic between them must pass through a gateway that routes between the subnets. That gateway can be a router, a firewall, or a Layer 3 switch.
On a Layer 3 switch, the gateway for each VLAN is a switched virtual interface, or SVI: a virtual Layer 3 interface with an IP address in that VLAN's subnet. Hosts use the SVI address as their default gateway, and the switch routes between VLANs in hardware. Cisco documents this as inter-VLAN routing, and the same pattern appears on other vendors' switches under different names.
Layer 3 switch vs router: which should you use?
A Layer 3 switch routes in the same hardware that switches, which is why it became the default inside a site. It moves traffic between VLANs at close to wire speed, with low latency, and it needs no extra device or cable.
A router still guards the boundary. WAN links, VPNs, internet access, and most firewalling stay with a router or firewall, where advanced routing protocols such as BGP, traffic shaping, and security policy matter more than raw forwarding speed.
Not every Layer 3 switch is equal. Light Layer 3, sometimes called Layer 2+, offers static routes only. Full Layer 3 adds dynamic routing such as OSPF, and gateway redundancy with protocols such as VRRP. Read the datasheet before you assume a model can do what you need.
Three common designs cover most networks. Router-on-a-stick uses one router interface, with a sub-interface per VLAN, over a single trunk. A Layer 3 switch uses one SVI per VLAN and routes locally. A firewall as gateway routes between VLANs and inspects the traffic at the same time, which is the right choice when the VLANs need different trust levels.
For a home or small office, the answer is usually simpler: the router your internet provider gave you already does both jobs, and a managed switch adds VLANs when you outgrow it. Our guide to securing your Wi-Fi covers the home side of that setup.
How do you troubleshoot Layer 2 vs Layer 3 problems?
Start by deciding which layer is broken. If two devices on the same VLAN cannot talk, the problem is usually Layer 2: a wrong VLAN assignment, a bad cable, a full MAC table, or a duplex mismatch.
If devices on the same VLAN can talk but cannot reach another VLAN or the internet, the problem is usually Layer 3: a missing or wrong default gateway, a missing route, a wrong subnet mask, or a firewall rule blocking the traffic.
Use the right tool for each layer. At Layer 2, check the switch MAC table, the port status, and the VLAN assignment. At Layer 3, check the IP address and subnet mask, the gateway, the routing table, and whether ARP resolves the gateway's MAC address.
A quick test separates the two: ping the gateway first. If that fails, the fault is local, at Layer 1 or 2. If the gateway answers but a distant host does not, the fault is at Layer 3 or beyond. That one test saves hours of guessing.
You can confirm what address your own device is using with the what is my IP tool.
For name resolution, use the DNS lookup tool. The underlying address mapping is defined in RFC 826, and Cisco's ARP notes walk through the request and reply exchange.
The bottom line
Layer 2 and Layer 3 are not rivals; they are partners. Layer 2 delivers frames to the right device on the local network, Layer 3 delivers packets to the right network, and ARP connects the two. VLANs split Layer 2, and Layer 3 joins the pieces back together.
When you design a network, put Layer 2 where devices share a network, put Layer 3 where networks meet, and use a Layer 3 switch for fast routing inside a site and a router at the edge. Check your own network's public footprint with the free DNS lookup tool before your next change.
Frequently asked questions
What is the main difference between Layer 2 and Layer 3?
Layer 2 forwards Ethernet frames by MAC address inside one local network, while Layer 3 forwards IP packets by IP address between different networks. Layer 2 builds one broadcast domain; Layer 3 separates broadcast domains and chooses paths between them.
Is a switch Layer 2 or Layer 3?
A traditional switch is Layer 2: it forwards frames by MAC address. A Layer 3 switch is both: it forwards frames by MAC address and routes packets by IP address between VLANs and subnets, usually in hardware at close to wire speed.
Is a router Layer 2 or Layer 3?
A router is a Layer 3 device: it forwards IP packets between networks using a routing table. It also handles the Layer 2 header for each link it uses, but its forwarding decision is made on the IP address.
Do I need a Layer 3 switch or a router?
Use a Layer 3 switch when VLANs inside one site need to talk to each other at high speed. Use a router at the edge of the site, for WAN links, VPNs, and internet access, where advanced routing and firewalling matter more than raw speed.
What is the difference between a MAC address and an IP address?
A MAC address is a 48-bit hardware address tied to a network interface, used on the local link. An IP address is a logical address assigned to a device on a network, and it can change when the device moves. ARP maps one to the other on the local network.
Can two devices in different VLANs talk without Layer 3?
No. Each VLAN is a separate Layer 2 network and a separate IP subnet, so traffic between them must pass through a Layer 3 device: a router, a Layer 3 switch, or a firewall acting as the gateway for both VLANs.
What does a Layer 2 switch do with a broadcast?
A Layer 2 switch forwards a broadcast frame to all ports in the same VLAN, because broadcasts are how devices find each other on a local network. A router does not forward broadcasts between networks, which is one reason Layer 3 separates broadcast domains.
Sources
The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.
Checked against RFC 826, Cisco's ARP notes and Cisco Learning Network's inter-VLAN routing guidance.
How we write and fact-check →