CGNAT calculator ports per subscriber and MikroTik script
See how many subscribers fit on each public IP, how many IPs you need, and then generate a deterministic CGNAT script for RouterOS. You can also find which subscriber used a given IP and port.
FreeNo sign-upSourced formulasRuns in your browser
By the IP Insight Support engineering team · Updated
Use the CGNAT calculator
Set subscribers, ports per subscriber and your public IP pool, and then the script is generated instantly.
Rolling out CGNAT, or moving to IPv6 so you depend on it less? In that case, we design it and leave it running.
Chat on WhatsAppHow the CGNAT calculator works
In short, the method is deterministic CGNAT: every subscriber always gets the same public IP and the same port range.
Subscribers per public IP
First, take the available port range; then divide it by the ports per subscriber.
Subscribers per IP = ⌊(last port − first port + 1) / ports per subscriber⌋
IPs needed = ⌈subscribers / subscribers per IP⌉Ports 0 to 1023 are system ports, per RFC 6335, so the default range starts at 1024.
Why deterministic
When each subscriber has a fixed range, you can tell who used an IP and port without logging every session.
The method is described in RFC 7422. In addition, RFC 6888 requires the ability to limit ports per subscriber (REQ-4).
How the script is built
Each subscriber gets three rules: TCP and UDP with its port range, and a third for other protocols. Rules are grouped into jump chains so the router evaluates fewer rules per packet.
add chain=cgnat-1-1 action=src-nat protocol=tcp src-address=100.64.0.1 to-addresses=203.0.113.10 to-ports=1024-2023src-nat syntax and a CGNAT example are in the MikroTik NAT documentation.
Which private space to use
In particular, the 100.64.0.0/10 block is reserved for the network between an operator CGNAT and its subscribers.
Source: RFC 6598. The 203.0.113.0/24 addresses in the examples are documentation addresses, per RFC 5737.
Worked example with the CGNAT calculator: 500 subscribers
An operator has 500 subscribers and wants to give each one 1,000 ports, using 1024 to 65535. Each public IP offers 64,512 ports, so it serves 64 subscribers, and the operator needs 8 public IPs.
Subscriber 100.64.0.1 goes out through 203.0.113.10 on ports 1024 to 2023, while subscriber 65 moves to the second IP. When a request arrives for 203.0.113.11 and port 5000, the reverse lookup answers in a second: it was subscriber 100.64.0.68.
- More ports per subscriber improve the experience but require more public IPs.
- Keep the plan (pool, ports and IPs) with dates: after all, it is what lets you identify subscribers later.
- Check your router connection limit as well, not just ports.
- CGNAT is a bridge; however, the long-term fix is IPv6, so read our what is CGNAT guide.
CGNAT calculator FAQ
What is deterministic CGNAT?
A CGNAT where each subscriber always gets the same public IP and port range. As a result, you can identify the subscriber from an IP and port without logging every connection, as RFC 7422 describes.
How many ports should each subscriber get?
There is no single number, because it depends on the applications your customers use. RFC 6888 requires the limit to be configurable; start generous and adjust with real usage.
Why three rules per subscriber?
TCP and UDP use ports, so they get the assigned range. Other protocols, such as ICMP, go out through the same public IP with a rule that has no ports.
Why use jump chains?
So each packet walks fewer rules. The router first picks the public IP block and then the subscriber group, instead of checking every rule one by one.
Do I still need to keep logs?
Fixed mapping greatly reduces what you must log, but you should keep the plan with its dates and check what your local regulations require.
Does the script work on any router?
It is written in RouterOS syntax, so it targets MikroTik routers. Test it in a lab, back up your configuration and adapt it to your topology before using it in production.
Other free tools for your network
Link budget calculator
Check link margin and free-space path loss, then confirm Fresnel zone clearance over an obstacle.
Use the tool →AddressingIPv6 subnet calculator
Plan IPv6 prefixes and, in addition, carve IPv4 subnets with VLSM and a full range table.
Use the tool →SLA and continuityDowntime calculator
Turn an SLA into hours of downtime per year, then estimate the cost and what redundancy adds.
Use the tool →Related services and guides
Want a right-sized CGNAT, or a way out with IPv6?
We design your CGNAT, subscriber logging and IPv6 migration so you stop depending on it.
