Layer 2 Switching
Lessons (6, study in order)
Lesson 1 · How does a switch know which port to send out
Beginner · about 8 min
Goal: Understand everything an L2 switch does — just three things: learn, look up, forward.
First, clear up a misconception: a switch isn't smart
A lot of people assume a switch runs some complex algorithm. In reality it does exactly three things:
① Learn — on receiving a frame, record the "source MAC" and "which port it came in on" into a table
② Look up — when it needs to send, look up the outgoing port by "destination MAC" in that table
③ Forward — send it out the port it found
★ It never looks at IP, port numbers, or content — only the two MAC addresses in the Ethernet frame header.
That's exactly why a switch is "transparent" to the two communicating ends — when PC1 sends a frame to PC3, it has no idea how many switches it passed through.
⚠️ The easiest thing to get backwards
It learns the "source" MAC, and looks up the "destination" MAC.
Why does this work? Because an L2 link is bidirectional.
The fact "PC1's frame came in on GE0/0/1" is exactly equivalent to
"to send to PC1 in the future, go out GE0/0/1."
★ One line to remember: wherever it came from is where you send it back.
Hands-on: watch an empty table fill up
Go to the Topology & MAC Table page, and first click "Clear MAC table" — you'll see all four tables go empty.
Then go to the Frame Forwarding Simulation page and send a frame from PC1 → PC3, then come back and check the tables.
★ Notice what each switch learned: SW1 learned both PC1 and PC3, and SW2 learned the same two — but on different ports.
Key takeaways
- A switch only does three things: learn (source MAC → incoming port), look up (destination MAC), forward
- ⚠️ Learn source, look up destination — don't mix up these two directions
- A switch never looks at IP, and is transparent to both communicating ends
Lesson 2 · What if the table can't find it: flooding
Beginner · about 10 min
Goal: Understand flooding — L2's most counterintuitive, and most important, behavior.
Right after power-on, the table is empty
A switch just powered on has a completely empty MAC table — it has no idea where any device is.
Now a frame arrives whose destination MAC can't be found. It has two choices:
· Drop it — but then the network could never work, because the table could never learn anything
· Take a gamble: send a copy out every port except the one it came in on
★ It picks the latter. This action is called flooding.
★★ The most counterintuitive part of flooding
A unicast frame addressed to one specific device ends up delivered to everyone.
There are three costs:
· Every unrelated host's NIC has to accept it, check the destination MAC, realize it isn't theirs, and drop it → wasted CPU
· Every link has a slice of its bandwidth consumed
· The content might get captured by someone who shouldn't see it → a security concern
★ But note: this isn't a fault — it's a necessary part of L2's design. Without flooding, the table could never get built in the first place.
★ Three situations that trigger flooding — don't mix them up
· Broadcast frame — destination MAC is ffff.ffff.ffff, which by definition must go to everyone (normal behavior)
· Unknown unicast — destination MAC is a specific device, but not found in the table (this is the one worth watching)
· Multicast — sent to a group of devices; without multicast optimization configured, it also degrades into flooding
★ If you see a lot of unknown unicast flooding in a real packet capture, that's a sign something's off — Lesson 5 covers its real cause.
Hands-on: watch the fan-out with your own eyes
Go to the Frame Forwarding Simulation page, first clear the MAC table, then send PC1 → PC3.
★ Watch the first step at SW1: several lines light up at the same time on the canvas — that's flooding's fan-out.
Only one direction is actually useful, and the UI marks it.
Key takeaways
- Not found → flood (send one copy out every port except the incoming one)
- Flooding isn't a fault — without it the table could never get built
- ★ But unknown unicast flooding is worth watching: a unicast frame delivered to everyone
- Flooding's cost: unrelated hosts waste CPU + links waste bandwidth + content might get sniffed
Lesson 3 · A host only has the IP: ARP fills that gap
Beginner · about 10 min
Goal: Understand ARP's one and only reason to exist, and why it must use broadcast.
Where's the gap
You ping an IP, or your browser hits a URL — the application layer hands you an IP address.
But the NIC needs to send a frame, and the frame header needs a MAC address.
★ There's a gap here: you know the IP, but not the MAC.
ARP (Address Resolution Protocol) exists for exactly one reason: to close that gap.
★ Why it has to be a broadcast
ARP wants to ask "who is 10.0.0.3". But there's a chicken-and-egg problem here:
I want to ask, but I don't know who to ask — because knowing "who to ask" itself requires a MAC address.
There's only one way to break this loop: broadcast, and ask everyone.
The destination MAC is set to ffff.ffff.ffff, so every device in the broadcast domain receives it and checks:
"Is this IP me?" — whichever one it is replies via unicast.
★ Why can the reply be unicast? Because the request frame carried the source host's MAC, so the responder already knows exactly who to reply to.
★★ The most elegant part: the table gets built by ARP
Put Lessons 1 and 2 together and watch one full exchange:
① ARP request (broadcast) floods the whole network → every switch along the way learns the source host's MAC
② The target replies via unicast → since the table was just built, this hits a table match the whole way, with no more flooding
③ The actual data frame goes out → clean unicast the whole way
★★★ It's the first frame's (the ARP request's) flood that builds the table.
This is exactly why real packet captures rarely show flooding — not because it never happened, but because it happened before you started watching.
★ When crossing subnets, ARP asks for the gateway
A host makes one check before sending a frame: "is the destination IP on my subnet?"
· Same subnet → ARP for the peer's MAC; the frame header's destination MAC is the peer's
· Cross-subnet → ARP for the gateway's MAC; the frame header's destination MAC is the gateway's
⚠️ The second one is a common mistake point: when crossing subnets, the destination host's MAC never appears at all in the frame header.
L2 is only responsible for getting the frame to the gateway — the rest is layer 3's job.
Hands-on: walk through ARP
Go to the ARP Protocol page and have PC1 resolve PC3's IP.
Watch the two frames: the request (broadcast, flooded) and the reply (unicast, a hit the whole way).
★ Then be sure to look at the two side-by-side tables in the lower half of the page — the next lesson is exactly about them.
Key takeaways
- The gap ARP fills: you know the IP, but the frame header needs a MAC
- ★ The request must be broadcast (you don't know who to ask yet); the reply can be unicast (the request already carries the source MAC)
- ★★ The table gets built by the flood of the first frame
- ⚠️ When crossing subnets, ARP asks for the gateway; the frame header's destination MAC is the gateway's
Lesson 4 · ★★ Don't mix up two tables: ARP cache vs MAC table
Beginner · about 8 min
Goal: Cleanly separate L2's most commonly confused pair of concepts.
Side by side
| | ARP cache | MAC address table |
|---|---|---|
| Lives on | a host | a switch |
| Key → value | IP → MAC | MAC → port |
| Solves what | I know the IP, but the frame header needs a MAC | I know the MAC, I need to pick a port to send it out |
| How it's built | asked for via ARP | self-learned from the source MAC of received frames |
| Default timeout | 20 minutes | 300 seconds |
| View command | display arp | display mac-address |
★ Mnemonic: the ARP cache spans layer 3 and layer 2 (IP→MAC); the MAC table is purely internal to layer 2 (MAC→port).
One ARP resolution updates both tables at once
This is exactly why they're so easy to mix up — they're often filled in at the same time.
After PC1 resolves PC3 once:
· PC1's ARP cache gains one entry: 10.0.0.3 → PC3's MAC
· SW1 / SW2's MAC tables each gain two entries: PC1's MAC → some port, PC3's MAC → some port
★ Same operation, two completely different tables. Go check those two side-by-side tables on the ARP page.
⚠️ But they age out independently — foreshadowing Lesson 5
Notice the last row of that table above: the timeouts are different — 20 minutes vs 300 seconds.
This mismatch causes a very specific real-world phenomenon, covered in the next lesson.
Hands-on: separate them yourself
Go to the Topology & MAC Table page — there are two independent buttons there:
· Clear MAC table (clears only the switches')
· Clear ARP cache (clears only the hosts')
★ Click each one separately and see which table changed and which didn't.
Key takeaways
- The ARP cache lives on hosts, IP → MAC
- The MAC table lives on switches, MAC → port
- One ARP resolution fills both tables at once — which is why they're easy to confuse
- ⚠️ But they age out independently, with timeouts 4× apart
Lesson 5 · Tables forget things: aging, and the real cause of unknown unicast flooding
Intermediate · about 10 min
Goal: Understand the aging mechanism, and where unknown unicast flooding really comes from in the real world.
Why aging has to exist
A MAC table can't just grow forever, for two reasons:
· Table capacity is limited — a switch's MAC table is a hardware table with a few thousand to a few hundred thousand entries, and it can fill up
· Devices move — a laptop moves from the 3rd floor to the 5th; if the entry doesn't update, frames get sent the wrong way
So every dynamic entry carries a timer: if this MAC hasn't been seen again in 300 seconds, delete it.
★ Note "seen" means receiving a frame it sent (where it's the source MAC) — as long as it keeps talking, the entry keeps refreshing and never ages out.
★★★ And that's how this real-world phenomenon comes about
Put the two timeouts side by side:
· Switch MAC table: 300 seconds
· Host ARP cache: 1200 seconds (20 minutes)
The MAC table forgets first.
Consider a device that "speaks rarely" — a backup server, a printer, a monitoring probe:
① It hasn't sent any frame in 10 minutes → the switch ages out its table entry
② But other hosts' ARP caches still remember its MAC (that takes 20 minutes to expire)
③ So a host sends it a unicast frame as usual
④ The switch looks it up → not found → floods it
★★ This is the real cause of unknown unicast flooding.
It's not a misconfiguration — it's the inevitable result of two default values not matching.
Hands-on: reproduce it yourself
Go to the Topology & MAC Table page:
① First send PC1 → PC3 once, so the table gets built
② Click "Clear MAC table" — but don't clear the ARP cache
③ Go back to the Frame Forwarding Simulation page and send PC1 → PC3 again
★ This time you'll see: PC1 doesn't send ARP (it's in the cache) — it sends unicast directly;
but the switch can't find it → unknown unicast flooding. The UI will clearly flag it.
★ You can also use the "Advance time" button to watch aging actually happen once.
How to fix it
· Extend the MAC table's aging time — so it isn't shorter than the ARP cache by so much
· Configure a static MAC entry for critical devices — static entries never age out
· Have the device speak periodically (many monitoring probes refresh their entry as a side effect of heartbeat packets)
★ In practice, the second option is usually preferred: pin the server's / gateway's MAC to a specific port, which also happens to guard against MAC spoofing.
Key takeaways
- A dynamic entry ages out if it hasn't been seen in 300 seconds; it keeps refreshing as long as it keeps talking
- ★★★ The real cause of unknown unicast flooding: the MAC table forgets first at 300 seconds, while the ARP cache still remembers at 1200
- It's not a misconfiguration — it's the inevitable result of two mismatched defaults
- Fixes: extend the aging time / configure a static entry (never ages out)
Lesson 6 · Broadcast circulation in a triangle
Troubleshooting · about 12 min
Goal: Trace broadcast circulation, terminating host copies, and actual MAC port changes.
Ethernet has no TTL
Ethernet has no hop limit equivalent to IPv4 TTL. With STP and storm control absent and no packet loss, broadcast copies can keep circulating. This does not mean frames can never be dropped.
One broadcast in the triangle
PC1 injects one broadcast. SW1 sends one copy through each ring port, creating two opposite-direction circulating copies. Each next switch forwards a copy through its other ring port and a copy to its local host. Hosts do not bridge received copies, so the circulating count does not double every round.
How MAC entries change
A switch learns the source MAC against the actual incoming port. A dynamic entry moves only when the same source is received on another port. Initial learning is not a flap, and event order depends on arrival timing.
Hands-on: inspect each wave
Start the Loop & Broadcast Storm simulation and compare emitted copies, continuing copies, host deliveries, and MAC port changes. A round is a logical forwarding wave, not a second or a TTL decrement. This preview injects one broadcast and does not infer link utilization or CPU load.
The fix: STP
STP constructs a loop-free forwarding topology for each spanning-tree instance by blocking selected redundant ports. In a triangle, blocking one inter-switch link leaves two forwarding links; the cost is not a fixed half of all bandwidth. New broadcasts can accumulate with circulating traffic and cause congestion, depending on rate, hardware, and protection settings.
Key takeaways
- Ethernet has no TTL; looped copies can continue circulating
- One injected broadcast leaves two circulating copies in this triangle; host copies terminate
- MAC changes follow actual received ingress ports
- STP breaks the forwarding loop; the preview round limit is not TTL