Need to calculate network ranges from CIDR notation? This guide covers everything about CIDR calculation via API, including subnet masks, IP ranges, and implementation examples in multiple programming languages.
What is CIDR?
CIDR (Classless Inter-Domain Routing) is a method for allocating IP addresses and routing. It uses a suffix to indicate the network portion of the address, replacing the older class-based system.
Example: 192.168.1.0/24 represents a network with 256 addresses (192.168.1.0 - 192.168.1.255)
CIDR Components
Understanding CIDR notation:
Network Address
The base IP address of the network (e.g., 192.168.1.0)
Prefix Length
The number after the slash indicates network bits. /24 means 24 network bits, 8 host bits.
Subnet Mask
/24 equals subnet mask 255.255.255.0, determining network vs host portions.
Using the CIDR Calculator API
TinyFn provides a comprehensive endpoint to calculate CIDR networks:
GET https://api.tinyfn.io/v1/network/cidr?cidr=192.168.1.0/24
Headers: X-API-Key: your-api-key
{
"cidr": "192.168.1.0/24",
"network_address": "192.168.1.0",
"broadcast_address": "192.168.1.255",
"subnet_mask": "255.255.255.0",
"wildcard_mask": "0.0.0.255",
"first_host": "192.168.1.1",
"last_host": "192.168.1.254",
"total_hosts": 256,
"usable_hosts": 254,
"ip_version": 4
}
Parameters
| Parameter | Type | Description |
|---|---|---|
cidr |
string | CIDR notation (e.g., 192.168.1.0/24) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/network/cidr?cidr=10.0.0.0/16',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const result = await response.json();
console.log(`Range: ${result.first_host} - ${result.last_host}`);
console.log(`Usable hosts: ${result.usable_hosts}`);
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/network/cidr',
params={'cidr': '10.0.0.0/16'},
headers={'X-API-Key': 'your-api-key'}
)
result = response.json()
print(f"Range: {result['first_host']} - {result['last_host']}")
print(f"Usable hosts: {result['usable_hosts']}")
cURL
curl "https://api.tinyfn.io/v1/network/cidr?cidr=10.0.0.0/16" \
-H "X-API-Key: your-api-key"
Common Use Cases
- Network Planning: Calculate IP ranges for network segments
- Cloud Infrastructure: Plan VPC and subnet configurations
- Firewall Rules: Define allow/deny rules with CIDR ranges
- IP Management: Track allocated and available IP addresses
- Documentation: Generate network documentation automatically
Best Practices
- Plan for growth: Choose CIDR ranges with room for expansion
- Avoid overlap: Ensure subnets don't overlap in your infrastructure
- Use private ranges: Use RFC 1918 ranges (10.x, 172.16-31.x, 192.168.x) for internal networks
- Document allocations: Keep records of CIDR allocations
Try the CIDR Calculator API
Get your free API key and start calculating networks in seconds.
Get Free API Key