Lesson 3 of 15
Subnet Masks & CIDR
Subnet Masks & CIDR
A subnet mask determines which portion of an IP address identifies the network and which identifies the host. CIDR (Classless Inter-Domain Routing) notation uses a slash followed by the number of network bits.
Subnet Mask Basics
IP: 192.168.1.100
Mask: 255.255.255.0 (/24)
Network: 192.168.1.0
Host: 0.0.0.100
The network address is obtained by ANDing the IP with the mask. The broadcast address has all host bits set to 1.
CIDR Notation
| CIDR | Subnet Mask | Hosts |
|---|---|---|
| /8 | 255.0.0.0 | 16,777,214 |
| /16 | 255.255.0.0 | 65,534 |
| /24 | 255.255.255.0 | 254 |
| /28 | 255.255.255.240 | 14 |
| /32 | 255.255.255.255 | 1 |
Number of usable hosts = 2^(32 - prefix) - 2 (excluding network and broadcast addresses).
Your Task
Implement subnetInfo(cidr) that takes a CIDR string (e.g., "192.168.1.100/24") and returns an object with:
networkAddress: the network addressbroadcastAddress: the broadcast addresssubnetMask: dotted-decimal maskusableHosts: number of usable host addresses
Node.js loading...
Loading...
Click "Run" to execute your code.