Fundamentals 20 min read

How Do Computers Communicate? A Deep Dive into IP, MAC, ARP, DHCP, and NAT

This article uses vivid school analogies and detailed diagrams to explain how computers communicate over networks, covering concepts such as hosts, subnets, IP and MAC addresses, subnet masks, ARP, DHCP, routing, and NAT, helping readers grasp both basic and advanced networking principles.

Su San Talks Tech
Su San Talks Tech
Su San Talks Tech
How Do Computers Communicate? A Deep Dive into IP, MAC, ARP, DHCP, and NAT

Preface

We deeply analyze the classic question of the complete path from entering a product on Taobao to its final display, covering both hardware (switches, routers, NICs) and software (TCP, LVS) mechanisms, and provide extensive diagrams to illustrate the network’s soft‑ and hardware‑level operations.

Using a School Scenario to Understand Network Concepts

Technical terms become clearer when mapped to everyday school life. A teacher’s list of students represents a host list; shouting a name is analogous to broadcasting; the class corresponds to a subnet; the class identifier is the network address; a student’s name is the host address; the combination of class and name forms an IP address; the student’s appearance plus ID card mimics a MAC address; and moving between classes represents a gateway. 主机: student (host) 子网: class (subnet) 网络地址: class identifier (network address) 主机地址: student name (host address) IP 地址: class + student (IP address) 子网掩码: length of class identifier indicating network portion mac 地址: student’s appearance + ID (MAC address) 网关: door to another class (gateway)

How Computers Communicate

1. Communication Within the Same Subnet

Computers connect via a switch. Because a single NIC cannot connect to hundreds of machines directly, a middle layer (switch) is added to which all computers attach. DHCP dynamically assigns IP addresses: a new host broadcasts a DHCP DISCOVER packet (source IP 0.0.0.0, destination 255.255.255.255); the DHCP server replies with an offered IP and the host’s MAC; the host confirms, and the server acknowledges, completing the IP assignment.

When a host A wants to talk to host D in the same subnet, it first checks the subnet mask. If the network portions match, A broadcasts an ARP request asking “who has 192.168.1.13?”. D replies with its MAC, allowing A to update its ARP table. The switch learns the port‑MAC mapping and forwards subsequent frames directly to D without further broadcast.

2. Communication Across Different Subnets

If the destination is in another subnet, the source must send the packet to the default gateway (usually a router). A first obtains the gateway’s MAC via ARP, then sends the packet with the destination IP unchanged but the destination MAC set to the gateway’s MAC. The router looks up its routing table, determines the appropriate outgoing interface (next hop), possibly performs another ARP to resolve the next hop’s MAC, rewrites the source MAC to its own, and forwards the packet.

Routers use routing tables consisting of destination network, subnet mask, next‑hop IP, and outgoing port. To avoid large ARP caches, routers forward packets to the next‑hop IP rather than directly to every host in the destination subnet.

Public Network, Private Network, and NAT

Private (intranet) networks use non‑routable address spaces; devices inside must translate their private IP to a globally unique public IP to reach the Internet. This translation is performed by NAT, which also maps source ports (the TCP four‑tuple) so that return traffic can be correctly routed back to the originating private host.

Summary

Understanding both IP and MAC is essential: IP locates the subnet, reducing broadcast storms, while ARP resolves the MAC within that subnet, enabling direct communication. The analogy of finding a student by first locating the class (subnet) and then the student (host) illustrates why both layers are indispensable. This also clarifies why switches operate at Layer 2 (MAC) and routers at Layer 3 (IP).

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

routingNetworkingNATipMacARPDHCP
Su San Talks Tech
Written by

Su San Talks Tech

Su San, former staff at several leading tech companies, is a top creator on Juejin and a premium creator on CSDN, and runs the free coding practice site www.susan.net.cn.

0 followers
Reader feedback

How this landed with the community

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.