IP address, MAC address and ARP
Internet Protocol (IP) address is unique ID assigned to every device connected on a particular network so that it can be located on that network.
So, an IP address solves two purposes: Identification and Location addressing.
There are two types of IP addresses —
- IPv4 uses 32 bits long address.
- A newer version called IPv6 uses 128 bits long address.
We’ll focus our discussion on IPv4 address. Generally we use dotted decimal notation to write an IP address.
For example 10100110 00000110 01100110 01000111 can be written as 166.6.102.71.
We divide 32 bit long address space into 4 segments of 8 bits each. Then we find out the decimal value of each segment. The value of any segment is [0,255] inclusive.
Now the question arises that how do IP addresses resolve the location of any device on a network. For that let’s understand Classfull Addressing and Classless Addressing.
32 bit IP address can be divided into five subclasses — Class A, Class B, Class C, Class D, Class E. Each of these classes has a valid range of IP addresses.
Every IP address has two parts —
- Network ID (NID) to identify the network.
- Host ID (HID) to identify the host within a particular network.
Class A
- NID is 8 bits long and HID is 24 bits long.
- First bit of NID is set to 0 and remaining 7 bits can have any value.
- Range of IP addresses is 1.x.x.x — 126.x.x.x
- Number of network addresses is 2⁷ = 128.
- Number of host addresses is 2²⁴ ~ 65 million.
Class B
- Both NID and HID are 16 bits long.
- First two bits of NID is 10 and remaining 14 bits can have any value.
- Range of IP addresses is 128.0.x.x — 191.255.x.x
- Number of network addresses is 2¹⁴ ~ 16K.
- Number of host addresses is 2¹⁶ ~ 65K.
Class C
- NID is 24 bits long and HID is 8 bits long.
- First bit of NID is set to 110 and remaining 21 bits can have any value.
- Range of IP addresses is 192.0.0.x — 223.255.255.x
- Number of network addresses is 2²¹ ~ 2 million.
- Number of host addresses is 2⁸ = 256.
Class D
- IP address of class D are reserved for multicasting.
- First bit of NID is set to 1110.
- Range of IP addresses is 224.0.0.0–239.255.255.255
Class E
- IP address od class E are reserved for research and military purposes.
- First bit of NID is set to 1111.
- Range of IP addresses is 240.0.0.0–255.255.255.254
Disadvantage of classfull addressing
The large size of host ID causes so many addresses getting wasted in class A and B. Class C cannot cater the need of organizations because it provides so less numbers of host IDs. Class D and E are not in commercial use. So, classless addressing comes into picture.
To reduce the wastage of IP addresses, we use subnetting. Subnetting essentially means dividing a network into two or more smaller sub-networks. Each IP address consists of a subnet mask. The purpose of subnet mask is to determine the type and number of IP addresses required for a given local network.
Media Access Control (MAC)
Media Access Control (MAC) address is unique hardware identifier assigned to every network adapter typically used to direct packets from one device to another. No two adapters can have same MAC address. MAC address is a 12 hexadecimal characters long address embedded in Network Interface Controller (NIC) of the device. Ex. 00:1C:B3:09:85:15 is a form of MAC address. Each network adapter on your device including Ethernet, WiFi and Bluetooth have MAC address.
If you’re directly connected to a network (maybe Ethernet cable), then your device will have an IP address that can be used to locate your device on the network. However if you are connected to a router, then that router address will have public IP address. It will setup a private network with all the devices connected to it, assigning IP addresses out of private range not visible on Network. Any traffic generated by your device must go through the router and it will appear on the network to have come from router. MAC travels the network until the next device along the way is reached where it will get replaced by MAC of that next device. This process continues till packets reach the right destination.
Address Resolution Protocol (ARP)
Address Resolution Protocol (ARP) is a mapping that converts IP address to MAC address. When a data packet destined for a particular client machine arrives on a LAN network, then ARP converts IP address of client machine to MAC address of client machine and packets are redirected to client machine. A lookup table, called ARP cache, is used to store mapping of IP address and MAC address. However if IP address doesn’t match with any entry in ARP cache then the packet is discarded.