Sub topic 2
Anatomy of a MAC address
This chapter assumes you know what an IP address is, can read hexadecimal and binary, and can run commands in a terminal. It covers how a MAC address is structured and written. Later chapters cover the vendor prefix, address types, and how frames use the address.
What a MAC address is
A MAC (Media Access Control) address is a 48-bit identifier for a network interface on a local network. Ethernet and Wi-Fi both use it at the link layer to say which interface a frame comes from and which interface it is for. It identifies an interface, not a computer. A laptop with Wi-Fi and a wired adapter has two MAC addresses.
48 bits is 6 bytes, and each byte is called an octet. The address is split into two halves of 3 octets each:
- The first 3 octets are the OUI (Organizationally Unique Identifier), assigned to a manufacturer.
- The last 3 octets are the device-specific part, which the manufacturer assigns to each interface.
Notation
The same address is written in several formats. All of them mean the same 48 bits.
| Style | Example | Common use |
|---|---|---|
| Colon-separated | `02:00:5e:10:00:01` | Linux, macOS |
| Hyphen-separated | `02-00-5E-10-00-01` | Windows, IEEE documents |
| Dotted groups of four digits | `0200.5e10.0001` | Cisco devices |
Each octet is two hexadecimal digits. Case does not matter, and parsers should accept both upper and lower case.
The two flag bits in the first octet
The low two bits of the first octet are flags. Bit 0 is the least significant bit.
- Bit 0, the group bit. If it is 0, the address is an individual (unicast) address. If it is 1, the address is a group (multicast) address. The all-ones address
ff:ff:ff:ff:ff:ffis the broadcast address, and it also has this bit set. - Bit 1, the locally administered bit. If it is 0, the address is universally administered, meaning the manufacturer assigned it from its OUI. If it is 1, someone set it locally, for example software or a virtual machine host.
Take the first octet 02. In binary it is 00000010. Bit 0 is 0, so the address is unicast. Bit 1 is 1, so it is locally administered. Now take ff, which is 11111111. Both bits are 1.
A common mistake is to read the bits from the left. The bit order on the wire differs from the order you read in hex, so use the mask method: first & 0x01 gives the group bit and first & 0x02 gives the locally administered bit.
Decoding an address in code
This function applies those masks and splits the address into its two halves.
def describe_mac(mac: str) -> dict:
parts = mac.replace('-', ':').split(':')
if len(parts) != 6:
raise ValueError('a MAC address has 6 octets')
octets = bytes(int(p, 16) for p in parts)
first = octets[0]
return {
'oui': ':'.join(f'{b:02x}' for b in octets[:3]),
'device_part': ':'.join(f'{b:02x}' for b in octets[3:]),
'is_group': bool(first & 0x01),
'is_locally_administered': bool(first & 0x02),
'is_broadcast': octets == b'\xff' * 6,
}
print(describe_mac('02:00:5e:10:00:01'))
print(describe_mac('ff:ff:ff:ff:ff:ff'))The first call reports is_group as false and is_locally_administered as true, because the first octet is 02. The second call reports all three flags as true, because the address is broadcast.
Common errors
- Treating the MAC as a unique, permanent identity. Software can change it, and many devices now randomize it.
- Assuming every address has a meaningful OUI. If the locally administered bit is set, the first 3 octets are not a manufacturer prefix.
- Mixing up notation styles when comparing addresses as strings. Normalize case and separators first.
- Looking at only the lowest bit of the whole first octet as a value. Check it with a mask, not by comparing the octet to a number.
Exercise
The first octet of a MAC address is 3a. Is the address unicast or multicast, and is it universally or locally administered?
Show answer
3a is 00111010 in binary. Bit 0 is 0, so it is unicast. Bit 1 is 1, so it is locally administered. Both results match 0x3a & 0x01 == 0 and 0x3a & 0x02 != 0.
Exercise
Why does 01:00:5e:00:00:fb count as a group address even though it is not ff:ff:ff:ff:ff:ff?
Show answer
Its first octet is 01, so bit 0 is 1. Any address with the group bit set is a multicast address. Only the all-ones address is broadcast.