IP¶
Summary
- Every device on a network needs an IP address to be reachable — a numeric identifier, paired with a subnet mask that says how much of that number identifies the network vs. the specific host.
- IPv4 uses 32-bit addresses (~4.3 billion total); IPv6 uses 128-bit addresses (~340 undecillion total) — introduced specifically because IPv4 ran out.
- Addresses fall into two categories — private (only meaningful inside a local network) and public (globally unique and routable) — and a default gateway is what a device sends traffic to whenever the destination isn't on its own local network.
Think of an IP address as:
"A street address with two parts — the neighborhood (network) and the house number (host) — and the subnet mask is what tells you exactly where the neighborhood name ends and the house number begins."
IP Address¶
An IP address is a numeric identifier assigned to a device (or, more precisely, to a network interface on that device) so it can send and receive traffic. On its own, an IP address is incomplete information — 192.168.1.50 doesn't tell you anything about which part identifies the network and which part identifies this specific device on it. That's exactly the job of a subnet mask, covered below — an IP address and a subnet mask always travel together.
Every IP address splits into two conceptual parts:
- Network portion — identifies which network this address belongs to
- Host portion — identifies this specific device within that network
Where that split happens isn't fixed — it depends entirely on the subnet mask (or, equivalently, the CIDR prefix) applied to the address.
Subnet Mask¶
A subnet mask is a second number, the same length as the IP address, that marks which bits belong to the network portion and which belong to the host portion. Wherever the mask has a 1 bit, that bit of the address is part of the network; wherever it has a 0, that bit is part of the host.
Working it out in binary
Take 192.168.1.50 with mask 255.255.255.0:
IP: 11000000.10101000.00000001.00110010 # (1)!
Mask: 11111111.11111111.11111111.00000000
└───────── network ────────┘└─ host ─┘
- The first three octets (
192.168.1) are the network; the last octet (50) identifies this specific host within that/24network.
A device combines its own IP with its subnet mask (via a bitwise AND) to figure out its network address — and, critically, to decide whether a destination address is on the same local network (deliver directly) or somewhere else entirely (send to the default gateway instead).
CIDR¶
CIDR (Classless Inter-Domain Routing) notation writes the subnet mask as a prefix length — the number of leading 1 bits — appended to the address with a slash: 192.168.1.50/24 means the same thing as the IP + 255.255.255.0 mask worked out above.1
| CIDR | Subnet Mask | Usable Hosts |
|---|---|---|
/8 |
255.0.0.0 |
~16.7 million |
/16 |
255.255.0.0 |
~65,000 |
/24 |
255.255.255.0 |
254 |
/30 |
255.255.255.252 |
2 (common for point-to-point links) |
Table 1. Common CIDR Blocks
CIDR replaced an older, rigid classful addressing scheme (Class A/B/C, each with a fixed-size network portion) — the fixed sizes wasted huge numbers of addresses whenever a network's real needs didn't match one of the three fixed boundaries. CIDR lets that boundary fall anywhere, and its more granular sibling, VLSM (Variable Length Subnet Masking), lets a single larger network be subdivided into differently-sized subnets as needed, rather than every subnet being forced to the same size.
Default Gateway¶
The default gateway is the router a device sends traffic to whenever the destination address isn't on its own local subnet — it's the "way out" of the local network toward everything else.
A typical entry looks like:
This says: for anything not matched by a more specific route, send it to 192.168.1.1 (the gateway/router), which is then responsible for forwarding it further along toward its actual destination.
Private vs. Public IP¶
Every IP address is either private (only meaningful inside one local network, never routed on the public internet) or public (globally unique and directly reachable across the internet).
| Private | Public | |
|---|---|---|
| Uniqueness | Only unique within its local network | Globally unique |
| Routable on the internet | No | Yes |
| Assigned by | The local network administrator/router | An ISP or regional internet registry |
| Typical use | Home/office LANs, internal servers | Internet-facing servers, the address your ISP gives your router |
Table 2. Private vs. Public IP
Private ranges are reserved by RFC 1918 specifically so they can be reused independently inside any number of separate networks without ever conflicting — your home router's 192.168.1.x network and your neighbor's are both valid and don't clash, because neither is ever routed onto the public internet directly. NAT (Network Address Translation) is the mechanism that lets an entire private network share one public IP when talking to the outside world, translating addresses at the boundary between the two.
IPv4¶
Address Format¶
A 32-bit address, written as four octets (0–255 each) separated by dots: 192.168.1.1. Historically, addresses were divided into fixed classes (A, B, C, D, E) based on their leading bits — Class A for huge networks, C for small ones — but this scheme was abandoned decades ago in favor of CIDR, which lets the network/host split fall anywhere, not just at fixed class boundaries.1
Special Address Ranges¶
| Range | Purpose |
|---|---|
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 |
Private addresses (RFC 1918) — never routed on the public internet2 |
127.0.0.0/8 |
Loopback — traffic to yourself (127.0.0.1 is the classic one) |
169.254.0.0/16 |
Link-local (APIPA) — self-assigned when DHCP fails |
224.0.0.0/4 |
Multicast |
255.255.255.255 |
Limited broadcast — every host on the local segment |
Table 3. Special IPv4 Address Ranges
The Exhaustion Problem¶
32 bits gives roughly 4.3 billion possible addresses — which sounded enormous in the 1980s and has been effectively exhausted for years. Two things kept IPv4 alive well past that point:
- CIDR — replacing rigid address classes with flexible subnet boundaries, so addresses aren't wasted on oversized blocks
- NAT — letting an entire private network share a single public IP, translating addresses at the boundary
Both are effective, but neither is a permanent fix — they're exactly why IPv6 exists.
IPv6¶
Address Format¶
A 128-bit address, written as eight groups of four hex digits, separated by colons: 2001:0db8:85a3:0000:0000:8a2e:0370:7334. Two shorthand rules make these actually writable:3
- Leading zeros in a group can be dropped:
0db8→db8 - One run of consecutive all-zero groups can be collapsed to
::(only once per address, or it becomes ambiguous)
So the address above compresses to: 2001:db8:85a3::8a2e:370:7334
Compression walkthrough
2001:0db8:0000:0000:0000:0000:1428:57ab compresses in two steps:
- Drop leading zeros per group:
2001:db8:0:0:0:0:1428:57ab - Collapse the run of four zero groups:
2001:db8::1428:57ab
Special Address Ranges¶
| Range | Purpose |
|---|---|
::1/128 |
Loopback (IPv6's equivalent of 127.0.0.1) |
fe80::/10 |
Link-local — every IPv6 interface gets one automatically, used for on-link operations like discovery |
fc00::/7 |
Unique Local Address (ULA) — the IPv6 equivalent of RFC 1918 private ranges4 |
2000::/3 |
Global unicast — the actual publicly-routable space |
ff00::/8 |
Multicast |
Table 4. Special IPv6 Address Ranges
There is no broadcast in IPv6
IPv6 removed broadcast entirely — everything that used to be a broadcast in IPv4 (like ARP requests) is now multicast instead, sent only to interested listeners rather than to every host on the segment.
SLAAC: Automatic Addressing Without DHCP¶
IPv6 introduced SLAAC (Stateless Address Autoconfiguration) — a device can construct its own address without a DHCP server at all, by combining a network prefix announced by the local router with an interface identifier it derives itself (traditionally from its MAC address, via EUI-64).5 DHCPv6 still exists for networks that want centralized control, but SLAAC means IPv6 doesn't strictly need it the way IPv4 needs DHCP.
IPv4 vs. IPv6 at a Glance¶
| IPv4 | IPv6 | |
|---|---|---|
| Address length | 32 bits | 128 bits |
| Written as | Dotted decimal | Colon-separated hex |
| Header | Variable length (20–60 bytes) | Fixed 40 bytes |
| Broadcast | Yes | No — multicast only |
| NAT | Common, often necessary | Generally unnecessary |
| Auto-configuration | DHCP only | DHCPv6 or SLAAC |
| Fragmentation | Can happen at any router | Only at the source; routers rely on Path MTU Discovery |
Table 5. IPv4 vs. IPv6 Comparison
Dual Stack¶
Almost every modern OS runs dual stack: both IPv4 and IPv6 active on the same interface at the same time, with the OS deciding per-connection which one to use (commonly preferring IPv6 when both are available and working). This is the dominant real-world transition strategy; full IPv6-only networks and translation mechanisms (NAT64, 464XLAT) exist but are far less common on typical systems.
Checking IP Configuration on Linux¶
ip -4 addr show # show only IPv4 addresses
ip -6 addr show # show only IPv6 addresses
ip addr show # show both
ping -4 example.com # force IPv4
ping -6 example.com # force IPv6
ip -6 route show # IPv6 routing table
Useful Resources¶
- IETF — RFC 1518: An Architecture for IP Address Allocation with CIDR
- IETF — RFC 1918: Address Allocation for Private Internets
- IETF — RFC 4291: IP Version 6 Addressing Architecture
- IETF — RFC 4193: Unique Local IPv6 Unicast Addresses
- IETF — RFC 4862: IPv6 Stateless Address Autoconfiguration
-
IETF. (1993). Classless Inter-Domain Routing (CIDR): An address assignment and aggregation strategy (RFC 1519). https://www.rfc-editor.org/rfc/rfc1519 ↩↩
-
Rekhter, Y., Moskowitz, B., Karrenberg, D., de Groot, G. J., & Lear, E. (1996). Address allocation for private internets (RFC 1918). IETF. https://www.rfc-editor.org/rfc/rfc1918 ↩
-
Hinden, R., & Deering, S. (2006). IP version 6 addressing architecture (RFC 4291). IETF. https://www.rfc-editor.org/rfc/rfc4291 ↩
-
Hinden, R., & Haberman, B. (2005). Unique local IPv6 unicast addresses (RFC 4193). IETF. https://www.rfc-editor.org/rfc/rfc4193 ↩
-
Narten, T., Draves, R., & Krishnan, S. (2007). IPv6 stateless address autoconfiguration (RFC 4862). IETF. https://www.rfc-editor.org/rfc/rfc4862 ↩