NetworkingIP AddressSecuritySubnettingDeveloper Tools

Understanding IP Addresses and Network Subnetting: A Complete Guide

โ€ขBy Hamid Abderrahim
Understanding IP Addresses and Network Subnetting: A Complete Guide

Understanding IP Addresses and Network Subnetting: A Complete Guide

Every device connected to the internet has an IP address โ€” a numerical label that identifies it on a network. When you load a website, your device sends a request from your IP address to the server's IP address. When you send an email, it travels through multiple routers, each one using IP addresses to decide where to forward it next.

Despite being fundamental to how the internet works, IP addresses and subnetting are topics many developers avoid because they seem overly complex. This guide breaks down both concepts clearly, with practical examples that make the theory immediately applicable.

IPv4: The Classic Address Format

IPv4 addresses are 32-bit numbers written as four decimal octets separated by dots:

192.168.1.100

Each octet represents 8 bits, so each can range from 0 to 255. The total address space is 2ยณยฒ = approximately 4.29 billion unique addresses.

In the 1990s, 4.29 billion seemed infinite. By the 2010s, the internet had far more connected devices than available IPv4 addresses. This is why private address ranges, NAT, and IPv6 all exist.

Public vs. Private IP Addresses

Not all IP addresses route over the public internet. The Internet Assigned Numbers Authority (IANA) has reserved three ranges for private networks:

RangeCIDR NotationAddresses
10.0.0.0 โ€“ 10.255.255.25510.0.0.0/8~16.7 million
172.16.0.0 โ€“ 172.31.255.255172.16.0.0/12~1 million
192.168.0.0 โ€“ 192.168.255.255192.168.0.0/16~65,000

Devices on a home or office network typically have addresses in the 192.168.x.x range. These addresses are not routable on the public internet โ€” your router performs Network Address Translation (NAT) to map your private address to its single public IP address when accessing the internet.

Loopback: 127.0.0.0/8 is reserved for the loopback interface. 127.0.0.1 (localhost) refers to the device itself and never leaves the machine.

Link-Local: 169.254.0.0/16 is the self-assigned range used when a device cannot reach a DHCP server and assigns itself a temporary address.

Subnet Masks and CIDR Notation

A subnet mask defines which portion of an IP address identifies the network and which identifies the host (individual device) within that network.

A subnet mask is also a 32-bit number, typically written alongside an IP address:

IP address: 192.168.1.100
Subnet mask: 255.255.255.0

The subnet mask 255.255.255.0 in binary is:

11111111.11111111.11111111.00000000

The 1 bits identify the network portion; the 0 bits identify the host portion. In this case, the first 24 bits are the network (192.168.1) and the last 8 bits are the host (.100).

CIDR Notation

CIDR (Classless Inter-Domain Routing) is a more compact way to express the same information. Instead of writing the full subnet mask, you write the IP address followed by a slash and the count of network bits:

192.168.1.0/24

This means: network 192.168.1.0 with a 24-bit network prefix (equivalent to subnet mask 255.255.255.0). The remaining 8 bits allow 2โธ = 256 addresses (254 usable โ€” the network address and broadcast address are reserved).

Common CIDR Subnets

CIDRSubnet MaskUsable Hosts
/8255.0.0.0~16.7 million
/16255.255.0.0~65,000
/24255.255.255.0254
/28255.255.255.24014
/30255.255.255.2522
/32255.255.255.2551 (single host)

A /32 is a host route โ€” it refers to a single IP address. Used in firewall rules to allow or block one specific IP.

Subnetting: Dividing a Network

Subnetting is the process of dividing a larger network into smaller sub-networks. For example, a company with a /24 network (254 hosts) might want to create separate subnets for its engineering, sales, and HR departments to isolate traffic.

Starting with 192.168.1.0/24, you can split it into four /26 subnets (each with 62 usable hosts):

  • 192.168.1.0/26 โ€” hosts .1 to .62
  • 192.168.1.64/26 โ€” hosts .65 to .126
  • 192.168.1.128/26 โ€” hosts .129 to .190
  • 192.168.1.192/26 โ€” hosts .193 to .254

Each subnet is isolated at Layer 3. Traffic between subnets must pass through a router, making it possible to apply firewall rules between departments.

Special IP Address Ranges

Documentation and examples: 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24 โ€” reserved for documentation and testing; should never appear in real network configurations

Multicast: 224.0.0.0/4 โ€” used for one-to-many streaming

IANA Reserved: 240.0.0.0/4 โ€” reserved for future use, not usable in practice

Shared Address Space: 100.64.0.0/10 โ€” used between ISPs and their customer routers (Carrier-Grade NAT)

IPv6: The Long-Term Solution

IPv6 uses 128-bit addresses, providing 2ยนยฒโธ โ‰ˆ 340 undecillion unique addresses โ€” enough for every grain of sand on Earth to have its own IP address many times over.

IPv6 addresses are written as eight groups of four hexadecimal digits separated by colons:

2001:0db8:85a3:0000:0000:8a2e:0370:7334

Zero compression: Consecutive groups of all zeros can be replaced with :: once per address:

2001:db8:85a3::8a2e:370:7334

IPv6 adoption is ongoing. Most modern devices and networks support both IPv4 and IPv6 simultaneously (dual-stack), and internet service providers are increasingly assigning IPv6 addresses natively.

Analyzing an IP Address

Our IP Address Analyzer tool provides detailed information about any IP address:

  • Geolocation (country, region, city)
  • ISP and organization
  • ASN (Autonomous System Number)
  • Whether the IP is in a private, reserved, or public range
  • Subnet information

This is particularly useful for security analysis, debugging connection issues, or understanding where traffic is originating from.

Practical Applications for Developers

Firewall rules: CIDR notation is used in AWS Security Groups, Azure Network Security Groups, GCP firewall rules, and nginx allow/deny directives.

API rate limiting: Implement rate limiting per IP subnet (/24) rather than per IP address to prevent trivial bypass by rotating IPs within the same range.

CDN and geolocation: Content delivery networks use IP geolocation databases to route users to the nearest edge server.

Security analysis: When investigating suspicious traffic or a potential breach, identifying the IP range and organization helps determine whether traffic is legitimate.

Summary

IP addresses and subnetting are the foundation of network communication. Understanding them makes you a better developer, particularly when working with cloud infrastructure, security configurations, and network debugging.

Key takeaways:

  • IPv4 addresses are 32 bits; IPv6 are 128 bits
  • Private ranges (192.168.x.x, 10.x.x.x, 172.16-31.x.x) are not routable on the public internet
  • Subnet masks and CIDR notation define which bits are network vs. host
  • /24 = 254 usable hosts; each bit added to the prefix halves the host count
  • Analyze any IP address instantly with the IP Address Analyzer tool