Post

Understanding TCP/IP Networking: IP Addresses, Subnets, and Routing

Understanding TCP/IP Networking: IP Addresses, Subnets, and Routing

Why Developers Should Understand TCP/IP

Every application you build communicates over a network. Whether you’re configuring cloud infrastructure, debugging connectivity issues, setting up VPCs, or understanding why a request times out, TCP/IP knowledge is foundational. This article breaks down the core concepts: IP addresses, subnet masks, network classes, default gateways, and private address ranges.

IP Addresses: Network and Host

An IP address is a 32-bit number that uniquely identifies a device on a TCP/IP network. It’s written in dotted-decimal notation — four numbers (octets) separated by periods:

1
192.168.123.132

Each octet represents 8 bits, so the full address in binary is:

1
11000000.10101000.01111011.10000100

Two Parts of Every IP Address

Every IP address is split into two logical parts:

PartPurposeExample
Network addressIdentifies which network the device belongs to192.168.123.0
Host addressIdentifies the specific device within that network0.0.0.132

Routers use the network portion to forward packets to the correct network. Once the packet arrives at the destination network, the host portion identifies the specific device.

This is analogous to postal mail: the network address is the street name, and the host address is the house number.

Subnet Masks: Separating Network from Host

The division between network and host isn’t fixed — it’s determined by the subnet mask.

A subnet mask is another 32-bit number. In binary, it’s always a sequence of 1s followed by 0s:

  • The 1 bits mark the network portion
  • The 0 bits mark the host portion

Example

1
2
11000000.10101000.01111011.10000100  — IP address   (192.168.123.132)
11111111.11111111.11111111.00000000  — Subnet mask  (255.255.255.0)

The first 24 bits (all 1s in the mask) are the network address. The remaining 8 bits (all 0s) are the host address:

1
2
11000000.10101000.01111011.00000000  — Network address (192.168.123.0)
00000000.00000000.00000000.10000100  — Host address    (0.0.0.132)

With this mask, any device with an IP starting with 192.168.123.x is on the same network. The last octet (0–255) identifies individual hosts within it.

How the Mask Works (Bitwise AND)

To extract the network address, perform a bitwise AND between the IP address and the subnet mask:

1
2
3
  192.168.123.132   →  11000000.10101000.01111011.10000100
& 255.255.255.0     →  11111111.11111111.11111111.00000000
= 192.168.123.0     →  11000000.10101000.01111011.00000000

This operation zeroes out the host bits, leaving only the network address.

Common Subnet Masks

DecimalBinaryNetwork bitsHosts per subnet
255.0.0.011111111.00000000.00000000.00000000816,777,214
255.255.0.011111111.11111111.00000000.000000001665,534
255.255.255.011111111.11111111.11111111.0000000024254
255.255.255.19211111111.11111111.11111111.110000002662
255.255.255.22411111111.11111111.11111111.111000002730

The number of usable hosts is 2^(host bits) - 2 (subtract the network address and broadcast address).

CIDR Notation

Instead of writing out the full subnet mask, CIDR notation appends the number of network bits after a slash:

CIDRSubnet MaskMeaning
/8255.0.0.0First 8 bits are the network
/16255.255.0.0First 16 bits are the network
/24255.255.255.0First 24 bits are the network
/26255.255.255.192First 26 bits are the network
/32255.255.255.255Single host

192.168.123.0/24 means “the network 192.168.123.0 with a 24-bit mask” — equivalent to subnet mask 255.255.255.0.

You’ll see CIDR notation everywhere in cloud configurations (AWS VPCs, security groups, route tables).

Network Classes

Historically, IP addresses were grouped into classes based on their first octet. While classful addressing has been largely replaced by CIDR, the terminology persists and is useful to understand:

