A MAC address is a unique identifier assigned to each device on a network. It’s most commonly used in the networking world to identify devices on a network, but it can also be used for other purposes such as tracking devices or identifying users. ..
Every piece of hardware on your local network has a MAC address in addition to the IP address assigned to it by the local router or server. What exactly is that MAC address for?
Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.
The Question
SuperUser reader Vishnu Vivek is curious about MAC addresses and their function:
Where indeed? What is the specific function of the MAC address?
I don’t think it sits there for no reason. So my question is, where exactly does a MAC address come into play during a packet transfer?
The Answer
SuperUser contributor Werner Henze offers some insight into the function of the MAC address:
Have something to add to the explanation? Sound off in the the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.
MAC addresses are the low level basics that make your ethernet based network work.
Network cards each have a unique MAC address. Packets that are sent on the ethernet are always coming from a MAC address and sent to a MAC address. If a network adapter is receiving a packet, it is comparing the packet’s destination MAC address to the adapter’s own MAC address. If the addresses match, the packet is processed, otherwise it is discarded.
There are special MAC addresses, one for example is ff:ff:ff:ff:ff:ff, which is the broadcast address and addresses every network adapter in the network.
How do IP addresses and MAC addresses work together?
IP is a protocol that is used on a layer above ethernet. Another protocol for example would be IPX.
When your computer wants to send a packet to some IP address x.x.x.x, then the first check is if the destination address is in the same IP network as the computer itself. If x.x.x.x is in the same network, then the destination IP can be reached directly, otherwise the packet needs to be sent to the configured router.
Up to now things seem to have gotten worse, because now we have two IP addresses: one is the original IP packet’s target address, the other is the IP of the device to which we should send the packet (the next hop, either the final destination or the router).
Since ethernet uses MAC addresses, the sender needs to get the MAC address of the next hop. There is a special protocol ARP (address resolution protocol) that is used for that. Once the sender has retrieved the MAC address of the next hop, he writes that target MAC address into the packet and sends the packet.
How does ARP work?
ARP itself is a protocol above ethernet, like IP or IPX. When a device wants to know the MAC address for a given IP address, it sends a packet to the broadcast MAC address asking “Who has IP address y.y.y.y?” All devices receive that packet, but only the one with the IP address y.y.y.y will respond with a packet “It’s me.” The asking device receives the answer and now knows that the source MAC address is the right MAC address to use. Of course the result will be cached, so the device does not need to resolve the MAC address every time.
Routing
I almost forgot to mention: there is no routing based on MAC addresses. Low level ethernet and MAC addresses can only reach every device on the same network (cabled or wireless). If you have two networks with a router in between you cannot have a device in network A send a packet to the MAC address of a device in network B. No device in network A has the MAC address of the device in network B, so a packet to this MAC address will be discarded by all devices in the network A (also by the router).
Routing is done on IP level. Simply seen the router is just doing what I described above in the section “How do IP addresses and MAC addresses work together?”. The router will receive packets for its own MAC address but for a different IP address. He will then check if he can directly reach the target IP address. If so, he sends the packet to the target. Otherwise the router itself also has an upstream router configured and will send the packet to that router.
Of course you can have multiple routers configured. Your home router will only have one upstream router configured, but in the internet backbone the big routers have big routing tables so they know the best ways for all packets.
Other use cases for MAC addresses
Network switches store a list of MAC addresses seen at every port and only forward packets to the ports that need to see the packet. Wireless access points often use MAC addresses for access control. They only allow access for known devices (MAC address is unique and identifies devices) with the correct passphrase. DHCP servers use the MAC address to identify devices and give some devices fixed IP addresses.