Use ipcalc to compute subnets

When creating VPCs, you need to divide your CIDR range into subnets.

The best tool I’ve found for the job is ipcalc.

ipcalc can be installed via homebrew on macOS.

Most VPC CIDR blocks are /16, so if you do something like:

➜  ~ ipcalc 10.0.0.0/16
Address:   10.0.0.0             00001010.00000000. 00000000.00000000
Netmask:   255.255.0.0 = 16     11111111.11111111. 00000000.00000000
Wildcard:  0.0.255.255          00000000.00000000. 11111111.11111111
=>
Network:   10.0.0.0/16          00001010.00000000. 00000000.00000000
HostMin:   10.0.0.1             00001010.00000000. 00000000.00000001
HostMax:   10.0.255.254         00001010.00000000. 11111111.11111110
Broadcast: 10.0.255.255         00001010.00000000. 11111111.11111111
Hosts/Net: 65534                 Class A, Private Internet

Then, if you want to divide up the /16 space to /20, you can do this:

➜  ~ ipcalc 10.0.0.0/16 /20
Address:   10.0.0.0             00001010.00000000. 00000000.00000000
Netmask:   255.255.0.0 = 16     11111111.11111111. 00000000.00000000
Wildcard:  0.0.255.255          00000000.00000000. 11111111.11111111
=>
Network:   10.0.0.0/16          00001010.00000000. 00000000.00000000
HostMin:   10.0.0.1             00001010.00000000. 00000000.00000001
HostMax:   10.0.255.254         00001010.00000000. 11111111.11111110
Broadcast: 10.0.255.255         00001010.00000000. 11111111.11111111
Hosts/Net: 65534                 Class A, Private Internet

Subnets after transition from /16 to /20

Netmask:   255.255.240.0 = 20   11111111.11111111.1111 0000.00000000
Wildcard:  0.0.15.255           00000000.00000000.0000 1111.11111111

 1.
Network:   10.0.0.0/20          00001010.00000000.0000 0000.00000000
HostMin:   10.0.0.1             00001010.00000000.0000 0000.00000001
HostMax:   10.0.15.254          00001010.00000000.0000 1111.11111110
Broadcast: 10.0.15.255          00001010.00000000.0000 1111.11111111
Hosts/Net: 4094                  Class A, Private Internet

 2.
Network:   10.0.16.0/20         00001010.00000000.0001 0000.00000000
HostMin:   10.0.16.1            00001010.00000000.0001 0000.00000001
HostMax:   10.0.31.254          00001010.00000000.0001 1111.11111110
Broadcast: 10.0.31.255          00001010.00000000.0001 1111.11111111
Hosts/Net: 4094                  Class A, Private Internet

 3.
Network:   10.0.32.0/20         00001010.00000000.0010 0000.00000000
HostMin:   10.0.32.1            00001010.00000000.0010 0000.00000001
HostMax:   10.0.47.254          00001010.00000000.0010 1111.11111110
Broadcast: 10.0.47.255          00001010.00000000.0010 1111.11111111
Hosts/Net: 4094                  Class A, Private Internet

 4.
Network:   10.0.48.0/20         00001010.00000000.0011 0000.00000000
HostMin:   10.0.48.1            00001010.00000000.0011 0000.00000001
HostMax:   10.0.63.254          00001010.00000000.0011 1111.11111110
Broadcast: 10.0.63.255          00001010.00000000.0011 1111.11111111
Hosts/Net: 4094                  Class A, Private Internet

...output redacted

Join the 80/20 DevOps Newsletter

If you're an engineering leader or developer, you should subscribe to my 80/20 DevOps Newsletter. Give me 1 minute of your day, and I'll teach you essential DevOps skills. I cover topics like Kubernetes, AWS, Infrastructure as Code, and more.

Not sure yet? Check out the archive.

Unsubscribe at any time.