As you know that the data you generate using various applications gets encapsulated at multiple layers before it is transferred over a network.
L2: Data link(Ethernet, Token Ring, PPP)
The framed packet is then converted into electrical signal(copper media) or light photons (fiber optic media) or radio wave(wireless media) and transmitted across the medium. At the destination, the received frame is stripped off header-by-header at the corresponding layer to deliver the data to the right application.
There are two addresses that are used to identify and deliver the packet to the destination.
1. Logical or Layer-3 address
2. Physical or Layer-2 address
The logical address is essential to identify the network of the destination host. It’s similar to your distant friend’s home address you write on the post card which directs the postal personnel to go toward. The IP is the ubiquitous Layer-3 protocol and the IP address plays the role of identifying the host logically.
IPv4 is the widely deployed IP version (for now) whose address is depicted as a dot separated 4 decimal numbers each in the range 0 to 255.
Eg. 192.168.10.12, 172.16.21.2 etc.
Every IP address also has an associated mask address. What it does is it separates the network part from the host part in the IP address. For example, the IP address 192.168.10.12 has a default mask address 255.255.255.0. The mask is logically ANDed with the IP address to get the network address.
(192.168.10.12) AND (255.255.255.0) = 192.168.10.0
The network address 192.168.10.0 is what actually gets stored in the router’s routing table and the packets are routed accordingly.
The IP address is a logical one, meaning it’s a tool for us(and routers) to locate and think about the nodes in the network. Similar to the destination address on the post card. But there has to someone who physically picks up your post card from the mail box to put it into city’s mailbox, next into neighboring city’s mailbox, so on until it reaches the mailbox of your friend’s city. And each of these hops require a local, immediate physical address of the mailbox for a postman to put the letter into it on your behalf. That address is called physical or layer-2 or data-link address in Networking parlance.
The MAC(Media Address Control) is the widely used layer-2 addressing scheme. It’s a colon separated 6 byte address in hexadecimal digits. The first 3 bytes identifies the manufacture of the NIC card, known as OUI (Organizationally Unique Identifier). The next 3 bytes identifies the NIC card of a particular vendor. This MAC address is what makes the packet to get physically delivered to the destination. MAC address space is flat, meaning every host must have a unique MAC address (not strictly speaking, I’ll write about it.) within the same physical network segment. MAC address changes from hop to hop as the packet gets routed toward its destination(IP address). Meaning the intermediate routers(postmen) must know(memorize) the next-hop router’s MAC address. That router in turn its next-hop interface’s MAC address, so on and so forth till the destination’s default router.
The astonishing fact is that all these things happen within milli seconds!
Points to remember:
- IP connects multiple heterogeneous networks by abstracting out the physical technologies implemented. Hence the global network called Internet.
- IP address identifies the hosts in the network of networks.
- IP address provides a way to reach every host in the network. Immediate or far-away.
- Routers use IP address(specifically network address) to make routing decisions.
- Mask draws a line between the network and host part in the IP address.
- [IP address] Logical AND [Mask] = Network Address
- IP address is hierarchical. Same IP addresses can be used in different networks and still reach the hosts.
- MAC address is the actual physical address of host which must be unique throughout the network.
- MAC address gets switched every hop whereas IP address will never change.
- IP address is analogous to your cell phone number which changes as you change your SIM card. MAC address is your phone’s IMEI number which will never change.