Difficulty: Beginner
Explain IPv4 addressing and the classful scheme (Class A to E). What are private IP ranges and special addresses?
IPv4 addressing is the bread and butter of networking interviews, and TCS and Infosys love asking for class ranges. Let's do it properly and also explain why classes were abandoned, because that is the part that shows understanding.
An IPv4 address is 32 bits, written as four decimal octets like 192.168.1.10. It has a network portion and a host portion. In the original classful design, the class was decided by the leading bits of the first octet. Class A starts with binary 0, so the first octet is 1 to 126, with a default mask of 255.0.0.0 (/8), giving 126 networks and about 16.7 million hosts each. Class B starts with 10, first octet 128 to 191, mask 255.255.0.0 (/16), 16384 networks, 65534 hosts each. Class C starts with 110, first octet 192 to 223, mask 255.255.255.0 (/24), about 2 million networks, 254 hosts each. Class D starts with 1110, 224 to 239, and is multicast. Class E is 240 to 255, reserved for experiments.
Why was 127 skipped in Class A? Because 127.0.0.0/8 is reserved for loopback; 127.0.0.1 is localhost, traffic that never leaves your machine. Hosts per network are always 2^n minus 2, because the all-zeros host part is the network address and the all-ones host part is the directed broadcast address.
The classful scheme wasted enormous amounts of space. A company needing 1000 addresses was too big for Class C and got a Class B with 65534, wasting 64000. This is why we moved to CIDR in 1993, which lets the prefix be any length, and which is covered in the subnetting question. Today classes are mostly history, but the names still appear in exams and interviews.
Private address ranges from RFC 1918 are not routable on the public internet and are reused by every home and office: 10.0.0.0/8, 172.16.0.0/12 (172.16.0.0 to 172.31.255.255), and 192.168.0.0/16. Devices using them reach the internet via NAT. Interviewers like to check the middle one; note that 172.32.x.x is public.
Other special addresses worth knowing: 0.0.0.0 means this host or any address depending on context (a server binding to 0.0.0.0 listens on all interfaces); 255.255.255.255 is the limited broadcast; 169.254.0.0/16 is link-local (APIPA), which is what Windows assigns when DHCP fails, so seeing a 169.254 address is a sign your DHCP server was unreachable; 100.64.0.0/10 is carrier-grade NAT space. A quick way to classify: look at the first octet only, so 172.20.5.9 is Class B and private, 10.5.5.5 is Class A and private, 200.1.1.1 is Class C and public.
Address: 172.20.5.9
First octet 172 -> in 128..191 -> Class B
Default mask: 255.255.0.0 (/16)
Network: 172.20.0.0
Broadcast: 172.20.255.255
Usable hosts: 2^16 - 2 = 65534
Private? 172.16.0.0 - 172.31.255.255 -> yes
Same steps work for any address under the classful view.
IPv4, Classful Addressing, Private IP, Loopback, Broadcast