# Subnet

> A slice of a network's IP addresses, grouped so its devices can talk directly.

- Level: Advanced
- Topics: Networks
- URL: https://tidbit.legios.com.ar/subnet/
- In Spanish: [Subred](https://tidbit.legios.com.ar/es/subnet/)

A **subnet** is a block of consecutive IP addresses that belong together, like all the addresses on one office floor or in one part of a cloud network. Devices in the same subnet reach each other directly. To reach anything outside it, they hand their traffic to a router, known as the **default gateway**, which forwards it on.

Subnets are usually written in **CIDR** notation: `10.0.1.0/24`. The number after the slash says how many of the 32 bits of an IPv4 address are fixed for the whole subnet; the rest are free for devices. A `/24` fixes the first three numbers, so `10.0.1.0` to `10.0.1.255` is roughly 250 usable addresses. A `/16` fixes only the first two and holds about 65,000. The bigger the number after the slash, the smaller the subnet. The older way to say the same thing is a **subnet mask**: `/24` is `255.255.255.0`.

Splitting a network has practical reasons. Each subnet can get its own rules, so a firewall can let the web servers in one subnet talk to the database in another, while the guest Wi-Fi in a third reaches only the internet. Smaller subnets also keep local chatter, like devices asking 'who has this address?', from flooding every machine in the building.

In the cloud this is everyday work. When you create an Amazon VPC you pick a range like `10.0.0.0/16` and carve it into subnets, typically one public and one private per Availability Zone. Public subnets hold what must be reachable from the internet, such as a load balancer; private ones hold databases and internal services. Ranges cannot overlap if networks will ever be connected, so it pays to plan them early.

## An analogy

A building's address range split into floors. People on the same floor walk over to each other's desks; to reach another floor, they go through the reception desk, which knows where everyone is.

## Keep in mind

- Devices in the same subnet talk directly; anything else goes through the router.
- `/24` means the first 24 bits are fixed: roughly 250 usable addresses.
- A bigger number after the slash means a smaller subnet.
- In the cloud, public subnets face the internet and private ones stay inside.

## Go deeper

- [Subnet on Wikipedia](https://en.wikipedia.org/wiki/Subnet)
- [Subnets for your VPC (AWS docs)](https://docs.aws.amazon.com/vpc/latest/userguide/configure-subnets.html)

## Related terms

- [IP address](https://tidbit.legios.com.ar/ip-address/): The number that identifies a device on a network, like a postal address.
- [Cloud computing](https://tidbit.legios.com.ar/cloud-computing/): Renting computers over the internet instead of buying your own.
- [Router](https://tidbit.legios.com.ar/router/): The box that connects your devices to each other and to the internet.
- [Firewall](https://tidbit.legios.com.ar/firewall/): A gatekeeper that decides which network traffic gets in or out.
- [Server](https://tidbit.legios.com.ar/server/): A computer whose job is to answer requests from other computers, all day, every day.
- [Database](https://tidbit.legios.com.ar/database/): An organized store of data that programs can search and update safely.
- [Wi-Fi](https://tidbit.legios.com.ar/wi-fi/): Networking over radio waves: the internet without the cable, within a few rooms.
- [Internet](https://tidbit.legios.com.ar/internet/): A worldwide network of networks that lets any connected device reach any other.
