Textbook language

IPv4, classful model, CIDR, and subnet calculation

We will analyze how a 32-bit IPv4 address is divided into network and host parts. In the simulators, you can calculate the range, compare two hosts, verify a mask, and distribute one address block among several subnets.

IPv4 structure, bitwise formulas, and Horner's method

Address IPv4 — is 32 bits (4 bytes = 4 octets, each from 0 to 255). A notation with an octet like 212.260.9.11 is invalid because 260 does not fit into 8 bits! The integer 32-bit representation of an address can be calculated via Horner's scheme:

IP32 = (((A · 256) + B) · 256 + C) · 256 + D
Network address = IP AND Mask | Broadcast = Network OR (NOT Mask) | Hosts = 232 − p − 2
  • Why do we subtract 2? The very first subnet address (all host bits = 0) denotes the network itself, and the last one (all host bits = 1) is the broadcast address broadcast. They cannot be assigned to regular hosts.
  • Exceptions: /31 /31 (RFC 3021) — two addresses for a direct point-to-point link without broadcast; /32 /32 — a route to one specific node.

Valid subnet masks and CIDR

In a correct 32-bit mask, there are first consecutive ones (network part, prefix length /p), then consecutive zeros (host part). Therefore, each mask octet can take exactly one of 9 values:

0 (00000000) · 128 (10000000) · 192 (11000000) · 224 (11100000) · 240 (11110000)
248 (11111000) · 252 (11111100) · 254 (11111110) · 255 (11111111)
Mask check: mask 255.255.250.0 is invalid (250 = 111110102 — a 0 appeared inside the ones!); mask 255.254.128.0 is also invalid (zeros already started in the 2nd octet, so the 3rd octet must be 0) 0!).

CIDR (Classless Inter-Domain Routing) allows shifting the boundary to any bit, not just by octets (/8, /16, /24). For example, for ≥ 4000 hosts, we take 12 host bits (212^12 - 2 = 4094) → prefix /20 /20 (255.255.240.0).

Historical IPv4 classes and checking "are they in the same subnet?"

ClassLeading bits1st octetNetworks / MaskHosts in network
A0...1–126 (0 and 127 are special)126 networks · /8224 − 2 = 16 777 214
B10...128–19116,384 networks · /16216 − 2 = 65 534
C110...192–2232,097,152 networks · /2428 − 2 = 254
D1110...224–239—Multicast
E1111...240–255—Reserved (experiments)
When to use: classes help read old materials. In current IP configuration, the network boundary is determined by the actual interface prefix or route entries.

Special, private (RFC 1918) addresses and a look at IPv6

Range / AddressName and role
10.0.0.0/8 · 172.16.0.0/12 · 192.168.0.0/16Private (Private, RFC 1918) — local networks, not routed on the public Internet (exit via NAT)
127.0.0.0/8 (usually 127.0.0.1)Loopback — loopback inside the device itself for testing the stack and local services
169.254.0.0/16Link-Local (APIPA, RFC 3927) — auto-configuration in Windows, macOS, and Linux if the DHCP server does not respond
100.64.0.0/10CGNAT (RFC 6598) — provider's shared address space for carrier-grade NAT (between the client and the public Internet)
224.0.0.0/4 (224.0.0.0–239.255.255.255)Multicast — delivery to a group of subscribed recipients
255.255.255.255Limited broadcast — to all nodes in the local segment, never goes beyond the router
0.0.0.0 / 0.0.0.0/0Unspecified address (or "all interfaces") / default route
Why IPv6 appeared: ~4.3 billion IPv4 addresses (232^32) are exhausted. IPv6 IPv6 uses 128 bits (8 groups of 4 hex digits, for example 2001:db8::1; ::1 — loopback, fe80::/10 — link-local, 2000::/3 2001:db8::/32 — global addresses), supports autoconfiguration SLAAC, simplifies the header and eliminates the need for mandatory NAT.