IP address structure
An IP address identifies a device on a network. IPv4 uses 32 bits split into four octets
(0-255 each), separated by dots: 192.168.1.1. IPv6 uses 128 bits grouped
into eight 16-bit blocks separated by colons:
2001:0db8:85a3:0000:0000:8a2e:0370:7334. The compact form drops leading
zeros and uses :: for consecutive zero groups.
IPv4 has capacity for ~4.3 billion unique addresses, almost all already assigned. IPv6 has 340 undecillion — enough for every atom on Earth several times over.
Special ranges worth knowing
- 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16: private networks (RFC 1918). Not routable on the public internet.
- 127.0.0.0/8: loopback.
127.0.0.1always points at the same device. - 169.254.0.0/16: link-local. Auto-assigned when a device fails to get an IP via DHCP.
- 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24: reserved for documentation (TEST-NET-1, 2, 3). RFC 5737.
- 224.0.0.0/4: multicast.
- 255.255.255.255: limited broadcast.
- ::1/128: IPv6 equivalent of 127.0.0.1.
- 2001:db8::/32: IPv6 documentation range. RFC 3849.
When to use each type
- Random public. For fixtures where realism matters (logs, geolocation, analytics). Caution: every public IP belongs to someone.
- Private (RFC 1918). For internal network configurations, test networks, firewall examples.
- Documentation (TEST-NET). When you need realistic-looking public IPs guaranteed to be unassigned. Recommended for public docs.
- Loopback. For local tests where the host is always the same device.
IP geolocation
Services like MaxMind, IP2Location and IPinfo associate IP ranges with countries, regions and sometimes cities. The mapping is probabilistic: an IP may show up in one country but the user is in another (VPN, proxy, mobile with foreign SIM). For geolocation testing, make sure to use IPs whose country you know with certainty, or test databases.
IPs in logs and privacy
In the EU, public IPs are considered personal data under GDPR when they can be tied to a user. Implications:
- Document the processing in your privacy policy.
- Define a retention period (typically 30-90 days for operational logs).
- Anonymize (truncate the last octet:
192.168.1.0) when you only need stats. - Allow user-requested deletion.
Common testing mistakes with IPs
- Using real public IPs in demos. If the IP belongs to another company, you might suggest traffic that isn't real. Prefer TEST-NET.
- Hardcoding 8.8.8.8. Valid but it belongs to Google. In documentation, prefer
192.0.2.1. - Ignoring IPv6. More and more traffic is v6. If your system tests only v4, you may have production bugs waiting.
- Validating with sloppy regex.
\d+\.\d+\.\d+\.\d+accepts999.999.999.999. Validate each octet is 0-255.