Learning paths / Cloud foundations / IP addresses and ports

IP addresses and how packets find their way

Reading · 5 min · Module 4, lesson 1 of 420 min left in this module

Module 4 · IP addresses and portsLesson 1 of 4

Goal: Read an IP address, tell a public address from a private one, and explain how a packet reaches a server it has never met.

Addresses and ports at a glance

IP address
Finds one machine on a network.
Private address
Works inside one network only.
Port
Finds one program on that machine.
Listen address
127.0.0.1 answers only itself; 0.0.0.0 answers everyone.
An address finds the machine, a port finds the program, and where your app listens decides who can reach it.

Key idea

Every machine on a network has an IP address. Data travels in small packets, each labelled with where it's going and where it came from, and routers pass each one a step closer until it arrives.

DNS, the next module, turns a name like example.com into one of these numbers. This module is about what happens with the number.

What an address looks like

There are two versions in use side by side:

  • IPv4: four numbers from 0 to 255, like 203.0.113.10. There are only about four billion of them, which isn't enough for everything online.
  • IPv6: eight groups of hexadecimal, like 2001:db8::10, where :: stands for a run of zeros. There are enough for every device many times over.

A server often has both, and a browser uses whichever works.

Public and private addresses

Some IPv4 ranges are reserved for private networks: 10.x.x.x, 172.16.x.x to 172.31.x.x, and 192.168.x.x. Routers on the internet won't carry packets to them, so the same private address can exist in millions of homes and data centres at once.

Your laptop almost certainly has one. Your router has a single public address and shares it: it rewrites outgoing packets to carry its own address, and hands each reply back to the right device. That trick is called NAT.

Try it: find your laptop's address.

ipconfig getifaddr en0

en0 is Wi-Fi on most Macs.

If it starts with 10., 172.16–172.31 or 192.168., it's private.

How a packet finds its way

A request is cut into packets, and your computer hands each one to your router, which passes it to your provider's router, and so on. No router knows the whole route: each only knows which neighbour is closer to the destination. A trip across the world is often 10 to 20 of these hops.

Packets can arrive out of order, or not at all. TCP, the protocol most web traffic rides on, numbers them, puts them back in order, and resends any that went missing, so your app sees one clean stream. The reply makes the same kind of trip back, to the source address on the packets.

Seeing the hops yourself

traceroute example.com on macOS and Linux, or tracert example.com on Windows, lists each router a packet passes through. Some routers don't answer and show as *; that's normal.

Check yourself

Your laptop's address is 192.168.1.23. A website logs the address your request came from. What does it see?