# IP Addressing, Subnetting and Routing

> Work with IPv4 and IPv6 addresses, CIDR and subnet masks, private ranges and NAT, DHCP, and the basics of how routers choose paths. Free notes, key concepts,...

Canonical: https://www.internhack.in/roadmaps/tracks/cs-fundamentals/ip-addressing-routing
Last updated: 2026-11-28

Work with IPv4 and IPv6 addresses, CIDR and subnet masks, private ranges and NAT, DHCP, and the basics of how routers choose paths.

Intermediate · about 5 hours · difficulty 3/5

Learn first: [How the Internet Works: OSI and TCP/IP](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/network-models)

The network layer gets packets from one machine to any other machine on the internet. Subnetting numericals are standard in aptitude-style CS tests, and NAT and DHCP explain everyday networking behaviour.

### IPv4 and CIDR

- An IPv4 address is 32 bits, written as four octets (`192.168.1.10`).
- **CIDR notation** `/24` means the first 24 bits are the network part. A /24 has 256 addresses, 254 usable hosts (network and broadcast addresses are reserved).
- **Subnetting**: borrowing host bits to split a network. Practise questions like "divide 10.0.0.0/24 into 4 subnets" (four /26 blocks of 64) and "which subnet does this IP belong to" by ANDing with the mask.
- Classful addressing (A, B, C) is legacy but still appears in some tests.

### Private addresses and NAT

- Private ranges: `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`. They are not routable on the public internet.
- **NAT** lets many private devices share one public IP by rewriting addresses and ports at the router. It is why your laptop's IP is different from what websites see.
- **DHCP** hands out IP, subnet mask, gateway and DNS server automatically (Discover, Offer, Request, Acknowledge).

### IPv6

128-bit addresses written in hex, no need for NAT, simplified header. Know the shorthand (`::`) and why IPv6 exists (IPv4 exhaustion).

### Routing

- Routers forward using a **routing table** and **longest prefix match**.
- Interior routing: distance vector (RIP, Bellman-Ford based) vs link state (OSPF, Dijkstra based). You already know both algorithms from graphs.
- **BGP** connects autonomous systems across the internet (optional depth).
- **ICMP** powers `ping` and `traceroute` via TTL expiry.

Good enough to move on: you can compute network address, broadcast address and host range for any IP and prefix, and explain NAT to a friend.

## Key concepts

- **IPv4 structure and CIDR**
- **Subnet masks and subnetting numericals**
- **Private ranges and NAT**
- **DHCP**
- **IPv6 basics**
- **Routing tables and longest prefix match**
- **RIP vs OSPF**
- **ICMP, ping and traceroute**
- **BGP overview**

## Mini project

Write a subnet calculator CLI that takes an IP in CIDR notation and prints the network address, broadcast address, usable host range and host count, and can split a block into N equal subnets. Verify a few outputs with traceroute and ipconfig/ip addr on your machine.

## Check yourself

How many usable hosts does 172.16.5.0/27 have, what is its broadcast address, and does 172.16.5.40 belong to it?

## Free resources

- [Cloudflare Learning Center: What is a subnet?](https://www.cloudflare.com/learning/network-layer/what-is-a-subnet/) (Cloudflare)
- [Cloudflare Learning Center: What is NAT?](https://www.cloudflare.com/learning/network-layer/what-is-nat/) (Cloudflare)
- [Kurose and Ross: Network layer resources](https://gaia.cs.umass.edu/kurose_ross/index.php) (Kurose and Ross)

Previous: [How the Internet Works: OSI and TCP/IP](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/network-models) · Next: [Transport Layer: TCP and UDP](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/tcp-and-udp)

## More in Computer Networks

- [How the Internet Works: OSI and TCP/IP](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/network-models)
- [IP Addressing, Subnetting and Routing](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/ip-addressing-routing)
- [Transport Layer: TCP and UDP](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/tcp-and-udp)
- [DNS](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/dns)
- [HTTP, HTTPS and TLS](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/http-and-https)
- [Network Security Essentials](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/network-security-basics)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [CS Fundamentals and Placement Prep Roadmap](https://www.internhack.in/roadmaps/tracks/cs-fundamentals)
