Carve a network into pieces, write address ranges the short way, and share one public IP.
A subnet is a smaller slice of a bigger network. CIDR is the short way to write an address range, such as 10.0.1.0/24. NAT lets many private machines share one public IP address.
/24 means 24 network bits and 8 host bits, so 256 addresses (254 usable in classic IPv4).10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16.An IPv4 address like 10.0.1.77 is really a 32-bit number written as four bytes. To split it into a network part and a host part, we use a prefix length. In CIDR notation (Classless Inter-Domain Routing) we write the address, a slash, and the number of network bits: 10.0.1.0/24.
mask = first 24 bits set to 1 -> 255.255.255.0 network = address AND mask -> 10.0.1.0 broadcast = network OR (NOT mask) -> 10.0.1.255 addresses = 2^(32 - 24) -> 256 usable = 256 - 2 -> 254 (10.0.1.1 to 10.0.1.254)
The smaller the host part, the smaller the subnet. A /16 has 65,536 addresses, a /24 has 256, a /28 has only 16. Every extra network bit halves the size.
IPv4 has only about 4.3 billion addresses, far fewer than the number of devices. Private addresses can be reused by everyone, because they are never routed on the public internet. NAT (Network Address Translation) sits at the edge and swaps the private source address for a public one on the way out. It keeps a table so the reply finds its way back to the right machine. When it also swaps port numbers (which is what most home and cloud gateways do), it is called PAT (Port Address Translation).
| CIDR | Mask | Total addresses | Usable hosts (classic) | Typical use |
|---|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 | A huge private block such as 10.0.0.0/8 |
| /16 | 255.255.0.0 | 65,536 | 65,534 | A whole cloud network (VPC) |
| /24 | 255.255.255.0 | 256 | 254 | One subnet for a tier or an availability zone |
| /28 | 255.255.255.240 | 16 | 14 | A tiny subnet (cloud providers reserve a few, so fewer are free) |
| /32 | 255.255.255.255 | 1 | 1 (a single address) | One exact host in a rule |
| Range | Addresses | Often used for |
|---|---|---|
| 10.0.0.0/8 | About 16.7 million | Big companies and cloud networks |
| 172.16.0.0/12 | About 1 million (172.16.x.x to 172.31.x.x) | Medium networks, some container setups |
| 192.168.0.0/16 | 65,536 | Home and small office networks |
| Kind | What it does | Example |
|---|---|---|
| Source NAT / PAT | Rewrites the source of outgoing traffic, using ports to tell hosts apart | Home router, cloud NAT gateway |
| Destination NAT / port forwarding | Sends incoming traffic on a public port to one private host | Forward port 443 to an internal server |
| Static (one-to-one) NAT | Maps one private address to one public address | An internet-facing instance with a fixed public IP |
The bit maths is real: mask = the first N bits set to 1, network = IP AND mask, broadcast = network OR (NOT mask). Classic IPv4 reserves the network and broadcast addresses, and cloud providers reserve a few more per subnet (check your provider). The public address and ports in the NAT table are made-up examples.
address 10.0.2.77 in 10.0.2.0/24 ? mask = 255.255.255.0 77 AND 0 stays 77 in the host part, network part = 10.0.2 (10.0.2.77 AND mask) == 10.0.2.0 -> yes, it is inside
/24 is 256, a /25 is 128, a /26 is 64, a /27 is 32. Subnets of that size start at multiples of the size, so 10.0.1.64/26 is valid but 10.0.1.70/26 is not.| Term | Meaning in easy words |
|---|---|
| Subnet | A smaller network carved out of a larger address range |
| CIDR | Classless Inter-Domain Routing: writing a range as address/prefix, like 10.0.0.0/16 |
| Prefix length | The number of leading bits that name the network (the number after the slash) |
| Subnet mask | The same idea written as an address, such as 255.255.255.0 for /24 |
| Network address | The first address of a subnet, which names the subnet itself |
| Broadcast address | The last address of a classic IPv4 subnet, which reaches every host in it |
| Private address | An address from 10/8, 172.16/12 or 192.168/16, not routed on the public internet |
| NAT | Network Address Translation: rewriting addresses as traffic crosses a boundary |
| PAT | Port Address Translation: NAT that also rewrites ports so many hosts share one address |
| NAT gateway | A managed device or service that gives private subnets outbound internet access |
| Public / private subnet | A subnet with, or without, a route to an internet gateway |
| Choice | We gain | We lose |
|---|---|---|
| A big subnet (/16) | Plenty of room, simple | Everything shares one rule set, and a large blast radius |
| Many small subnets | Fine-grained rules and isolation | More to manage and easy to run out in one subnet |
| Private subnet + NAT | Servers can reach out but are not reachable | NAT cost, a possible bottleneck, and one more thing to fail |
| Public IP on every server | Direct and simple | A large attack surface |
| Large address plan | Room for growth and peering | Needs careful records so ranges stay unique |
| IPv6 | No shortage, no NAT needed | Different tools and habits to learn |