Network Communication Demystified: The Mechanics of IP-Based Data Transmission
Imagine you’re sending a letter. If the recipient lives in your neighborhood, you might deliver it directly to their house. But if they live in a different city, you’ll drop it at the nearest post office, which takes responsibility for forwarding it to the destination. Computers in a network work similarly when deciding how to send data.
When a device (Machine A) wants to send data, it checks whether the destination is in the same "neighborhood" (local network) or far away (external network). This decision is crucial for efficient communication and relies on the combination of the device's IP address, the destination's IP address, and the subnet mask. If the destination is local, Machine A sends the data directly to the recipient. If not, it forwards the data to a gateway (like the post office) to route it further.
A. How Machine A Decides Where to Send Data: Destination or Gateway
It takes a series of steps for a machine to ascertain if the destination machine is on the same network or not.
Step 1: Check if the Destination is in the Same Network
When Machine A wants to send data, it first checks whether the destination device is in the same network or a different one. This is based on comparing the Network IDs of its own IP address and the destination's IP address.
What is the Network ID?
The Network ID or Subnet Number is derived by applying the subnet mask to the IP address. It defines the boundary of a network by distinguishing the network part of the IP address from the host part.
But Wait! How Does Machine A Know the Network ID of the Destination?
At this point, Machine A only knows the destination ip address or domain name (e.g., example.com
) in case you are trying to reach a website using domain name. Here first machine A will esolve this domain name into an IP address before it can proceed. This resolution is done using the Domain Name System (DNS).
So Exactly What is compared ?
Now that Machine A knows the destination IP address, it applies the subnet mask to its own IP address and the destination's IP address to derive their respective Network IDs.
-
If the Network IDs Match:
The destination is in the same subnet (local network), and Machine A can send the data directly. -
If the Network IDs Differ:
The destination is in a different subnet, and Machine A must send the data to the default gateway for routing.
But How Do We Actually Calculate the Network ID? Let’s find out in Step 2.
Step 2: Perform Subnet Matching with Bitwise AND
Machine A uses a bitwise AND operation to determine the Network ID of its own address and the destination address. Here’s how this works:
Example 1: Destination is Local (Same Subnet)
- Machine A's IP Address:
192.168.1.10
- Subnet Mask:
255.255.255.0
- Destination IP Address:
192.168.1.20
Bitwise AND Operation:
Machine A's Network ID:
192.168.1.10 = 11000000.10101000.00000001.00001010 255.255.255.0 = 11111111.11111111.11111111.00000000 --------------------------------------------------- Network ID = 11000000.10101000.00000001.00000000 (192.168.1.0)
Destination's Network ID:
192.168.1.20 = 11000000.10101000.00000001.00010100
255.255.255.0 = 11111111.11111111.11111111.00000000
---------------------------------------------------
Network ID = 11000000.10101000.00000001.00000000 (192.168.1.0)
Result: Both have the same Network ID (192.168.1.0
).
Action: Machine A sends the data directly to 192.168.1.20 after resolving its MAC address using ARP.
Example 2: Destination is Remote (say google.com)
- Machine A's IP Address:
192.168.1.10
- Subnet Mask:
255.255.255.0
- Destination IP Address:
142.250.194.238
Bitwise AND Operation:
Machine A's Network ID:
192.168.1.10 = 11000000.10101000.00000001.00001010 255.255.255.0 = 11111111.11111111.11111111.00000000 --------------------------------------------------- Network ID = 11000000.10101000.00000001.00000000 (192.168.1.0)
Destination's Network ID:
142.250.194.238 = 10001110.11111010.11000010.11101110 255.255.255.0 = 11111111.11111111.11111111.00000000 --------------------------------------------------- Network ID = 10001110.11111010.11000010.00000000 (142.250.194.0)
Result:
- Machine A's Network ID is
192.168.1.0
and the destination's Network ID is142.250.194.0
. - Since the Network IDs are different (
192.168.1.0
≠142.250.194.0
), Machine A determines that the destination is on a different subnet.
Action: Machine A will send the data to its default gateway (e.g., 192.168.1.1
).
B. How Machine A Forwards the Data
It takes a series of steps for a machine to ascertain if the destination machine is on the same network or not.
Step 1: Forward the Data – From Machine A to Machine B
Once Machine A has determined that the destination is in the same network or a different network (via the gateway), the next step is to forward the data to its destination.
This step involves a deeper look at the process, including the roles of MAC addresses, ARP resolution, switches, routers, and the relevance of the OSI model at each layer.
Why Do We Need MAC Addresses?
MAC addresses are fundamental for communication within any physical or logical network segment. While IP addresses determine the logical endpoint for data, MAC addresses ensure that the data can be physically delivered to the next device along the path.
- Same Network: The next hop is the final destination (Machine B).
- Different Network: The next hop is the default gateway (router), which forwards the data toward the destination network.
Step 2 :Resolve the MAC Address of the Next Hop
To communicate with the next hop, Machine A must resolve its MAC address. This is done using the Address Resolution Protocol (ARP):
- Check ARP Cache: Machine A first checks if it already knows the MAC address of the next hop (either Machine B or the default gateway). If it does, it uses that MAC address directly.
- Broadcast ARP Request: If the MAC address is not in the ARP cache:
- Machine A broadcasts an ARP request to all devices in the local subnet:
"Who has IP addressX
? Tell me your MAC address." - For same subnet communication,
X
is Machine B's IP. - For different subnet communication,
X
is the default gateway's IP.
- Machine A broadcasts an ARP request to all devices in the local subnet:
- Receive ARP Reply:
- The device (Machine B or the gateway) with the requested IP sends a unicast ARP reply containing its MAC address.
- Machine A stores the MAC address in its ARP table for future use.
Step 3. Encapsulation and Frame Forwarding
Machine A encapsulates the data into a frame that can be sent over the network:
- Layer 3 (Network Layer): The IP packet contains:
- Source IP address (Machine A’s IP, e.g.,
192.168.1.10
). - Destination IP address (Machine B’s IP, e.g.,
192.168.1.20
, or a remote address like142.250.194.238
).
- Source IP address (Machine A’s IP, e.g.,
- Layer 2 (Data Link Layer): The frame header contains:
- Source MAC address (Machine A’s MAC).
- Destination MAC address (resolved MAC of Machine B or the gateway).
- Send the Frame to the Network:
- Machine A transmits the frame to the network, where it is picked up by the next hop (either Machine B or the gateway).
Step 4. Data Forwarding Within the Network (Switch Operation)
A switch forwards the frame based on the destination MAC address:
- The switch checks its MAC address table to determine the correct port for the destination MAC.
- It forwards the frame to the appropriate port:
- Case 1: If the destination MAC belongs to Machine B, the frame is delivered to Machine B.
- Case 2: If the destination MAC belongs to the gateway, the frame is forwarded to the router.
Switches operate at Layer 2 (Data Link Layer) and are unaware of IP addresses.
Step 5. Data Forwarding Between Networks (Router Operation)
If the next hop is the router:
- Receive and De-Encapsulate the Frame:
- The router removes the Layer 2 frame to inspect the Layer 3 IP packet.
- Routing Decision (Layer 3):
- The router examines the destination IP address and checks its routing table to decide where to forward the packet:
- If the destination is directly connected, the router sends the packet to the destination subnet.
- Otherwise, the router forwards it to another router (the next hop).
- Re-Encapsulate the Packet:
- The router encapsulates the IP packet into a new Layer 2 frame:
- Source MAC: The router’s outgoing interface MAC address.
- Destination MAC: The MAC address of the next hop (another router or Machine B).
- Send the Frame to the Next Hop:
- The router transmits the frame through the appropriate interface.
This process repeats at every router along the path until the packet reaches the destination subnet.
Step 6. Final Delivery to the Destination (Remote Network)
Once the packet reaches the destination subnet:
- Resolve the MAC Address:
- The last router uses ARP to resolve the MAC address of Machine B if not already cached.
- It encapsulates the IP packet in a frame addressed to Machine B’s MAC.
- Switch Forwarding:
- The switch in Machine B’s local network forwards the frame to the correct port based on Machine B’s MAC.
- Machine B Processes the Packet:
- Machine B verifies that the destination IP matches its own and processes the packet.
- The packet is passed up the OSI layers to the application.
About Upspir
Bridging the Gap: Skilling Professionals, Solving Resourcing
At Upspir, we specialize in training professionals to excel in technical support roles by combining in-depth technical knowledge with essential soft skills. Our programs focus on self-learning, problem-solving, and strong work ethics, ensuring candidates are job-ready and adaptable. Backed by 16 years of industry expertise, we are committed to solving hiring challenges and delivering skilled talent that meets your needs.