IP Addresses & Routing
Computer Networking Basics · Networking & Cryptography track
4 min read
In this module
Finding a Computer on the Internet
When you send data across a network, it needs an address - just like a letter needs a street address. The Internet Protocol (IP) provides this addressing system and defines how packets are routed from source to destination.
IPv4 Addresses
An IPv4 address is a 32-bit number, usually written as four decimal octets: 192.168.1.1. Each octet is 8 bits (0-255), giving roughly 4.3 billion possible addresses. That sounded like plenty in the 1980s, but the modern internet has long since outgrown it.
That example address is a private one. Three ranges, 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16, are reserved for local networks and never routed on the public internet (RFC 1918). Your home router hands them out to your devices and uses NAT (network address translation) to share its single public address among them, which is one of the ways IPv4 has stretched past its 4.3 billion limit.
A subnet is a logical subdivision of an IP network. It groups nearby devices together so that local traffic stays local and only messages destined for other networks get forwarded to a router. A subnet mask (like 255.255.255.0) tells a device which part of the address identifies the network and which part identifies the host.
Worked example: /24 and /26
The /n notation counts how many leading bits of the mask are 1s. A /24 mask is 255.255.255.0, so for 192.168.1.0/24 the first three octets name the network and the last octet names the host:
| /24 | /26 | |
|---|---|---|
| Mask | 255.255.255.0 | 255.255.255.192 |
| Last octet of mask in binary | 00000000 | 11000000 |
Network containing .130 | 192.168.1.0 | 192.168.1.128 |
| Broadcast | 192.168.1.255 | 192.168.1.191 |
| Usable hosts | .1 to .254 (254) | .129 to .190 (62) |
A /26 borrows two more bits for the network, which splits the old /24 into four blocks of 64 addresses: .0, .64, .128 and .192.
So are 192.168.1.130 and 192.168.1.20 on the same subnet under /26? The first three octets match, so only the top two bits of the last octet decide it. The bits below start at 130; toggle them to 20 (00010100) and compare the two leftmost bits.
130 starts 10 and 20 starts 00, so they're in different /26 blocks and a packet between them has to go through a router. Under /24 they'd be neighbours.
IPv6: Room to Grow
IPv6 extends addresses to 128 bits, written as eight groups of four hexadecimal digits (e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334). This provides an astronomically large address space - enough to assign a unique address to every grain of sand on Earth many times over. Adoption has been gradual, but IPv6 is increasingly the default on modern networks.
How Routing Works
Your data doesn't travel directly to its destination. It hops through a chain of routers — devices that look at the destination IP in each packet and forward it one step closer. Each router has a routing table: roughly, "for addresses in this range, send the packet out this interface."
No single router knows the full path. Each one makes a local call about the next hop, and the packet gradually converges on its destination. When several table entries match, the router picks the most specific one, the longest prefix:
The addresses are from a block reserved for documentation, so the routers are made up but the matching rule is the real one.
Because every router decides on its own, the internet is obstinate about staying up — if one path dies, routers find another.
DNS: Names for Humans
People remember names, not numbers. The Domain Name System (DNS) translates human-friendly names like example.com into IP addresses like 203.0.113.10 (an address reserved for documentation; real sites' addresses change over time). When you type a URL into your browser, the first thing that happens - before any web page loads - is a DNS lookup to find the IP address of the server you want to reach.
DNS itself is a distributed database spread across thousands of servers worldwide, organised in a hierarchy. Root servers point to the servers for each top-level domain such as .com, and those point to each domain's authoritative servers, which hold the actual records. Your computer doesn't walk that chain itself: it asks a recursive resolver (usually your ISP's, or a public one), which does the walking and caches each answer for as long as the record's TTL allows.