IPv4 CIDR Subnetting & Linux File Permissions Architecture
Efficient network routing and operating system security are foundational pillars of internet infrastructure. Understanding how 32-bit IPv4 addresses are partitioned via Classless Inter-Domain Routing (CIDR, RFC 4632) and how POSIX file systems regulate access through octal chmod bitmasks is essential for every systems and backend engineer.
1. The Mathematics of IPv4 Subnetting
An IPv4 address consists of 32 binary bits divided into four 8-bit octets. A subnet mask separates the network portion of the address from the host portion. Using bitwise operations:
- Network Address: Calculated via bitwise AND between the IP and the Subnet Mask:
Network Address = IP & Netmask - Broadcast Address: Calculated by setting all host bits to 1 (bitwise OR with inverted wildcard mask):
Broadcast Address = Network Address | (~Netmask) - Total Host Capacity: With a prefix length of $n$ bits, there are $32 - n$ host bits. The total count of IP addresses in the subnet is $2^{32-n}$. Under standard conventions, 2 addresses are reserved (the network identifier and the broadcast address), yielding $2^{32-n} - 2$ usable host addresses.
2. Special Subnet Exceptions: /31 and /32
- Point-to-Point Links (/31, RFC 3021): In modern router-to-router point-to-point connections, reserving network and broadcast addresses wastes 50% of available IPs. RFC 3021 standardizes /31 subnets where both addresses are fully usable for the two connected interfaces.
- Host Route (/32): A /32 prefix has 0 host bits, representing a single specific machine (such as a loopback interface or VPC Elastic IP).
3. Private IPv4 Address Ranges (RFC 1918)
To preserve public IPv4 space, RFC 1918 designates three private address blocks that are never routed on the public internet:
10.0.0.0/8(10.0.0.0 – 10.255.255.255): 16,777,216 addresses (Enterprise intranets)172.16.0.0/12(172.16.0.0 – 172.31.255.255): 1,048,576 addresses (Cloud VPCs & containers)192.168.0.0/16(192.168.0.0 – 192.168.255.255): 65,536 addresses (Home & office LANs)
4. Linux File Permissions & Octal Chmod Mechanics
POSIX file permissions utilize a 3-tier access model: User (Owner), Group, and Others (World). Each role has three independent permission bits:
- Read (r = 4 / binary 100₂): Grants permission to open and read file contents or list directory entries.
- Write (w = 2 / binary 010₂): Grants permission to modify file contents or add/delete entries in a directory.
- Execute (x = 1 / binary 001₂): Grants permission to execute binary programs/scripts or enter (cd into) a directory.
By summing the bit values for each category, permissions are concisely represented as a 3-digit octal number (e.g. User 4+2+1=7, Group 4+0+1=5, Others 4+0+1=5 yields 755 / -rwxr-xr-x).
5. Frequently Asked Questions (FAQ)
- Why does SSH reject my private key with "Permissions 0644 are too open"?
- OpenSSH enforces strict security requirements on private identity files. A permission of
644permits other local accounts to read your private key. You must restrict access exclusively to the owner usingchmod 600 ~/.ssh/id_rsa. - What is a Wildcard Mask used for?
- A wildcard mask is the exact bitwise inversion of a subnet mask (e.g.
255.255.255.0netmask corresponds to0.0.0.255wildcard). It is primarily used in Cisco IOS Access Control Lists (ACLs) and OSPF routing configurations where a0bit indicates "must match" and a1bit indicates "ignore". - Are my subnet queries or IP addresses logged?
- No. All bitwise calculations, octal transformations, and binary string generations run 100% locally within your browser's JavaScript engine. No network requests are made.