Fundamentals 21 min read

Understanding How Computers Communicate: From IP and MAC to Routing, NAT and Beyond

This article explains the fundamental mechanisms of computer networking—including IP addressing, MAC addresses, ARP, DHCP, subnetting, routing, and NAT—using clear analogies and detailed diagrams to help readers grasp how data travels from one host to another across local and wide-area networks.

Sohu Tech Products
Sohu Tech Products
Sohu Tech Products
Understanding How Computers Communicate: From IP and MAC to Routing, NAT and Beyond

Preface

We deeply analyze the classic question "Describe the complete path from entering a product on Taobao to its final display". The topic is difficult because it involves both hardware (switches, routers, NICs) and software (TCP, LVS). This article uses many diagrams to detail the operation of network hardware and software.

Note: the next part will discuss LVS principles.

Next we will dissect the communication flow between A and B in the diagram.

Using Everyday Scenarios to Understand Network Concepts

Technical terms can be hard to grasp, but mapping them to everyday situations makes them clear. We use a school scenario to illustrate network design.

On the first day of class, a teacher has a list of students but does not know each individual. He shouts "Li Si"; only Li Si responds, establishing a one‑to‑one mapping. This is analogous to a broadcast.

Because the class name (prefix) is the same for all students, the teacher only searches within that class, not other classes. The process of locating "Xuejun Primary School First Grade Class Li Si" involves:

First find the class 学军小学一年级一班 .

Then shout "Li Si" inside that class; only Li Si answers.

The teacher now knows the exact student and can address him directly next time.

If a student from Class 1 needs to find a student in Class 2, the teacher must first locate the other class (different prefix) before shouting the name.

Now we map the school analogy to network terminology:

Host : a student.

Subnet : a class (a collection of hosts).

Network address : the class identifier (e.g., "学军小学一年级一班").

Host address : the student's name (e.g., "Li Si").

IP address : combination of network address and host address, expressed in dotted decimal (e.g., 192.168.1.10).

Subnet mask : indicates which bits belong to the network part; written as "/9" in the analogy or "/24" in IPv4.

MAC address : the student's appearance + ID, a globally unique 48‑bit identifier.

Gateway : the door that must be used when communicating with a different class.

How Computers Communicate

There are two cases:

Both computers are in the same subnet.

Computers are in different subnets.

1. Same Subnet Communication

Computers need a physical link (cable) to talk. Because a single NIC can only connect to one cable, a switch acts as an intermediate layer, allowing many hosts to share the same medium.

IP addresses are assigned either statically or dynamically via DHCP. When a new host (A) joins, it broadcasts a DHCP DISCOVER packet (source IP 0.0.0.0, destination 255.255.255.255). The DHCP server replies with an OFFER containing an IP and the host's MAC. After the host acknowledges, the server sends an ACK and the host now has an IP.

When A wants to talk to D, it first checks whether D is in the same subnet using the subnet mask. If the network part matches, A sends an ARP broadcast asking "Who has IP 192.168.1.13?". D replies with its MAC address, and both A and the switch update their MAC‑to‑port tables.

Subsequent packets from A to D carry A's IP/MAC as source and D's IP/MAC as destination; the switch forwards the frame based on the destination MAC without further broadcasting.

2. Different Subnet Communication

When hosts are in different subnets, they must use a default gateway (usually a router). A first determines that D is in another subnet, then ARPs for the gateway's MAC, and sends the packet to the gateway with D's IP as the destination.

The router looks up its routing table, selects the appropriate outgoing interface (next hop), ARPs for the next hop's MAC if needed, rewrites the source MAC to its own, and forwards the packet. The source and destination IPs remain unchanged; only MAC addresses change at each hop.

Routers operate at layer 3 (network layer) because they make forwarding decisions based on IP addresses, while switches operate at layer 2 (data‑link layer) using MAC addresses.

Public Network, Private Network and NAT

Private networks (LANs) use non‑routable IP ranges; devices inside must go through NAT to reach the public Internet, where each device has a globally unique public IP.

NAT translates private IP/port pairs to public IP/port pairs (the TCP four‑tuple) so that return traffic can be correctly routed back to the originating host.

Summary

After reading this article you should understand how two hosts communicate over the Internet, why both IP and MAC addresses are needed, and how switches (layer 2) and routers (layer 3) work together. The next article will cover LVS.

Applying real‑world analogies to technical concepts often leads to faster comprehension.

RoutingnetworkingNATIPfundamentalsMACARPDHCP
Sohu Tech Products
Written by

Sohu Tech Products

A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.