Sub topic 17
MAC Addresses
A MAC address identifies a network interface on a local link. This chapter assumes you know the layered model, binary and hexadecimal notation, and the role of the data link layer. It covers the structure of a 48-bit address, the three address types, how a frame uses the address to decide who accepts it, and the errors that GATE-style questions exploit.
What a MAC address is
A MAC address (medium access control address, also called a physical or hardware address) is a 48-bit number assigned to a network interface card (NIC). It is written as six bytes in hexadecimal, usually separated by colons or hyphens, for example 00:1A:2B:3C:4D:5E.
Key facts:
- The address belongs to the interface, not to the computer. A laptop with Wi-Fi and Ethernet has two MAC addresses.
- It has meaning only on the local link. A router rewrites the source and destination MAC addresses of a frame at every hop, while the IP addresses stay the same end to end.
- There are 2^48 (about 2.8 × 10^14) possible addresses.
- It is a flat address. Nothing in it tells you where in the network the device is, so a switch cannot summarize groups of addresses. This is why switches keep one table entry per address.
Structure of the address
The 48 bits split into two halves.
| Part | Size | Meaning |
|---|---|---|
| OUI (organizationally unique identifier) | first 24 bits (3 bytes) | Assigned by the IEEE to the manufacturer |
| NIC-specific part | last 24 bits (3 bytes) | Assigned by the manufacturer to each card |
Two bits in the first byte carry special meaning.
- I/G bit (individual/group): the least significant bit of the first byte. It is 0 for a unicast address and 1 for a multicast or broadcast address.
- U/L bit (universal/local): the second least significant bit of the first byte. It is 0 for a globally unique, manufacturer-assigned address and 1 for a locally administered address.
Ethernet transmits each byte starting from its least significant bit. So the I/G bit is the first bit of the address on the wire. A receiver can therefore tell group addresses from individual ones after reading a single bit.
def describe_mac(mac: str) -> dict:
parts = mac.replace("-", ":").split(":")
if len(parts) != 6:
raise ValueError("a MAC address has six bytes")
first = int(parts[0], 16)
return {
"oui": ":".join(p.upper() for p in parts[:3]),
"group": bool(first & 0b00000001),
"local": bool(first & 0b00000010),
"broadcast": all(int(p, 16) == 0xFF for p in parts),
}
print(describe_mac("00:1A:2B:3C:4D:5E"))
print(describe_mac("01:00:5E:00:00:FB"))
print(describe_mac("FF:FF:FF:FF:FF:FF"))The first call reports a unicast, universally administered address. The second has first byte 01, so the group bit is set. The third is the broadcast address.
Unicast, multicast and broadcast
| Type | Address pattern | Who accepts the frame |
|---|---|---|
| Unicast | I/G bit = 0 | The one interface whose address matches |
| Multicast | I/G bit = 1, not all ones | Interfaces configured to listen to that group |
| Broadcast | `FF:FF:FF:FF:FF:FF` | Every interface on the local network |
Broadcast is a special case of group addressing. In FF, the I/G bit is 1, so every broadcast address is also a group address, but not every group address is a broadcast. IPv4 multicast frames use addresses that begin with 01:00:5E.
A source address is always unicast. A frame can never come from a group.
How a NIC uses the address
When a frame arrives, the NIC compares the destination address against its own address and the groups it has joined. Then it acts as follows:
- If the destination equals the NIC's own address, the NIC accepts the frame and passes it up.
- If the destination is the broadcast address, the NIC accepts it.
- If the destination is a multicast address the NIC subscribes to, it accepts it.
- Otherwise the NIC discards the frame without bothering the CPU.
A NIC in promiscuous mode skips the filter and accepts every frame it sees. Packet sniffers use this mode. On a hub, a sniffer sees all traffic. On a switch, it sees only its own traffic, broadcasts and flooded frames (see the chapter on learning switches).
MAC address versus IP address
| Property | MAC address | IP address |
|---|---|---|
| Layer | Data link | Network |
| Length | 48 bits | 32 bits (IPv4) |
| Scope | One local link | End to end across networks |
| Structure | Flat (OUI plus serial) | Hierarchical (network plus host) |
| Changes at each hop | Yes | No (without NAT) |
A sender that knows only the destination IP address needs the matching MAC address to build a frame. On IPv4 networks, ARP (Address Resolution Protocol) supplies it. The sender broadcasts a request, "who has this IP address?", and the owner replies with its MAC address by unicast. The sender caches the answer.
Worked example: addresses across a router
Host A (MAC_A) sends a packet to host B on another network, through router R.
- A sees that B's IP address is off-link. It uses ARP to learn the MAC address of its default gateway, R's interface
MAC_R1. - A builds a frame with destination
MAC_R1and sourceMAC_A. The IP packet inside has source IP A and destination IP B. - R receives the frame, removes the Ethernet header, and looks up the next hop.
- R builds a new frame with source
MAC_R2(its other interface) and destinationMAC_B. The IP addresses inside are unchanged.
Counting addresses is a common question: along a path of two links, the packet carries two different MAC pairs but one IP pair.
Uniqueness and the real world
Manufacturer-assigned addresses are meant to be unique, but a few things weaken that:
- Many operating systems let you override the address in software. The result is a locally administered address, with the U/L bit set to 1.
- Modern phones randomize their Wi-Fi MAC address to resist tracking. They set the U/L bit.
- Duplicate addresses on one LAN cause a switch to flip its table entry back and forth. Traffic then reaches only one of the two stations at a time.
- Virtual machines receive generated addresses from a hypervisor-specific OUI.
The address is also not a security control. It can be forged, so MAC filtering gives only weak protection.
Common errors
- Confusing bit order and byte order. Hex notation writes the I/G bit as the lowest bit of the first byte. For
01:...the bit is 1. For02:...the group bit is 0 but the local bit is 1. - Calling
FF:FF:FF:FF:FF:FFthe only group address. It is the only broadcast address, but millions of multicast addresses exist. - Thinking the MAC address changes the IP packet. Routers rewrite only the Ethernet header and trailer.
- Counting 6 bytes as 6 bits or 12 bits. There are 12 hex digits, which is 48 bits.
- Assuming the address says where a host is. It does not, so switches must learn locations.
Quick check on counts
How many addresses can one OUI supply? The 24-bit device part gives 2^24 = 16,777,216 addresses. The number of distinct OUIs is bounded by 2^22 for universal unicast OUIs, because two of the 24 OUI bits are the I/G and U/L flags.
print(2 ** 24) # 16777216 addresses per OUI
print(2 ** 22) # 4194304 possible OUIs with I/G = 0 and U/L = 0
print(2 ** 46) # 70368744177664 universal unicast addressesExercise
A frame has destination address 03:00:00:00:00:01. Is it unicast, multicast or broadcast? Is it universally or locally administered? Would a host with MAC 00:11:22:33:44:55 that has joined no groups accept it?
Show answer
The first byte is 03 = 00000011. The least significant bit (I/G) is 1, so it is a group address. It is not all ones, so it is multicast, not broadcast. The second least significant bit (U/L) is also 1, so it is locally administered. The host has joined no groups and the address is not its own or the broadcast address, so it discards the frame (unless it is in promiscuous mode).
Exercise
Host A sends a packet to host B across three routers, so the path has four links. How many different source MAC addresses and how many different source IP addresses appear on the packet along the whole path?
Show answer
Each link carries a frame sent by a different interface: A's NIC, then one outgoing interface on each of the three routers. That gives 4 different source MAC addresses. The source IP address stays A's address on every link (no NAT), so there is 1 source IP address.