Sub topic 2
Anatomy of a MAC address
This chapter assumes you can read hexadecimal and binary, you know what an IP address is, and you can run commands in a terminal. It covers the layout of a MAC address, the ways it is written down, and how to take one apart in code. The later chapters on unicast and multicast, OUIs, and locally administered addresses go deeper on individual fields. Here you learn where those fields sit.
What a MAC address is
A MAC address (Media Access Control address) is a 48-bit identifier. Ethernet and Wi-Fi network interfaces use it to say which device on the local link a frame is from and which it is for. The address belongs to a network interface, not to a computer. A laptop with an Ethernet port and a Wi-Fi card has at least two MAC addresses. A virtual machine, a container network interface, or a VLAN subinterface can each have its own as well.
The IEEE standards body defines the format. The official name for a 48-bit identifier is EUI-48 (Extended Unique Identifier). The older name MAC-48 means the same thing. The IEEE also defines a 64-bit form, EUI-64. You will meet it later in IPv6, where an interface identifier can be derived from a MAC address.
A 48-bit space holds 2^48 values, about 281 trillion. Two bits in the first octet are reserved for flags, so unicast, universally administered addresses use 46 bits of that space. That is still about 70 trillion addresses.
The six octets
An octet is 8 bits, so a MAC address is six octets. By convention each octet is written as two hexadecimal digits, which gives 12 hex digits in total.
The address splits into two halves of three octets each:
| Octets | Bits | Name | Assigned by |
|---|---|---|---|
| 1 to 3 | 24 | OUI (Organizationally Unique Identifier) | The IEEE registers it to a manufacturer or other organization |
| 4 to 6 | 24 | Device-specific part (NIC-specific) | The registered organization, who gives each interface a different value |
Two flag bits sit inside the first octet, which means they are part of the OUI half. They are not part of the vendor's identity. They describe how the address behaves.
The two flag bits in the first octet
Number the bits in an octet from 0 (least significant) to 7 (most significant). In the first octet of a MAC address:
- Bit 0 is the group bit, also called the I/G bit (individual/group). A value of 0 means the address names one interface (unicast). A value of 1 means it names a group (multicast), and the all-ones broadcast address is the special case of a group address.
- Bit 1 is the local bit, also called the U/L bit (universal/local). A value of 0 means the manufacturer assigned the address from its registered OUI. A value of 1 means someone else set it locally. That could be an administrator, a hypervisor, or an operating system that randomizes addresses.
Take the first octet 0x02. In binary it is 00000010. Bit 0 is 0, so the address is unicast. Bit 1 is 1, so it is locally administered. You can test the bits with masks: first & 0x01 reads the group bit and first & 0x02 reads the local bit.
A quick way to read these bits by eye is to look at the second hex digit of the first octet:
| Second hex digit of octet 1 | Group bit | Local bit | Meaning |
|---|---|---|---|
| 0, 4, 8, c | 0 | 0 | Unicast, universal |
| 2, 6, a, e | 0 | 1 | Unicast, local |
| 1, 5, 9, d | 1 | 0 | Multicast, universal |
| 3, 7, b, f | 1 | 1 | Multicast, local |
This is why you often see randomized or virtual addresses that start with 02, 06, 0a, or 0e. It is also why ff:ff:ff:ff:ff:ff sets both bits.
Notation
The 48 bits are the same everywhere, but systems write them in different ways. These three forms all describe one address:
| Style | Example | Common in |
|---|---|---|
| Colon-separated | `00:1a:2b:3c:4d:5e` | Linux, macOS, most Unix tools |
| Hyphen-separated | `00-1A-2B-3C-4D-5E` | Windows, IEEE documents |
| Dotted groups of four | `001a.2b3c.4d5e` | Cisco IOS and some other network equipment |
Hex digits are case-insensitive, so AA:BB:CC:DD:EE:FF and aa:bb:cc:dd:ee:ff are the same address. Some tools also drop leading zeros in an octet and print 0:1a:2b:3c:4d:5e. This is a display quirk. The address still has six octets. When you compare or store addresses, normalize them first. A string comparison of 00:1A:2B:3C:4D:5E with 00-1a-2b-3c-4d-5e says they differ, even though they are the same address.
import re
def normalize_mac(text: str) -> str:
"""Return a MAC address as lowercase colon-separated octets."""
digits = re.sub(r'[:\-.]', '', text.strip().lower())
if not re.fullmatch(r'[0-9a-f]{12}', digits):
raise ValueError(f'not a 48-bit MAC address: {text!r}')
return ':'.join(digits[i:i + 2] for i in range(0, 12, 2))
for style in ('00:1A:2B:3C:4D:5E', '00-1a-2b-3c-4d-5e', '001a.2b3c.4d5e'):
print(style, '->', normalize_mac(style))All three lines print 00:1a:2b:3c:4d:5e on the right. The function removes separators first, then checks for exactly 12 hex digits. It accepts mixed separators, which is lenient on purpose. A strict parser for user input would also check that the separators are consistent.
Taking an address apart in code
Once an address is normalized, you can convert it to six bytes and read the fields with masks. This function splits the address into its two 24-bit halves and reads both flag bits.
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 prints an address with is_group false and is_locally_administered true, because the first octet is 0x02. The second call prints true for all three flags: group, locally administered, and broadcast. The broadcast address has every bit set, so it also has the local bit set. Only the all-ones value is called broadcast. Other addresses with the group bit set are multicast.
Bit order on the wire
Hex notation hides a detail. Ethernet transmits each octet starting with its least significant bit. The bytes themselves go out in order, first octet first. The bits inside each byte go out in the opposite order from how you write the number.
This has one useful effect. The group bit is bit 0 of the first octet, so it is the first bit of the address on the wire. A receiving interface can see whether a frame is unicast or group-addressed before it has read anything else of the address.
Some older technologies, such as Token Ring and FDDI, sent the most significant bit first. Software that moved addresses between those media had to reverse the bits within each octet. Documents then spoke of canonical form (the Ethernet order) and non-canonical form (bit-reversed). On modern Ethernet and Wi-Fi networks you can ignore this. It matters when you read old documentation, and when an address in a packet capture looks like it has the wrong flag bits.
Seeing real addresses
On Linux, ip link show prints the MAC address of each interface on the link/ether line. The brief form is easier to read:
# Show the MAC address (link/ether) of every interface
ip link show
# One line per interface: name, state, MAC address
ip -br linkThe loopback interface shows 00:00:00:00:00:00. It has no real link layer, so it has no real address. A physical interface shows a universal address from its manufacturer's OUI. A virtual interface, such as one created by a hypervisor or container runtime, often shows a locally administered address. Check the second hex digit of the first octet with the table above and you can tell which you are looking at.
Common mistakes
- Treating a MAC address as a globally unique name. Manufacturers aim for uniqueness, but any administrator or operating system can change an address, and virtual machines routinely get addresses from a pool. Two devices can end up with the same MAC. Duplicates cause intermittent failures that are hard to find.
- Comparing addresses as raw strings. Case, separators, and dropped leading zeros all vary. Normalize or compare the 6-byte value.
- Assuming the first three octets always identify a vendor. That holds for universally administered addresses only. When the local bit is 1, the prefix means nothing about the manufacturer.
- Using a MAC address as a security credential. The address is sent in clear text in every frame and is easy to change. A later chapter covers spoofing.
Exercise
A Cisco switch shows a device as 0a1b.2c3d.4e5f. Write this address in colon-separated form, then say whether its first octet marks it as unicast or group, and as universal or local.
Show answer
In colon form it is 0a:1b:2c:3d:4e:5f. The first octet is 0x0a, which is 00001010 in binary. Bit 0 is 0, so the address is unicast. Bit 1 is 1, so it is locally administered. The second hex digit a in the table above confirms this: unicast, local.
Exercise
Is 01:00:5e:00:00:fb a valid source address for a normal network interface? Explain using the first octet.
Show answer
No. The first octet is 0x01, which is 00000001 in binary, so the group bit (bit 0) is 1. That makes it a multicast address, and group addresses are used only as destinations. A frame's source address must name a single interface, so the group bit must be 0 there.