Script Valley
HTTP & The Web: How It Actually Works
How the Internet Moves DataLesson 1.5

IP addresses, ports, and sockets explained

IPv4 vs IPv6, public vs private IP, NAT, ports 0-65535, well-known ports, socket definition, socket pair uniqueness

IPs, Ports, and Sockets

Socket connection IP and port diagram

A socket is the combination of an IP address and a port number. It is the actual endpoint of a network connection โ€” not a URL, not a hostname.

IP addresses

IPv4 addresses are 32-bit numbers written as four octets: 192.168.1.1. About 4.3 billion possible addresses โ€” exhausted in 2011. IPv6 uses 128-bit addresses: 2001:0db8::1, solving the shortage with a virtually unlimited address space.

Private IP ranges (RFC 1918) are not routable on the public internet:

10.0.0.0/8       # Large private networks
172.16.0.0/12    # Medium private networks
192.168.0.0/16   # Home/office networks (your router)

NAT (Network Address Translation) maps many private IPs to one public IP. That is why your laptop has 192.168.x.x but the server sees your router's public IP.

Ports

Ports 0โ€“1023 are well-known (reserved by IANA):

  • 80 โ€” HTTP
  • 443 โ€” HTTPS
  • 22 โ€” SSH
  • 53 โ€” DNS

Ports 1024โ€“49151 are registered for specific applications. Ports 49152โ€“65535 are ephemeral โ€” the OS picks one randomly for the client side of outgoing connections. That random client port is what makes each connection unique.

Sockets

A TCP connection is uniquely identified by four values: (client IP, client port, server IP, server port). This is why one server IP on port 443 can handle thousands of simultaneous connections โ€” the client-side ephemeral port differs every time.

# Inspect active sockets on Linux/macOS
ss -tnp
# or
netstat -an | grep ESTABLISHED
IP addresses, ports, and sockets explained โ€” How the Internet Moves Data โ€” HTTP & The Web: How It Actually Works โ€” Script Valley โ€” Script Valley