Sub topic 3
Unicast, multicast, and broadcast destinations
This chapter assumes you can read hexadecimal and binary. It also assumes you know that a MAC address is a 48-bit link-layer address written as six octets, such as 02:00:5e:10:00:01. Here you learn how the destination address in a frame decides who receives it. You also learn how to tell the three kinds of destination apart by reading one bit.
One bit decides the kind of destination
Every Ethernet frame carries a destination MAC address. That address is not always the address of a single device. It can name one device, a group of devices, or every device on the LAN.
The first octet of the address carries the answer. Its least significant bit is the Individual/Group bit, or I/G bit.
- If the I/G bit is 0, the address is unicast. It names one interface.
- If the I/G bit is 1, the address is a group address. It names several interfaces.
- A special group address with all 48 bits set to 1,
ff:ff:ff:ff:ff:ff, is broadcast. Every interface on the LAN should accept it.
Broadcast is a special case of a group address. Any address with the I/G bit set is a group address, and broadcast is the one with every bit set. The term "multicast" in Ethernet usually means a group address that is not broadcast.
To check the bit by hand, look at the second hex digit of the first octet. It is the low four bits. An odd digit (1, 3, 5, 7, 9, b, d, f) means the I/G bit is set.
| First octet | Binary | I/G bit | Kind |
|---|---|---|---|
| `00` | 00000000 | 0 | unicast |
| `02` | 00000010 | 0 | unicast (locally administered) |
| `01` | 00000001 | 1 | multicast |
| `33` | 00110011 | 1 | multicast |
| `ff` | 11111111 | 1 | broadcast if all octets are `ff` |
The 02 row shows that the second-lowest bit is a different flag. It marks a locally administered address, and the next chapter covers it. It does not make an address a group address.
What a network card does with a frame
A network interface card (NIC) sees every frame that arrives on its link. It does not hand all of them to the operating system. The card compares the destination MAC with a list of addresses it accepts. If nothing matches, it discards the frame in hardware, which saves CPU time.
A NIC normally accepts a frame if any of these is true:
- The destination equals the card's own unicast MAC.
- The destination is
ff:ff:ff:ff:ff:ff. - The destination is a multicast address that the host has subscribed to.
Promiscuous mode switches this filter off, and the card passes up every frame it sees. Packet capture tools such as Wireshark and tcpdump use it by default. On a switched network, promiscuous mode shows you little extra, because the switch does not send you other hosts' unicast frames (see the chapter on switch MAC tables).
Unicast
Unicast is the normal case. A frame to aa:bb:cc:00:11:22 is meant for one interface. Switches that already know where that address lives forward the frame out one port. Other hosts never see it.
A switch that does not yet know the address floods the frame out every port except the one it arrived on. Such a frame is called unknown unicast. Hosts that are not the target ignore it because their NICs filter it. The flooding is a performance and privacy leak, but it is normal behavior for a switch that has not learned the address.
Broadcast
A broadcast frame goes to every device in the broadcast domain. A broadcast domain is the set of devices that receive each other's broadcasts. A switch floods broadcast frames out all ports in the same VLAN. A router does not forward them, so routers mark the boundary of the domain.
The best-known broadcast user is ARP. An ARP request asks "who has 192.168.1.1?" and is sent to ff:ff:ff:ff:ff:ff, because the sender does not yet know the target's MAC. DHCP discovery messages also use broadcast, because a new host has no address and does not know any server's address.
Broadcast has a cost. Every host in the domain must receive the frame and the operating system must process it. A few broadcasts per second are harmless. A broadcast storm, where frames loop through a switching loop or a faulty host floods the network, can make a LAN unusable. Large flat networks therefore get split into VLANs or routed subnets.
Multicast
Multicast sends one frame to a group of interested receivers. A host joins a group by telling its NIC to accept a given group MAC address. Hosts that have not joined ignore the frame at the NIC.
Ethernet defines how multicast IP addresses map to multicast MAC addresses.
IPv4 multicast mapping
An IPv4 multicast group address falls in 224.0.0.0/4. The MAC address is 01:00:5e followed by a 0 bit and the low 23 bits of the IP address.
224.0.0.251(mDNS) maps to01:00:5e:00:00:fb.225.1.1.1maps to01:00:5e:01:01:01.239.129.1.1also maps to01:00:5e:01:01:01.
The last two examples collide. An IPv4 multicast address has 28 variable bits, because the top four bits are always 1110. Only 23 of them fit into the MAC address. Five bits are lost, so 32 different IPv4 groups share each MAC address. A host that joined 225.1.1.1 therefore also receives frames for 239.129.1.1 at the NIC. The IP layer drops the extra traffic after it reads the IP header.
IPv6 multicast mapping
IPv6 uses the prefix 33:33 followed by the low 32 bits of the IPv6 multicast address.
ff02::1(all nodes on the link) maps to33:33:00:00:00:01.ff02::1:ff00:1(a solicited-node address) maps to33:33:ff:00:00:01.
IPv6 Neighbor Discovery relies on this mapping. It replaces ARP broadcasts with targeted multicasts, so hosts that are not involved are not interrupted. A later chapter covers it.
Link-local control groups
Some multicast MAC addresses are reserved for protocols that run between neighboring devices.
| Address | Used by |
|---|---|
| `01:80:c2:00:00:00` | Spanning Tree Protocol (bridge protocol data units) |
| `01:80:c2:00:00:0e` | LLDP (Link Layer Discovery Protocol) |
| `01:00:0c:cc:cc:cc` | Cisco Discovery Protocol |
Standard bridges do not forward frames to the 01:80:c2:00:00:0x range. These frames stay on one link, which suits protocols that talk to the directly attached neighbor.
What switches do with multicast
A basic switch has no way to know which ports have subscribers. It treats multicast like broadcast and floods it out every port in the VLAN. That is correct but wasteful when many hosts are not subscribed. Switches that support IGMP snooping (for IPv4) or MLD snooping (for IPv6) watch the group-join messages and forward each group only to ports with members.
Wi-Fi adds another cost. Group-addressed frames are sent at a low basic data rate and are not acknowledged per receiver. A busy multicast stream can use a large share of airtime.
Classifying addresses in code
The script below classifies a MAC address and computes the multicast MAC for an IPv4 or IPv6 group. It uses only the Python standard library.
import ipaddress
def classify_mac(mac: str) -> str:
octets = bytes(int(p, 16) for p in mac.replace('-', ':').split(':'))
if len(octets) != 6:
raise ValueError('a MAC address has 6 octets')
if octets == b'\xff' * 6:
return 'broadcast'
if octets[0] & 0x01:
return 'multicast'
return 'unicast'
def ipv4_multicast_mac(ip: str) -> str:
addr = ipaddress.IPv4Address(ip)
if not addr.is_multicast:
raise ValueError('not an IPv4 multicast address')
low23 = int(addr) & 0x7FFFFF
tail = ':'.join(f'{(low23 >> shift) & 0xFF:02x}' for shift in (16, 8, 0))
return '01:00:5e:' + tail
def ipv6_multicast_mac(ip: str) -> str:
addr = ipaddress.IPv6Address(ip)
if not addr.is_multicast:
raise ValueError('not an IPv6 multicast address')
low32 = (int(addr) & 0xFFFFFFFF).to_bytes(4, 'big')
return '33:33:' + ':'.join(f'{b:02x}' for b in low32)
for mac in ('02:00:5e:10:00:01', '01:00:5e:00:00:fb', 'ff:ff:ff:ff:ff:ff'):
print(mac, classify_mac(mac))
print(ipv4_multicast_mac('224.0.0.251'))
print(ipv4_multicast_mac('225.1.1.1'))
print(ipv4_multicast_mac('239.129.1.1'))
print(ipv6_multicast_mac('ff02::1'))
print(ipv6_multicast_mac('ff02::1:ff00:1'))Running it prints unicast, multicast, and broadcast for the first three addresses. The next lines show 01:00:5e:00:00:fb, then 01:00:5e:01:01:01 twice (the collision described above), then 33:33:00:00:00:01 and 33:33:ff:00:00:01.
Seeing group addresses on a real host
On Linux, ip maddr lists the link-layer multicast addresses each interface accepts. Replace eth0 with your interface name.
# Link-layer multicast addresses this host listens to
ip maddr show dev eth0
# Watch broadcast and multicast frames only (needs root)
sudo tcpdump -i eth0 -e -n 'ether broadcast or ether multicast'The -e option prints the link-layer header, so you can see the destination MAC of each frame. You should expect ff:ff:ff:ff:ff:ff for ARP requests and 33:33:... or 01:00:5e:... for IPv6 and mDNS traffic.
Common errors
- Treating broadcast and multicast as separate bit patterns. Broadcast is a multicast-style address with all bits set. Test for broadcast first, then for the I/G bit, as
classify_macdoes. - Reading the wrong bit. The I/G bit is the least significant bit of the first octet, not the most significant.
80:00:00:00:00:00is unicast, and01:00:00:00:00:00is multicast. - Assuming a multicast MAC identifies one IP group. The 32-to-1 mapping means the NIC may pass up frames for groups the host never joined.
- Assuming routers forward broadcast. A router does not forward Ethernet broadcast frames. A directed or limited IP broadcast does not cross a subnet boundary by default.
- Using a group address as a source. Spoofing tools sometimes do this by mistake, and receivers may drop the frame.
Exercise
Classify each destination as unicast, multicast, or broadcast, and say which bit or rule decides it: (a) 00:1a:2b:3c:4d:5e, (b) 33:33:00:00:00:fb, (c) ff:ff:ff:ff:ff:ff, (d) 03:00:00:00:00:01.
Show answer
(a) Unicast, because the first octet 00 has the I/G bit 0. (b) Multicast, because 33 is 00110011 and its lowest bit is 1; the 33:33 prefix marks an IPv6 multicast mapping. (c) Broadcast, because all 48 bits are 1. (d) Multicast, because 03 is 00000011 and its lowest bit is 1. The second-lowest bit marks it as locally administered, but that does not affect the I/G test.
Exercise
Which MAC address does a host use for the IPv4 group 239.255.0.1, and which other group address, from 224.0.0.0/4 shares it?
Show answer
Take the low 23 bits of the address. The second octet 255 has its top bit cleared, giving 127 (0x7f). The MAC is 01:00:5e:7f:00:01. Any group whose last three octets, with the top bit of the second octet ignored, match gives the same MAC, such as 224.127.0.1, 225.127.0.1, or 239.127.0.1. In total 32 IPv4 groups share this MAC.
Exercise
A host joins the IPv6 solicited-node group ff02::1:ff12:3456. Which MAC address must its NIC accept?
Show answer
The MAC is 33:33 followed by the low 32 bits of the address, which are ff:12:34:56. The NIC must accept 33:33:ff:12:34:56.