How to Calculate Network Addresses with ipcalc

The math behind IP addresses is convoluted. Our nice IPv4 addresses start out as 32-bit binary numbers, which are then converted to base 10 numbers in four 8-bit fields. Decimal numbers are easier to manage than long binary strings; still, calculating address ranges, netmasks, and subnets is a bit difficult and error-prone, except for the brainiacs who can do binary conversions in their heads. For the rest of us, meet ipcalc and ipv6calc.

ipcalc is for IPv4 networks, and ipv6calc is for IPv6 networks. Today, we’ll play with IPv4, and next week IPv6.

You must understand Classless Inter-Domain Routing (CIDR) as this is fundamental to IP addressing; if you don’t, please look it up. (See Practical Networking for Linux Admins: Real IPv6 for a concise description.)


Run ipcalc with your IP address to see everything you need to know:

$ ipcalc 11000000.10101000.00000000. 10000111Netmask: = 24 11111111.11111111.11111111. 00000000Wildcard: 00000000.00000000.00000000. 11111111=>Network: 11000000.10101000.00000000. 00000000HostMin: 11000000.10101000.00000000. 00000001HostMax: 11000000.10101000.00000000. 11111110Broadcast: 11000000.10101000.00000000. 11111111Hosts/Net: 254 Class C, Private Internet

What I especially like about ipcalc is seeing the binary form of IP addresses, which clearly shows what netmasks do. These don’t make much sense in dotted decimal notation, but in binary they are as clear as can be. A mask covers things, and in this example it’s plain that the 24-bit netmask covers the first three quads. The first three quads make up the network ID, and the final quad is the host address.

ipcalc tells us the network range (, the first and last available host addresses ( and, and that it’s a Class C private network. Each 8-bit field contains values ranging from 0-255. The very first value in the host field, 0, is always reserved as the network address, and the last value, 255, is always reserved for the broadcast address, so you cannot use these as host addresses. ipcalc reports only available addresses, so in this example, that is 254 instead of 256.

Classful Networking

IPv4 networks have five classes: A, B, and C, which we use all the time, D, the multicast class, and E, which is experimental and reserved for future use. With the advent of IPv6, it’s likely class E will never be used. A picture is worth a thousand words, and this table from Classful network on Wikipedia shows the relationship from decimal to binary.

In the following table:

  • n indicates a bit used for the network ID.
  • H indicates a bit used for the host ID.
  • X indicates a bit without a specified purpose.
Class A 0. 0. 0. 0 = 00000000.00000000.00000000.00000000127.255.255.255 = 01111111.11111111.11111111.11111111 0nnnnnnn.HHHHHHHH.HHHHHHHH.HHHHHHHHClass B128. 0. 0. 0 = 10000000.00000000.00000000.00000000191.255.255.255 = 10111111.11111111.11111111.11111111 10nnnnnn.nnnnnnnn.HHHHHHHH.HHHHHHHHClass C192. 0. 0. 0 = 11000000.00000000.00000000.00000000223.255.255.255 = 11011111.11111111.11111111.11111111 110nnnnn.nnnnnnnn.nnnnnnnn.HHHHHHHHClass D224. 0. 0. 0 = 11100000.00000000.00000000.00000000239.255.255.255 = 11101111.11111111.11111111.11111111 1110XXXX.XXXXXXXX.XXXXXXXX.XXXXXXXXClass E240. 0. 0. 0 = 11110000.00000000.00000000.00000000255.255.255.255 = 11111111.11111111.11111111.11111111 1111XXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX

In the first three classes, note the leading bits, which are the most significant bits. Class A has a leading bit of 0, which means the following 7 bits comprise the network ID, 0-127. Class B has 10, which converts to 128-191, and Class C is 110, 192-223.

You can calculate the total size of each class from the number of leading bits:

$ ipcalc [...]Hosts/Net: 2147483646 Class A, In Part Private Internet$ ipcalc[...]Hosts/Net: 1073741822 Class B, In Part APIPA$ ipcalc[...]Hosts/Net: 536870910 Class C, In Part Private Internet

APIPA is Automatic Private IP Addressing, the range from through This is used primarily in Windows networks; DHCP clients automatically assign themselves one of these addresses when there is no DHCP server.

Private Networks

Most of us are familiar with the private IPv4 network ranges, because we can use these freely on our LANs without requesting globally unique address allocations from a service provider.

Class A B C

Plug any of these into ipcalc and see what it tells you.


Thanks to CIDR, we can finely slice and dice A, B, or C networks into multiple subnets, and ipcalc makes subnetting easy. Suppose you want to make two Class B subnets; just tell ipcalc the network segment you want to divide and how many hosts in each segment. In this example we want 15 hosts in each subnet:

$ ipcalc -s 15 15Address: 10101100.00010000.00000001. 00000000Netmask: = 24 11111111.11111111.11111111. 00000000Wildcard: 00000000.00000000.00000000. 11111111=>Network: 10101100.00010000.00000001. 00000000HostMin: 10101100.00010000.00000001. 00000001HostMax: 10101100.00010000.00000001. 11111110Broadcast: 10101100.00010000.00000001. 11111111Hosts/Net: 254 Class B, Private Internet1. Requested size: 15 hostsNetmask: = 27 11111111.11111111.11111111.111 00000Network: 10101100.00010000.00000001.000 00000HostMin: 10101100.00010000.00000001.000 00001HostMax: 10101100.00010000.00000001.000 11110Broadcast: 10101100.00010000.00000001.000 11111Hosts/Net: 30 Class B, Private Internet2. Requested size: 15 hostsNetmask: = 27 11111111.11111111.11111111.111 00000Network: 10101100.00010000.00000001.001 00000HostMin: 10101100.00010000.00000001.001 00001HostMax: 10101100.00010000.00000001.001 11110Broadcast: 10101100.00010000.00000001.001 11111Hosts/Net: 30 Class B, Private InternetNeeded size: 64 addresses.Used network:

I think that is pretty darned fabulous. Why does the example use Trial and error: I ran ipcalc with different CIDR ranges until I found one close to the size I needed. = 254 hosts per subnet, leaving room to grow.

16,777,214 Loopback Addresses

Did you know that the loopback address range is an entire Class A 8-bit range?

$ ipcalc 01111111. 00000000.00000000.00000000Netmask: = 8 11111111. 00000000.00000000.00000000Wildcard: 00000000. 11111111.11111111.11111111=>Network: 01111111. 00000000.00000000.00000000HostMin: 01111111. 00000000.00000000.00000001HostMax: 01111111. 11111111.11111111.11111110Broadcast: 01111111. 11111111.11111111.11111111Hosts/Net: 16777214 Class A, Loopback

Try it for yourself — you can ping any address in this range. ping localhost returns because most Linux distributions configure this in /etc/hosts.

Sorry, but that’s all the fun we can have today. Come back next week to learn how to tame those massive unwieldy IPv6 addresses with ipv6calc.

Learn more about Linux through the free “Introduction to Linux” course from The Linux Foundation and edX.