Welcome to the comprehensive documentation for the IPv4 Subnet Calculator PHP library. This documentation provides everything you need to effectively use the library for network planning, IP address management, and subnet calculations.
- Getting Started - Installation, setup, and your first subnet calculations
- Quick Reference - Common operations at a glance
- Migration Guide (v4 → v5) - Upgrading from version 4.x to 5.0
- Core Features - Essential network calculations and operations
- Advanced Features - CIDR aggregation, subnet exclusion, utilization analysis
- Reports - Generate comprehensive network reports
- API Reference - Complete method documentation
- Real-World Examples - Practical patterns and use cases
New to the library? Follow this path:
- Getting Started - Learn installation and basic usage
- Core Features - Network Component Access - Understand IP addresses, masks, and network portions
- Core Features - Check if IP is in Subnet - Basic subnet operations
- Reports - Generate your first network report
Already familiar with basics? Explore these topics:
- Core Features - Network Overlap and Containment - Detect network conflicts
- Core Features - IP Address Type Detection - Classify IP addresses
- Core Features - Subnet Operations - Split and navigate subnets
- Examples - Firewall and Security - Apply to real scenarios
Ready for complex operations? Master these:
- Advanced Features - Subnet Exclusion - IPAM and address carving
- Advanced Features - CIDR Aggregation - Route summarization
- Advanced Features - Utilization Statistics - Capacity planning
- Examples - Network Planning and IPAM - Build complete solutions
// From CIDR notation (most common)
$subnet = IPv4\Subnet::fromCidr('192.168.1.0/24');
// From IP and subnet mask
$subnet = IPv4\SubnetParser::fromMask('192.168.1.0', '255.255.255.0');
// From IP range
$subnet = IPv4\SubnetParser::fromRange('192.168.1.0', '192.168.1.255');
// From host count requirement
$subnet = IPv4\SubnetParser::fromHostCount('192.168.1.0', 100);$subnet = IPv4\Subnet::fromCidr('192.168.1.0/24');
$subnet->networkAddress(); // IPAddress: 192.168.1.0
$subnet->broadcastAddress(); // IPAddress: 192.168.1.255
$subnet->mask(); // SubnetMask: 255.255.255.0
$subnet->hostCount(); // 254
$subnet->addressRange(); // IPRange: 192.168.1.0 - 192.168.1.255// Check if IP is in subnet
$subnet->containsIP('192.168.1.100'); // true
// Check for overlaps
$subnet1->overlaps($subnet2);
// Split into smaller subnets
$smaller = $subnet->split(26); // Split /24 into /26 subnets
// Get adjacent subnets
$next = $subnet->next();
$prev = $subnet->previous();
// Check IP type
$subnet->isPrivate(); // true for RFC 1918 addresses
$subnet->isPublic(); // true for publicly routable addresses// Exclude subnets (IPAM)
$remaining = $allocated->exclude($reserved);
// Aggregate routes (BGP)
$summary = IPv4\Subnets::aggregate($subnets);
// Utilization analysis
$utilization = $subnet->utilizationFor(100);
$wasted = $subnet->wastedAddressesFor(100);// Print to console
echo $subnet;
// Get as JSON
$json = $subnet->toJson();
// Get as array
$array = $subnet->toArray();- Getting Started - From Required Host Count
- Core Features - Subnet Operations
- Advanced Features - Subnet Exclusion
- Advanced Features - Utilization Statistics
- Examples - Network Planning and IPAM
- Core Features - Network Overlap and Containment
- Core Features - IP Address Type Detection
- Examples - Firewall and Security
- Advanced Features - CIDR Aggregation
- Core Features - Adjacent Subnet Navigation
- Examples - BGP Route Summarization
- Getting Started - From Required Host Count
- Advanced Features - Utilization Statistics
- Examples - DHCP Scope Planning
| Feature | Core | Advanced | Examples |
|---|---|---|---|
| IP Address & Masks | ✓ | ||
| Network/Host Portions | ✓ | ||
| IP in Subnet Check | ✓ | ✓ | |
| Network Overlap Detection | ✓ | ✓ | |
| IP Type Classification | ✓ | ✓ | |
| Subnet Splitting | ✓ | ||
| Adjacent Subnet Navigation | ✓ | ||
| Subnet Exclusion (IPAM) | ✓ | ✓ | |
| CIDR Aggregation | ✓ | ✓ | |
| Utilization Analysis | ✓ | ✓ | |
| Network Class Info | ✓ | ||
| Report Generation | ✓ | ✓ |
All public methods are documented in the API Reference, organized by category:
- Factory Methods
- Network Information
- IP Address Operations
- Network Operations
- Type Detection
- Navigation
- Reports
Practical examples are organized by use case in Real-World Examples:
- Network Planning & IPAM
- Firewall & Security
- BGP Route Summarization
- DHCP Scope Planning
- DNS Configuration
- Network Automation
IP Addresses:
Subnet Masks:
Network Calculations:
Overlaps & Conflicts:
IPAM Operations:
Route Optimization:
The library implements standards and best practices from various RFCs:
- RFC 1918 - Private Address Space
- RFC 1122 - Host Requirements (Loopback, This Network)
- RFC 919 - Broadcasting
- RFC 3927 - Link-Local Addresses
- RFC 5771 - Multicast
- RFC 6598 - Carrier-Grade NAT
- RFC 5737 - Documentation Addresses (TEST-NET)
- RFC 2544 - Benchmarking
- RFC 1112 - Reserved Addresses
- RFC 3021 - Point-to-Point (/31) Networks
- RFC 4632 - CIDR (Classless Inter-Domain Routing)
See Core Features - IP Address Type Detection for detailed RFC compliance information.
- Current Version (v5.x): Requires PHP 8.1+
- Previous Version (v4.x): PHP 7.2-8.0 users should use v4.4.0
- Legacy Support (v3.x): PHP 5.5-7.1 users should use v3.1
Found an issue or have a suggestion for improving the documentation?
- Main README - Project overview and quick reference
- GitHub Repository
- Packagist Package
- IPv4 Address Space
- CIDR Notation
-
- Installation
- System Requirements
- Quick Start
- Creating Subnet Calculators
- Basic Network Information
- Troubleshooting
-
- Network Component Access (IP, Masks, Portions)
- Network Overlap and Containment
- IP Address Type Detection
- Reverse DNS (ARPA Domain)
- Subnet Operations (Split)
- Adjacent Subnet Navigation
-
- Subnet Exclusion and Difference Operations
- CIDR Aggregation and Supernetting
- Utilization Statistics
- Network Class Information (Legacy)
-
- Printed Report
- Array Report
- JSON Report
- String Report
- Standard Interfaces
- Use Cases
-
- Complete method documentation
- Organized by category
- Quick reference by use case
-
- Network Planning and IPAM
- Firewall and Security
- BGP Route Summarization
- DHCP Scope Planning
- DNS Configuration
- Network Automation
Ready to get started? Begin with Getting Started →