Understanding MAC Addresses, IP Addresses, Subnets, Switches, and Routers in Network Layers
This article explains how computers use MAC and IP addresses, subnet masks, ARP, hubs, switches, and routers to communicate across physical, data‑link, and network layers, illustrating the learning process with step‑by‑step examples and tables of address mappings.
The article begins by personifying a computer (A) that initially has no network connection and then connects to another computer (B) with a simple Ethernet cable, introducing the concept of a physical link without delving into low‑level I/O details.
It then describes the first networking device, a hub, which simply broadcasts incoming frames to all ports, placing the hub in the physical layer and highlighting the need for unique MAC addresses for each device.
Next, the switch is introduced as an intelligent hub that learns MAC‑to‑port mappings in a MAC address table, forwarding frames only to the correct destination port and reducing unnecessary traffic.
The router is presented as a layer‑3 device with its own MAC addresses on each interface, capable of forwarding packets between different subnets based on a routing table that maps destination IP networks to output ports or next‑hop addresses.
The article explains the structure of MAC addresses (48‑bit hardware identifiers) and contrasts them with IP addresses, which are 32‑bit logical identifiers that can be expressed in dotted‑decimal notation and organized into subnets using subnet masks (e.g., 255.255.255.0).
Subnetting is illustrated: devices whose IP addresses share the same network portion (after applying the mask) are considered to be in the same subnet and can communicate directly; otherwise, they must send packets to a default gateway.
ARP (Address Resolution Protocol) is described as the mechanism by which a host discovers the MAC address corresponding to a known IP address, populating an ARP cache after broadcasting a request and receiving a reply.
Routing tables are shown in tabular form, mapping destination networks (with optional subnet masks) to output ports and next‑hop IPs, and the process of packet forwarding through multiple routers is detailed step‑by‑step, including MAC address updates at each hop.
Finally, the article summarizes the perspectives of computers, switches, and routers, emphasizing the three key tables (MAC address table, routing table, ARP cache) that enable end‑to‑end communication across the first three OSI layers.
Refining Core Development Skills
Fei has over 10 years of development experience at Tencent and Sogou. Through this account, he shares his deep insights on performance.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.