子网
What Is Subnetting?¶
Subnetting is the process of dividing a large network into smaller logical networks called subnets. Each subnet works as an independent network while still being part of a larger network.
In simple terms, subnetting helps organize IP addresses efficiently and allows better control over network traffic.
Key Concepts You Must Know Before Subnetting¶
Before performing subnet calculations, it is important to understand a few basic networking terms.
1. IP Address: An IP address uniquely identifies a device on a network, such as 192.168.1.10.
2. Subnet Mask: A subnet mask defines which part of the IP address represents the network and which part represents hosts.
Example: 255.255.255.0
3. Network ID: The first address in a subnet that identifies the network itself.
4. Broadcast Address: The last address in a subnet, used to communicate with all devices in that subnet.
5. Host Addresses: The usable IP addresses assigned to devices within the subnet.
Understanding Subnet Masks¶
A subnet mask works by masking the network portion of an IP address.
Common Subnet Masks
- 255.0.0.0 → Class A
- 255.255.0.0 → Class B
- 255.255.255.0 → Class C
The subnet mask directly affects how many hosts and subnets are available.
What Is CIDR?¶
CIDR (Classless Inter-Domain Routing) is a modern IP addressing method that replaces class-based subnetting. It allows flexible subnet sizes and better IP utilization.
Example:
Here, /24 means the first 24 bits are used for the network, and the remaining bits are used for hosts.
Subnetting Basics Explained Step by Step¶
Now let’s break subnetting into simple, beginner-friendly steps.
Step 1: Identify the Given IP Address and Subnet Mask¶
The first step is to identify the IP address and subnet mask.
Example: IP Address: 192.168.1.0 Subnet Mask: 255.255.255.0 or /24
This tells us we are working with a Class C–type network, where 24 bits represent the network portion.
Step 2: Determine the Number of Subnets or Hosts Needed¶
Subnetting problems usually ask one of the following:
- How many subnets are required
- How many hosts are required per subnet
This requirement helps decide how many bits must be borrowed from the host portion.
Step 3: Borrow Bits from the Host Portion¶
Each borrowed bit doubles the number of subnets.
Example:
- Borrow 1 bit → 2 subnets
- Borrow 2 bits → 4 subnets
- Borrow 3 bits → 8 subnets
This step is critical in subnet calculation.
Step 4: Calculate the New Subnet Mask¶
Borrowing bits increases the subnet mask value.
Example:
- Original subnet: /24
- Borrow 2 bits → /26
New subnet mask: 255.255.255.192
This new mask defines the size of each subnet.
Step 5: Calculate the Number of Hosts per Subnet¶
Use the formula:
Hosts = 2ⁿ − 2
Where n is the number of remaining host bits.
Example:
- /26 leaves 6 host bits
- Hosts = 2⁶ − 2 = 62 usable hosts
Two addresses are reserved for the network ID and broadcast address.
Step 6: Identify Subnet Ranges¶
Subnet ranges are calculated using the block size.
Block size formula: 256 − subnet mask value
Example: 256 − 192 = 64
Subnet ranges:
- 192.168.1.0 – 192.168.1.63
- 192.168.1.64 – 192.168.1.127
- 192.168.1.128 – 192.168.1.191
- 192.168.1.192 – 192.168.1.255
Each range represents one subnet.
Subnetting Example Explained¶
Let’s look at a complete subnetting example.
Given:
IP Address: 192.168.10.0/26
Results:
- Number of subnets: 4
- Hosts per subnet: 62
Subnet Breakdown:
- Network ID: 192.168.10.0
- First usable host: 192.168.10.1
- Last usable host: 192.168.10.62
- Broadcast address: 192.168.10.63
The same pattern repeats for each subnet.
Common Subnetting Mistakes Beginners Make¶
Some common mistakes include:
- Forgetting to subtract network and broadcast addresses
- Miscalculating block size
- Confusing CIDR notation with subnet mask
- Relying only on class-based thinking
Regular practice helps avoid these errors.
Subnetting in Real-World Networks¶
Subnetting is widely used in practical environments such as:
- Office and enterprise networks
- VLAN-based network designs
- Cloud VPC and subnet planning
- Firewall and VPN configurations
- High availability and load-balanced systems
Subnetting improves both performance and security.
Subnetting Interview Questions¶
Interviewers frequently test subnetting concepts.
Common questions include:
- How many hosts are available in a /27 network?
- What is the subnet mask for /23?
1. /24 -> mask: 255.255.255.0
2. 24 - 23 = 1 1bit -> 255 - 2**0 = 254
3. so, the subnet mask of /23 is 255.255.254.0
- How many subnets are created by borrowing 3 bits?
- Find the broadcast address for a given subnet
Clear step-by-step logic matters more than memorization.
参考文章:https://www.computernetworkingnotes.com/ccna-study-guide/subnetting-tricks-subnetting-made-easy-with-examples.html