c2cedge
LibraryCS Fundamentals › Ch 12
CS Fundamentals · C — Computer Networks

IP Addressing & Subnetting

Every device on a network needs an address. IPv4 classes, private ranges and basic subnetting are bread-and-butter interview questions.

Test weight: HighAsked by: TCS, Infosys, Wipro, networking rolesDifficulty: Medium

An IP address identifies a device on a network. IPv4 uses 32 bits written as four octets (e.g. 192.168.1.10); IPv6 uses 128 bits to solve address exhaustion. An address splits into a network part and a host part, and a subnet mask says where that split is.

Network vs host & the subnet mask

The subnet mask (e.g. 255.255.255.0, or /24) marks which bits are the network and which are the host. Devices on the same network share the same network part. Subnetting borrows host bits to create more, smaller networks.

Key facts to memorise

  • IPv4 = 32 bits (4 octets); IPv6 = 128 bits.
  • Private ranges: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 — not routable on the public internet.
  • A /24 network has 256 addresses, but only 254 usable hosts (network and broadcast are reserved).
  • Loopback is 127.0.0.1; 0.0.0.0 means 'any/unspecified'.
⚡ The edge
  • For a /n network, usable hosts = 2^(32−n) − 2 (subtracting the network and broadcast addresses). A /24 gives 2^8 − 2 = 254.
  • Private IPs need NAT to reach the internet — NAT translates many private addresses to one public address, which is also why IPv4 has survived address exhaustion.
Worked example
'How many usable host addresses are in a /26 network?'
  1. A /26 leaves 32 − 26 = 6 host bits.
  2. Total addresses = 2^6 = 64.
  3. Subtract the network and broadcast addresses: 64 − 2 = 62 usable hosts.
Worked example
'Why do we have private IP addresses and NAT?'
  1. IPv4 has only ~4.3 billion addresses, far fewer than the world's devices.
  2. Private ranges let countless internal networks reuse the same addresses behind a router.
  3. NAT maps those private addresses to a shared public address, conserving public IPs and adding a layer of isolation.
⚠ Watch out
  • Usable hosts is 2^(host bits) minus 2 (network + broadcast), not the full count.
  • Private addresses are not routable on the public internet — they require NAT.
  • Don't confuse the subnet mask (network/host split) with the gateway (the router's address).
Practice this — take a timed mock →
1,300+ questions, scored, with a weak-area report.
Know who's ready. Not who finished.
HomeLibraryPrivacyTerms