Computer Networks Interview Questions · Question 05

Why does a device need both a MAC address and an IP address for communication?

Interview preparation resource from Gate Smashers.

Interview-ready answer

IP and MAC addresses serve different scopes. An IP address identifies the source and intended destination for routing between networks, while a MAC address is used to deliver a frame over the current local Ethernet or Wi‑Fi link. To send an IP packet, the sender encapsulates it in a Layer 2 frame addressed to either the destination host on the local network or to the next-hop router. At each routed hop, the router forwards the IP packet in a new Layer 2 frame with local source and destination MAC addresses.

Understand it clearly

Different layers and purposes

IP addressing operates at the network layer. It provides logical addressing that lets routers determine how to forward packets toward the destination network and host.

MAC addressing operates at the data-link layer on technologies such as Ethernet and Wi‑Fi. A MAC address identifies the local interface that should receive a frame on that link. It is not necessarily a permanent physical identifier; it is a link-layer address used for local delivery.

  • IP address: Used for routing packets across networks toward an intended destination.
  • MAC address: Used to deliver a frame to the next receiver on the current local link.

Sending to a local or remote destination

Before sending on an Ethernet or Wi‑Fi network, a host determines whether the destination IP address is directly reachable on its local network. It then obtains the relevant local link-layer address, commonly through ARP for IPv4 or Neighbor Discovery for IPv6.

If the destination is local, the frame is addressed to the destination host's MAC address. If the destination is remote, the frame is addressed to the default gateway's MAC address, while the IP packet still names the remote destination.

  • Local destination: The frame's destination MAC address is the destination host's MAC address.
  • Remote destination: The frame's destination MAC address is the next-hop router's MAC address.

What changes at routers

A router receives a Layer 2 frame, removes its link-layer encapsulation, examines the IP packet, and chooses the next hop using the destination IP address. It then sends the packet on its outgoing link inside a newly created Layer 2 frame.

Therefore, the Layer 2 source and destination MAC addresses are local to each routed link and generally change at routers. The original IP source and destination usually remain end-to-end, although mechanisms such as network address translation can modify IP addresses.

Why both are needed

IP addresses answer where the packet is ultimately intended to go across interconnected networks. MAC addresses answer which local interface should receive the frame for the next step. IP routing alone does not provide local frame delivery, and a MAC address alone does not provide routing across separate IP networks.

Quick comparison
BasisIP addressMAC address
Protocol layerNetwork layerData-link layer
Primary roleLogical addressing and routing toward the intended destinationLocal frame delivery to the next receiver on a link
ScopeAcross IP networksCurrent local link
Behavior at routed hopsUsually retained from source to destinationReplaced when a router creates a frame for the next link