01 / 22

IP Addressing
& Routing

Understand how devices find each other on the internet using IP addresses, subnets, and routing protocols.

Cyber Security

What Is an IP Address?

An IP address (Internet Protocol address) is a unique numerical label assigned to every device connected to a network. Think of it as a home address for your computer: it tells the network where to deliver data.

The IPv4 Address Structure

An IPv4 address consists of 4 octets (groups of 8 bits), separated by dots. Each octet ranges from \(0\) to \(255\), giving a total of \(2^{32}\) possible addresses.

192 168 1 10 . . . Network Portion (24 bits) Host Portion (8 bits) 8 bits 8 bits 8 bits 8 bits
Total: 32 bits (\(2^{32}\) addresses)

Why IP Addressing Matters

Identification
Every device gets a unique address, preventing confusion about where data should go.
Routing
Routers use IP addresses to decide the best path for data packets across networks.
Security
Firewalls filter traffic by IP address, blocking unauthorized access to your network.

Understanding Subnets

A subnet (subnetwork) divides a larger network into smaller, more manageable segments. A subnet mask determines which bits of the IP address represent the network vs. the host.

Large Network: 192.168.0.0/16 Subnet A 192.168.1.0/24 Subnet B 192.168.2.0/24 Router A router connects subnets together

The Subnet Mask

A subnet mask is a \(32\)-bit number that separates the network portion from the host portion. A /24 mask means the first \(24\) bits are the network, leaving \(8\) bits for hosts.

IP Address: 192 . 168 . 1 . 10 Subnet Mask: 255 . 255 . 255 . 0 Binary: 11111111.11111111.11111111 .00000000 /24 Network (24 bits) Host (8 bits)

IPv4 vs IPv6

IPv4 IPv6
Address Size 32 bits 128 bits
Format Dotted decimal (192.168.1.1) Hex with colons (2001:db8::1)
Total Addresses \(2^{32} \approx 4.3 \times 10^9\) \(2^{128} \approx 3.4 \times 10^{38}\)
Security Optional (IPsec add-on) Built-in IPsec support
Status Addresses exhausted Expanding adoption

Public vs Private IP Addresses

Public IP
Globally unique, assigned by ISPs. Used to communicate across the internet. Example: 203.0.113.5
Private IP
Used only within local networks. Not routable on the internet. Example: 192.168.1.10

How Routing Works

Routing is the process of selecting the best path for data packets to travel from source to destination across interconnected networks. Routers examine the destination IP and consult their routing table.

Source 192.168.1.10 Router A Router B Router C Destination 10.0.2.50 Best path Alternative path Hop 1 Hop 2 Hop 3

The Routing Table

Every router maintains a routing table: a map that lists known network destinations and the best next hop (next router) to reach each one.

Destination Network Subnet Mask Next Hop Interface
192.168.1.0 /24 Direct eth0
10.0.2.0 /24 192.168.1.1 eth1
0.0.0.0 /0 203.0.113.1 eth2

Static vs Dynamic Routing

Static Routing
Routes manually configured by an administrator. Simple but does not adapt to network changes automatically.
Dynamic Routing
Routers share information using protocols (OSPF, BGP, RIP). Automatically adapts when links fail or new paths appear.

How to Calculate a Subnet

1
Identify the CIDR notation. For example, /24 means 24 network bits.
2
Calculate host bits: \(32 - \text{prefix length}\). For /24: \(32 - 24 = 8\) host bits.
3
Count usable hosts: \(2^{\text{host bits}} - 2\). For /24: \(2^8 - 2 = 254\) hosts.
4
Find the network address (all host bits = 0) and broadcast address (all host bits = 1).
5
The usable range is from network address + 1 to broadcast address - 1.

Example 1: A /24 Subnet

Given the address 192.168.5.0/24, find the usable host range and total number of hosts.

1
Prefix length: /24, so host bits = \(32 - 24 = 8\)
2
Usable hosts: \(2^8 - 2 = \) 254
3
Network address: 192.168.5.0
4
Broadcast address: 192.168.5.255
5
Usable range: 192.168.5.1 to 192.168.5.254

Example 2: A /26 Subnet

Given the address 10.0.0.0/26, how many usable hosts and what is the range?

1
Host bits: \(32 - 26 = 6\)
2
Usable hosts: \(2^6 - 2 = \) 62
3
Network address: 10.0.0.0
4
Broadcast address: 10.0.0.63 (since \(2^6 = 64\), range is 0 to 63)
5
Usable range: 10.0.0.1 to 10.0.0.62

Example 3: Packet Routing in Action

A device at 192.168.1.10 wants to reach 10.0.2.50. Trace the packet's journey:

Step 1: Source 192.168.1.10 Not on same subnet Step 2: Gateway 192.168.1.1 Checks routing table Step 3: Next Hop 10.0.0.1 Forwards to 10.0.2.x Step 4: Delivered 10.0.2.50 Packet arrives! Each router makes an independent forwarding decision

Common Mistakes

✕ Forgetting to Subtract 2
When counting usable hosts, always subtract 2 from \(2^n\): one for the network address and one for the broadcast address.
✕ Confusing Public and Private
Private IPs (192.168.x.x, 10.x.x.x) cannot be routed on the internet. Sending traffic without NAT will fail silently.
✕ Wrong Subnet Boundary
A /26 gives blocks of 64, not 26. The second subnet starts at .64, not .27. Always compute \(2^{\text{host bits}}\) for the block size.

Summary: Key Concepts

Concept What It Does Example
IP Address Unique device identifier 192.168.1.10
Subnet Mask Separates network from host 255.255.255.0 (/24)
Default Gateway Router to exit local network 192.168.1.1
Routing Table Maps destinations to next hops 0.0.0.0/0 → ISP router
NAT Shares one public IP for many Home router

Question 1 of 5

How many usable host addresses are available in a /24 subnet?

Question 2 of 5

Which of the following is a private IP address range?

Question 3 of 5

What does a router use to decide where to send a packet?

Question 4 of 5

Given the subnet 10.0.0.0/26, what is the broadcast address?

Question 5 of 5

What is the primary advantage of IPv6 over IPv4?