ClassFirst Octet RangeDefault Subnet MaskNetwork/Host SplitExample
A1–126255.0.0.0 (/8)8 / 24 bits10.52.36.11
B128–191255.255.0.0 (/16)16 / 16 bits172.16.52.63
C192–223255.255.255.0 (/24)24 / 8 bits192.168.123.132

Class A networks have few network addresses but millions of hosts per network. Class C networks have many network addresses but only 254 hosts each. Class B sits in between.

Note: 127.x.x.x is reserved for loopback (127.0.0.1 is localhost). Classes D (224–239, multicast) and E (240–255, experimental) exist but aren’t used for standard addressing.

Default Gateways

When a device wants to communicate with another device, it first determines whether the destination is local (same subnet) or remote (different subnet).

The process:

  1. Apply the subnet mask to both the source IP and destination IP (bitwise AND)
  2. Compare the resulting network addresses
  3. If they match — the destination is local; send directly on the subnet
  4. If they don’t match — the destination is remote; forward the packet to the default gateway

The default gateway is a router on your local subnet that knows how to forward packets to other networks. It’s the “exit door” from your subnet to the rest of the network.

Example

Your device: 192.168.1.100 with mask 255.255.255.0 and gateway 192.168.1.1

Sending to 192.168.1.50 (local):

1
2
3
192.168.1.100 AND 255.255.255.0 = 192.168.1.0
192.168.1.50  AND 255.255.255.0 = 192.168.1.0
→ Same network → send directly

Sending to 10.0.0.5 (remote):

1
2
3
192.168.1.100 AND 255.255.255.0 = 192.168.1.0
10.0.0.5      AND 255.255.255.0 = 10.0.0.0
→ Different network → forward to gateway 192.168.1.1

The router at 192.168.1.1 then consults its routing table to determine where to send the packet next.

Private IP Addresses

Not every device needs a globally unique, publicly routable IP address. RFC 1918 reserves three address ranges for private networks:

NameCIDR BlockAddress RangeAddressesClassful Description
24-bit block10.0.0.0/810.0.0.010.255.255.25516,777,216Single Class A
20-bit block172.16.0.0/12172.16.0.0172.31.255.2551,048,57616 Class B blocks
16-bit block192.168.0.0/16192.168.0.0192.168.255.25565,536256 Class C blocks

Key properties of private addresses

  • Not routable on the public internet — routers discard packets with private source/destination addresses
  • Free to use — no registration required
  • Reusable — different organisations can use the same private ranges without conflict
  • Require NAT for internet access — Network Address Translation maps private addresses to a public IP for outbound traffic

Where you’ll see them

  • Home networks: Your router typically assigns addresses from 192.168.0.0/24 or 192.168.1.0/24
  • AWS VPCs: Default VPC uses 172.31.0.0/16; custom VPCs commonly use 10.0.0.0/16
  • Docker networks: Default bridge uses 172.17.0.0/16
  • Kubernetes: Pod networks typically use 10.244.0.0/16 or similar

IPv6: The Future (and Present)

IPv4’s 32-bit address space provides approximately 4.3 billion addresses — not enough for the modern internet. IPv6 expands the address size to 128 bits, providing roughly 3.4 x 10^38 addresses.

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

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

Leading zeros can be omitted, and consecutive groups of zeros can be replaced with :::

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

While IPv6 adoption continues to grow, most developers still work primarily with IPv4 in cloud and enterprise environments. Understanding IPv4 thoroughly remains essential.

Quick Reference

ConceptKey Point
IP address32-bit number identifying a device on a network
Subnet maskDefines which bits are network vs. host
CIDR notationShorthand for subnet mask (/24 = 255.255.255.0)
Network classesHistorical grouping by first octet (A: 1–126, B: 128–191, C: 192–223)
Default gatewayRouter that forwards packets to other networks
Private addresses10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 — not internet-routable
NATTranslates private addresses to public for internet access
IPv6128-bit addresses replacing IPv4’s 32-bit space

References

This post is licensed under CC BY 4.0 by the author.