IP Range API: The Complete Guide to CIDR Conversion

Need to convert IP ranges to CIDR notation or expand CIDR blocks? This guide covers everything you need to know about IP range conversions via API, including aggregation and implementation examples.

What is IP Range Conversion?

IP range conversion transforms between different representations of IP address ranges. The most common conversion is between start-end notation (192.168.1.0 - 192.168.1.255) and CIDR notation (192.168.1.0/24).

CIDR is more compact and widely used in network configurations, firewalls, and routing tables.

Conversion Types

Common IP range operations:

Range to CIDR

192.168.1.0 - 192.168.1.255 becomes 192.168.1.0/24. May return multiple CIDRs if range doesn't align to boundaries.

CIDR to Range

192.168.1.0/24 becomes 192.168.1.0 - 192.168.1.255. Expands CIDR to start/end addresses.

CIDR Aggregation

Combine adjacent CIDRs into larger blocks: 192.168.0.0/24 + 192.168.1.0/24 = 192.168.0.0/23.

Note: Not all ranges convert to a single CIDR. Some ranges require multiple CIDR blocks.

Using the IP Range API

TinyFn provides endpoints for IP range conversions:

Range to CIDR Request
GET https://api.tinyfn.io/v1/network/range-to-cidr?start=192.168.1.0&end=192.168.1.255
Headers: X-API-Key: your-api-key
Response
{
  "start": "192.168.1.0",
  "end": "192.168.1.255",
  "cidrs": ["192.168.1.0/24"],
  "totalAddresses": 256
}
CIDR to Range Request
GET https://api.tinyfn.io/v1/network/cidr-to-range?cidr=192.168.0.0/23
Headers: X-API-Key: your-api-key

Parameters

Parameter Type Description
start string Starting IP address of range
end string Ending IP address of range
cidr string CIDR notation for expansion

Code Examples

JavaScript / Node.js

// Convert range to CIDR
const response = await fetch(
  'https://api.tinyfn.io/v1/network/range-to-cidr?start=192.168.1.0&end=192.168.1.255',
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const { cidrs, totalAddresses } = await response.json();
console.log(cidrs);          // ['192.168.1.0/24']
console.log(totalAddresses); // 256

// Convert non-aligned range (returns multiple CIDRs)
const nonAlignedResponse = await fetch(
  'https://api.tinyfn.io/v1/network/range-to-cidr?start=192.168.1.0&end=192.168.1.100',
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const nonAligned = await nonAlignedResponse.json();
console.log(nonAligned.cidrs);
// ['192.168.1.0/26', '192.168.1.64/27', '192.168.1.96/30', '192.168.1.100/32']

Python

import requests

# Convert range to CIDR
response = requests.get(
    'https://api.tinyfn.io/v1/network/range-to-cidr',
    params={'start': '192.168.1.0', 'end': '192.168.1.255'},
    headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(data['cidrs'])          # ['192.168.1.0/24']
print(data['totalAddresses']) # 256

# Expand CIDR to range
response = requests.get(
    'https://api.tinyfn.io/v1/network/cidr-to-range',
    params={'cidr': '10.0.0.0/8'},
    headers={'X-API-Key': 'your-api-key'}
)
range_data = response.json()
print(f"{range_data['start']} - {range_data['end']}")
# 10.0.0.0 - 10.255.255.255

cURL

# Convert range to CIDR
curl "https://api.tinyfn.io/v1/network/range-to-cidr?start=192.168.1.0&end=192.168.1.255" \
  -H "X-API-Key: your-api-key"

# Expand CIDR to range
curl "https://api.tinyfn.io/v1/network/cidr-to-range?cidr=192.168.0.0/16" \
  -H "X-API-Key: your-api-key"

Common Use Cases

  • Firewall Configuration: Convert IP lists to compact CIDR rules
  • Cloud Security Groups: Define allowed ranges in CIDR format
  • IP Whitelisting: Convert customer ranges to firewall rules
  • Network Documentation: Standardize range notation
  • BGP Route Aggregation: Combine routes for efficiency

Best Practices

  1. Aggregate when possible: Fewer CIDR blocks mean simpler configs
  2. Verify conversions: Ensure the resulting CIDRs cover the intended range
  3. Handle multiple CIDRs: Non-aligned ranges return multiple blocks
  4. Consider security: Don't over-provision CIDR ranges

Try the IP Range API

Get your free API key and start converting IP ranges in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key