Sub topic 1
What a switch reads from an Ethernet frame
A switch makes every forwarding decision from a small part of each Ethernet frame. This chapter covers which fields it reads, which it ignores, and what the switch does with the values. The rest of the tutorial builds on this: learning, lookup, flooding and aging all start with the two addresses at the front of the frame.
Prerequisites
This chapter assumes you already know:
- What a MAC address is, and that it differs from an IP address. A MAC address identifies a network interface on a local link. An IP address identifies a host on a routed network.
- The basic Ethernet frame fields: destination MAC, source MAC and EtherType.
- At a high level, how a hub, a switch and a router differ.
You do not need to know how the MAC address table works yet. Later chapters cover it.
The layout of an Ethernet frame
A frame is the unit of data at layer 2 of the OSI model. In the common Ethernet II format, the fields appear in this order:
| Field | Size | Purpose |
|---|---|---|
| Preamble and start frame delimiter | 8 bytes | Lets the receiver synchronize. The network card strips it before the frame reaches the switching logic. |
| Destination MAC | 6 bytes | The address the frame is meant for. |
| Source MAC | 6 bytes | The address of the sender. |
| 802.1Q tag (optional) | 4 bytes | Carries the VLAN ID and priority when the frame is tagged. |
| EtherType | 2 bytes | Says which protocol the payload carries, such as 0x0800 for IPv4 or 0x0806 for ARP. |
| Payload | 46 to 1500 bytes | The data, such as an IP packet. |
| Frame check sequence (FCS) | 4 bytes | A CRC value used to detect corruption. |
The destination address comes first. A switch can therefore start choosing an output port after receiving only the first 6 bytes. This is the basis of cut-through switching, which is described below.
The fields a switch uses
A layer 2 switch uses three pieces of information from the frame.
- The destination MAC address. The switch looks it up to decide where to send the frame.
- The source MAC address. The switch records it, together with the port the frame arrived on, so it can reach that sender later.
- The VLAN ID, if the frame carries an 802.1Q tag, or the VLAN configured on the ingress port if the frame is untagged. The switch uses it to pick which broadcast domain and which set of table entries apply. A later chapter covers VLANs in detail.
The switch also uses the FCS. It checks the CRC and discards frames that fail it. Without that check, a corrupted source address could be learned and send later traffic to the wrong place.
What the switch does not read
A pure layer 2 switch does not look at IP addresses, TCP or UDP ports, or the payload. Two hosts can exchange IP traffic through a switch without the switch knowing anything about IP. The EtherType matters only in a few cases, for example when the switch applies a policy based on protocol or recognizes a control frame.
Many modern switches are multilayer devices. They can also route, filter with access lists, or inspect ARP and DHCP. Those features are separate from the basic forwarding behavior described here. This tutorial covers only the layer 2 behavior.
Source and destination play different roles
The two addresses lead to two different actions, and mixing them up is a common mistake.
- The source address is used for learning. It tells the switch which port a host is reachable through. A source address is always a single device, so it is never a broadcast or multicast address.
- The destination address is used for forwarding. It says where the frame should go.
Consider host A (port 1) sending a frame to host B (port 2). The switch uses A's address to update its knowledge about port 1. It uses B's address to choose port 2, or to flood if it does not know B yet. Learning and forwarding are separate steps that happen to run on the same frame.
The structure of a MAC address
A MAC address is 48 bits, usually written as six hexadecimal octets, such as 00:1a:2b:3c:4d:5e. Different tools print it in different styles. Cisco IOS uses 001a.2b3c.4d5e, and Windows uses 00-1A-2B-3C-4D-5E. These are all the same value, so a script that compares addresses should normalize them first.
Two bits in the first octet carry meaning for a switch:
- The least significant bit, called the I/G bit (individual/group), says whether the address is a single device or a group. A value of 0 means unicast. A value of 1 means group, which covers both multicast and broadcast.
- The next bit, the U/L bit (universal/local), says whether the address was assigned by a manufacturer (0) or set locally (1). Virtual machines, containers and some tools use locally administered addresses. The switch does not treat these differently.
The broadcast address ff:ff:ff:ff:ff:ff has every bit set, so it is a group address. IPv4 multicast frames use addresses starting with 01:00:5e. IPv6 multicast frames use addresses starting with 33:33. Both start with an odd first octet, so the I/G bit is 1.
The next chapter covers these address types in more depth. For now, remember that the switch decides the type by looking at one bit.
The following Python function reads those two bits from an address string.
def classify(mac):
first_octet = int(mac.replace('-', ':').split(':')[0], 16)
kind = 'group' if first_octet & 0b01 else 'unicast'
scope = 'local' if first_octet & 0b10 else 'universal'
if mac.lower().replace('-', ':') == 'ff:ff:ff:ff:ff:ff':
kind = 'broadcast'
return kind, scope
for address in ['00:1a:2b:3c:4d:5e', 'ff:ff:ff:ff:ff:ff',
'01:00:5e:00:00:fb', '02:42:ac:11:00:02']:
print(address, classify(address))Running it prints:
00:1a:2b:3c:4d:5e ('unicast', 'universal')
ff:ff:ff:ff:ff:ff ('broadcast', 'universal')
01:00:5e:00:00:fb ('group', 'universal')
02:42:ac:11:00:02 ('unicast', 'local')The last address starts with 02, which sets the U/L bit. Docker uses addresses like this for container interfaces.
Reading the frame: store-and-forward and cut-through
Because the destination address is at the front, a switch has a choice about when to start forwarding.
- Store-and-forward switches receive the whole frame, check the FCS, and only then forward it. They never forward corrupted frames. The cost is a delay of one frame time at each hop.
- Cut-through switches start forwarding once the destination address has arrived. Latency is lower and does not depend on frame size. The FCS cannot be checked before forwarding begins, so a corrupted frame may already be on its way out when the error is found.
Most enterprise switches default to store-and-forward behavior, and some offer cut-through for latency-sensitive environments. The switch still reads the same fields in both modes. Only the timing differs. One consequence for the learning step: a store-and-forward switch can refuse to learn from a bad frame. A cut-through switch may learn the address before the check completes, and implementations differ in how they handle that.
The VLAN tag changes what "the frame" means
If a frame arrives on a trunk port, it normally carries a 4-byte 802.1Q tag between the source MAC and the EtherType. The tag holds a 12-bit VLAN ID. The switch reads that ID to know which VLAN the frame belongs to. On an access port, frames arrive without a tag. The switch assigns the port's configured VLAN to the frame internally.
This means the switch's working key is really the pair of VLAN and MAC address, not the MAC address alone. The same MAC address can appear in two VLANs on different ports without conflict.
The tag also changes the frame size. The standard maximum payload is 1500 bytes. A tagged frame is 4 bytes longer on the wire, so switches must accept a maximum frame size of 1522 bytes (not counting the preamble) for tagged traffic.
Common errors and misconceptions
- "The switch reads the IP address." A layer 2 switch does not. If two hosts have the wrong IP configuration but the right MAC addresses, the switch still delivers their frames without any error.
- "The switch learns from the destination address." It never does. Learning uses only the source address. A host that never sends anything is never learned, even if other hosts send to it all day.
- "The destination MAC is the final host's MAC." Only inside one broadcast domain. When a host sends to a remote IP address, the destination MAC is the default gateway's MAC address. The switch sees the router's address, not the remote host's.
- "The MAC address in the frame never changes." A router replaces both addresses at every hop. Between two switches on the same segment, the addresses stay unchanged.
- Ignoring address formats. Comparing
0011.2233.4455with00:11:22:33:44:55as strings fails even though they name the same interface.
Summary of what the switch reads
| Item | Where it comes from | What the switch does with it |
|---|---|---|
| Destination MAC | First 6 bytes after the preamble | Looks it up to choose the output port, or floods. |
| Source MAC | Next 6 bytes | Records it with the ingress port (learning). |
| VLAN ID | 802.1Q tag, or the access port's VLAN | Selects the broadcast domain and table partition. |
| FCS | Last 4 bytes | Detects corruption, and a bad frame is discarded. |
| Everything else | EtherType, payload | Ignored by basic forwarding. |
Exercise
A frame arrives on port 3 of a switch with destination 01:00:5e:00:00:fb and source 00:1a:2b:3c:4d:5e. Which address does the switch use for learning, which does it use for forwarding, and is the destination unicast or group?
Show answer
The switch uses the source address 00:1a:2b:3c:4d:5e for learning, and records it as reachable through port 3. It uses the destination address 01:00:5e:00:00:fb for the forwarding decision. The first octet is 0x01, so the I/G bit is 1 and the destination is a group (multicast) address.
Exercise
Why can a store-and-forward switch avoid forwarding corrupted frames, while a cut-through switch cannot always do so?
Show answer
A store-and-forward switch receives the whole frame and checks the FCS before sending anything. A cut-through switch starts sending as soon as the destination address has arrived. The FCS is at the end of the frame, so the check comes too late to stop the part already sent.
Exercise
Host A sends a packet to a server on another network. What destination MAC address does the first switch see in the frame, and why?
Show answer
The switch sees the MAC address of A's default gateway (the router interface). A host can only address frames directly to devices on its own link, so it sends traffic for remote networks to the gateway, which forwards the packet toward its destination.