
In the previous article, we answered "why MAC addresses aren't enough" — because they are flat, non-hierarchical, and switches can't make forwarding decisions at Internet scale. The conclusion: the Internet needs a hierarchical, logical addressing system that lets intermediate devices decide direction based on address prefixes, without needing to memorize the location of every device on the planet.
That system is the IP address. But what does "hierarchical" actually mean? How does an IP address split into a network portion and a host portion? How does your computer determine whether a target IP is "one of us" or "send to the gateway"?
This chapter unpacks the internal structure of IP addresses, so you can truly see how a router "knows which way to forward."
Understand why the Internet needs hierarchical addressing
Basic familiarity with binary-to-decimal conversion
Understand how ARP works
Open your terminal and check your IP configuration:
# macOS / Linux
ifconfig en0 | grep inet
# You might see output like:
# inet 192.168.1.10 netmask 0xffffff00 broadcast 192.168.1.255You see three numbers: 192.168.1.10, 0xffffff00, 192.168.1.255. The first two are familiar — your IP address and subnet mask. But do you really understand the relationship between them?
More specifically, recall a key operation from the ARP article: when your computer pings github.com (whose IP is, say, 151.101.2.133), it does NOT ARP-query that IP directly. Instead, it turns to the gateway 192.168.1.1. What makes your computer decide "151.101.2.133 is not in my neighborhood"?
The answer lies in the bitwise logic of IP addresses and subnet masks.
We normally see IP addresses in forms like 192.168.1.10 — this is called dotted decimal notation. But computers don't understand this — they only understand binary. Every IPv4 address is fundamentally 32 binary bits, divided into 4 groups of 8 bits (one byte each). The decimal value of each byte is joined by dots for human readability.
192 .168 .1 .10
11000000 .10101000 .00000001 .00001010So 192.168.1.10 is, to a computer, a 32-bit binary number:
11000000 10101000 00000001 00001010Understanding this binary face is critical — because the division between network and host portions, and the entire subnet mask mechanism, operate entirely at the binary level. The decimal form is just a skin for human eyes.
The "hierarchical structure" of an IP address is this: every IP address is naturally divided into two parts — the Network ID and the Host ID.
┌──────────────────┬──────────────────────┐
│ Network ID │ Host ID │
│ (which network) │ (which host inside) │
└──────────────────┴──────────────────────┘A postal address analogy:
Beijing, Haidian District · 1 Zhongguancun Street
└─── Network ID ──────┘ └── Host ID ──┘All addresses within "Haidian District" share the same "Beijing, Haidian District" prefix. The post office only needs to see "Beijing, Haidian District" to know which direction to send a letter. Once the letter arrives in Haidian District, the specific mailbox is located using "1 Zhongguancun Street."
IP addresses work the same way: all IPs sharing the same Network ID belong to the same network (the same broadcast domain). Routers only need to look at the Network ID to decide forwarding direction. Delivery to the specific device within the network is the job of switches and MAC addresses.
This perfectly answers the question left from the previous article: why can a single routing rule cover thousands or millions of devices? Because routers only remember Network IDs, not Host IDs.
Now the question: in 192.168.1.10's 32 bits, how many leading bits are the Network ID, and how many trailing bits are the Host ID? The IP address alone tells you nothing.
The answer comes from its partner: the subnet mask.
A subnet mask is also a 32-bit binary number, but it has a very distinctive shape: a continuous block of 1s followed by a continuous block of 0s. No interleaving — just a clean boundary.
IP Address: 192.168.1.10 → 11000000 10101000 00000001 00001010
Subnet Mask: 255.255.255.0 → 11111111 11111111 11111111 00000000
└─── 24 ones ───┘ └─ 8 zeros ─┘In the subnet mask, the portion covered by 1s is the Network ID; the portion covered by 0s is the Host ID. In this example, the first 24 bits are the network portion, the last 8 bits are the host portion.
The computer extracts the Network ID using a simple bitwise AND operation:
11000000 10101000 00000001 00001010 (192.168.1.10 — your IP)
& 11111111 11111111 11111111 00000000 (255.255.255.0 — subnet mask)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
11000000 10101000 00000001 00000000 (192.168.1.0 — network address)The rule is straightforward: 1 AND 1 = 1, 1 AND 0 = 0, 0 AND 0 = 0. The mask's 1s let the corresponding IP bits "pass through"; the mask's 0s "zero out" the corresponding IP bits. The result is the network address of the network your IP belongs to.
The number of bits covered by 0s in the subnet mask is the number of host bits, which also determines the maximum number of devices in the network:
Mask 255.255.255.0 → 8 bits for hosts
Theoretical host count = 2⁸ - 2 = 254 devices
(subtract two reserved addresses: the all-0 network address and the all-1 broadcast address)This is the fundamental meaning behind "your home network can support up to 254 devices" — the 8-bit host portion allocated by the subnet mask defines your IP address pool size.
Constantly writing 192.168.1.0 / 255.255.255.0 is verbose. Network engineering has a cleaner notation: CIDR (Classless Inter-Domain Routing).
CIDR simply writes the count of 1s in the subnet mask after the IP, separated by a slash:
192.168.1.0 / 255.255.255.0 → 192.168.1.0/24
10.0.0.0 / 255.0.0.0 → 10.0.0.0/8
172.16.0.0 / 255.255.0.0 → 172.16.0.0/16/24 means "the first 24 bits are the Network ID," /8 means "the first 8 bits are the Network ID." It's concise, precise, and completely frees us from the outdated Class A/B/C classification.
Common CIDR prefixes and their corresponding subnet masks:
/8 → 255.0.0.0 (~16.77 million hosts)
/16 → 255.255.0.0 (~65,534 hosts)
/24 → 255.255.255.0 (254 hosts)
/28 → 255.255.255.240 (14 hosts)
/32 → 255.255.255.255 (1 host — this device only)Why don't we talk about Class A/B/C anymore? Because that classification system (Class A = /8, Class B = /16, Class C = /24) was superseded by CIDR 30 years ago. Under CIDR, the boundary between network and host portions can be at any position — like /26, a division that never existed in the classful world. Clinging to the "Class A/B/C" mindset only confuses beginners.
Back to our original question: how does your computer know 151.101.2.133 is not on the local network?
The answer is now clear — it performs a bitwise AND between the target IP and its own subnet mask, then compares the result to its own network address.
Your IP: 192.168.1.10 → 11000000 10101000 00000001 00001010
Your subnet mask: 255.255.255.0 → 11111111 11111111 11111111 00000000
Your network addr: 192.168.1.0 → 11000000 10101000 00000001 00000000
Target IP: 151.101.2.133 → 10010111 01100101 00000010 10000101
& Your subnet mask: 255.255.255.0 → 11111111 11111111 11111111 00000000
Target network: 151.101.2.0 → 10010111 01100101 00000010 00000000
Compare: 192.168.1.0 ≠ 151.101.2.0 → Different network → Send to gateway!Conversely, if the target is 192.168.1.20:
Target IP: 192.168.1.20 → 11000000 10101000 00000001 00010100
& Subnet mask: 255.255.255.0 → 11111111 11111111 11111111 00000000
Target network: 192.168.1.0 → 11000000 10101000 00000001 00000000
Compare: 192.168.1.0 = 192.168.1.0 → Same network → ARP the target directly!Every operating system performs this check before sending any data packet. Now you can use this knowledge to explain a wide range of networking phenomena: why two computers with mismatched subnet masks might not communicate, why ping 127.0.0.1 never touches your network card, why a VPN connection adds extra entries to your routing table — they all boil down to subnet checks happening behind the scenes.
By now, you understand how IP addresses split into network and host portions. But here's another question: your home's 192.168.1.10 and your neighbor's 192.168.1.10 — won't they conflict?
The answer is: no, because these two IPs live in their respective LANs and can never see each other. This is the concept of private IPs.
The IETF reserved three IP address ranges in RFC 1918, specifically for LAN-internal use:
10.0.0.0/8 → 10.0.0.0 ~ 10.255.255.255 (~16.77 million)
172.16.0.0/12 → 172.16.0.0 ~ 172.31.255.255 (~1.04 million)
192.168.0.0/16 → 192.168.0.0 ~ 192.168.255.255 (~65,534)These three ranges share a common trait: routers on the Internet will never forward packets destined for private IP addresses. Private IPs only work within a LAN; once past the router, no one recognizes them.
Think of it like internal employee IDs — "I'm employee #3" has meaning inside the company, but outside the building, the statement means nothing to anyone.
In contrast, a public IP is globally unique and routable across the Internet. Your router's WAN port holds a public IP (e.g. 100.64.0.2), and it acts as the "spokesperson" for your entire home network on the Internet.
Now a problem arises: three devices at home each have private IPs (192.168.1.10, 192.168.1.20, 192.168.1.30), but the router has only one public IP. How do they all access the Internet simultaneously?
The answer is NAT (Network Address Translation). When forwarding a packet, the router replaces the private source IP with its own public IP and remembers "this port number originally corresponds to which device inside." When the reply comes back, it reverse-maps the port number back to the correct internal device.
PC A (192.168.1.10:50001) ──┐
Phone B (192.168.1.20:50002) ──┼── Router ─── Internet
Tablet C (192.168.1.30:50003) ──┘ 100.64.0.2
Router NAT table:
Internal 192.168.1.10:50001 → External 100.64.0.2:60001 → github.com:443
Internal 192.168.1.20:50002 → External 100.64.0.2:60002 → google.com:443
Internal 192.168.1.30:50003 → External 100.64.0.2:60003 → twitter.com:443NAT has been the "life support" of the IPv4 era — it allows billions of devices to access the Internet through just a few hundred million public IPs, dramatically slowing IPv4 address exhaustion. But it also introduces a side effect: external hosts cannot directly reach internal devices (unless you set up port forwarding), a common pain point for P2P connections, remote desktop, and similar scenarios.
IPv4 has only 32 bits, which means the theoretical maximum number of addresses is:
2³² = 4,294,967,296 ≈ 4.3 billion4.3 billion sounds like a lot — but the world population exceeds 8 billion, and each person has more than one connected device on average. Phones, laptops, tablets, smartwatches, TVs, game consoles, IoT sensors... plus servers, routers, and switches that also need IPs.
In reality, IPv4 addresses were fully allocated by 2011. For over a decade since, we've relied on survival tactics like NAT and address reclamation — but these are bandaids, not cures.
IPv6 expands the address from 32 bits to 128 bits:
2¹²⁸ ≈ 3.4 × 10³⁸ ≈ 340 undecillionHow big is this number? Every square meter of the Earth's surface could be assigned approximately 667 sextillion IPv6 addresses. It's not just one address per device — every atom could have an address.
IPv6 addresses use hexadecimal notation, with groups of 4 hex digits separated by colons:
2001:0db8:0000:0000:0000:ff00:0042:8329
→ after omitting leading zeros and consecutive zero blocks:
2001:db8::ff00:42:8329A typical residential IPv6 prefix is /64, meaning every household gets 2⁶⁴ addresses. NAT becomes unnecessary in IPv6 — every device can have its own globally unique public address.
IPv6 is a massive topic: extension headers, SLAAC (stateless auto-configuration), NDP (Neighbor Discovery Protocol replacing ARP), multicast replacing broadcast... all deserve deep discussion. For this article, you only need to understand:
For now, continue using IPv4 as the primary vehicle for learning network layer concepts — almost all networking principles are common between IPv4 and IPv6.
Check your IP configuration and subnet mask
# macOS / Linux
ifconfig en0 | grep inet
# Windows
ipconfigFind your IP address and subnet mask. Write your network address in CIDR notation (e.g. 192.168.1.0/24). What's the maximum number of devices your home network can support?
Manually determine if a target is on the same subnet
Suppose your IP is 10.0.0.45 and your subnet mask is 255.255.255.0. Which of the following IPs are on the same subnet as you?
10.0.0.10010.0.1.45192.168.1.1Show your working (IP & mask → compare network addresses).
Check your router's public IP
Visit https://ifconfig.me in your browser or run curl ifconfig.me. Is the IP you see the same as what ifconfig shows? If not, why?
Verify subnet check behavior on a real network
On a LAN with subnet mask 255.255.255.0, configure two machines as 192.168.1.10 and 192.168.2.10. Use Wireshark to observe what happens when they ping each other. Was an ARP request ever sent? If not, at what step was it blocked?
Calculate address ranges for a /26 network
A /26 prefix means the subnet mask is 255.255.255.192. For IP 192.168.1.100/26, compute:
192.168.1.0/24) is a more precise and modern notation than the Class A/B/C system.10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) only work within a LAN and cannot cross routers. Public IPs are globally unique.You now understand the static structure of IP addresses: what they look like, how Network and Host portions are divided, how subnet masks work, and the difference between public and private IPs. But a critical question remains unanswered:
Once you hand a packet to the gateway, what does the gateway (router) do next? How does it know where the "next hop" should go?
The next article formally enters the world of routing — the structure of routing tables, static vs. dynamic routing protocols (RIP, OSPF, BGP), the meaning of the default route, and the complete journey of a data packet traversing multiple networks.