Computer Networks
Subnets and Masks
Consider an office of 1000 employees on one network. Every broadcast is visible to all, security is nonexistent, performance is terrible. Subnets solve this problem - like walls between departments.
- **VLAN + subnets:** Isolating departments - accounting doesn't see development
- **IP conservation:** ISPs divide a block into small subnets for clients
- **Security:** A DMZ in a separate subnet protects the internal network
Предварительные знания
What is a subnet mask
A **subnet mask** is a 32-bit number that divides an IP address into two parts: the **network** part and the **host** part. The mask bits indicate where the network address ends and the device address begins.
The mask works like a stencil: ones (1) are network bits, zeros (0) are host bits. A bitwise **AND** operation between the IP and the mask gives the network address.
**Why?** The mask determines whether two devices are on the same network. If the network parts match - they can communicate directly. If not - a router is needed.
What does the subnet mask 255.255.0.0 indicate?
CIDR notation
**CIDR** (Classless Inter-Domain Routing) is a compact way to write a mask. Instead of `255.255.255.0` we write `/24` - the number of one-bits in the mask. This is called the **prefix length**.
**Why CIDR?** The old class-based system (Class A/B/C) was inflexible. CIDR allows dividing IP space into chunks of any size - precisely matching needs.
**Formula:** number of hosts = 2^(32-prefix) - 2. Minus 2, because the network address and broadcast cannot be assigned to devices.
How many hosts can a /24 network have?
Network and host bits
Understanding the boundary between network and host bits is the key to working with subnets. Let's work through an example with `/26`.
**Rule:** network address - all host bits are 0; broadcast - all host bits are 1. Everything in between is available for devices.
**Common mistake:** thinking that broadcast always ends in .255. In /26, broadcast is .63; in /28, it's .15. It depends on the subnet size!
What is the broadcast address for the network 10.0.0.0/30?
Practical subnet calculation
A typical task: "Divide 192.168.1.0/24 into 4 equal subnets". The goal is to determine the new mask and address ranges.
**Tip:** Subnet size is always a power of two: 4, 8, 16, 32, 64, 128, 256. Subnet boundaries are multiples of their size.
Any mask can be used with any IP
The network address must match the mask - host bits must be zeros
192.168.1.100/24 is incorrect as a network address (host part is not zero). Correct: 192.168.1.0/24 or 192.168.1.100 with a /24 mask.
What mask is needed to divide a /24 into 8 subnets?
Key ideas
- **Mask** divides an IP into network and host parts (AND with IP = network address)
- **CIDR /N** - the number of one-bits in the mask
- **Hosts = 2^(32-N) - 2** (minus network and broadcast)
- **Subnetting:** borrow bits from hosts to get more, smaller networks
Related topics
Subnets are the foundation of network architecture:
- Private IP addresses — Which ranges to use inside a network
- Routing — How a router determines a path using a mask
- VLSM — Variable-length subnets for optimization
Вопросы для размышления
- Why can't the broadcast address be assigned to a device?
- How to tell if two IP addresses are on the same subnet without a calculator?
- Why use /30 for point-to-point connections?