How to Calculate IP Subnet Address with ipcalc Tool

When managing a network, you will undoubtedly need to deal with subnetting. Some network administrators are able to do the binary math quite quickly in their head, to determine the subnet mask. However, others may need some help and this is where the ipcalc tool comes in handy.

Read Also: A Linux Sysadmin’s Guide to Network Management, Troubleshooting and Debugging

Ipcalc actually does a lot more – it takes an IP address and netmask and provides the resulting broadcast, network, Cisco wildcard mask, and host range. You can also use it as a teaching tool to present subnetting results in an easy to understand binary values.

Some of the uses of ipcalc are:

  • Validate IP address
  • Show calculated broadcast address
  • Display hostname determined via DNS
  • Display network address or prefix

How to install ipcalc in Linux

To install ipcalc, simply run one of the commands below, based on the Linux distribution you are using.

$ sudo apt install ipcalc  

The ipcalc package should be installed automatically under CentOS/RHEL/Fedora and it is part of the initscripts package, but if for some reason it is missing, you can install it by using:

# yum install initscripts     #RHEL/CentOS
# dnf install initscripts     #Fedora

How to Use ipcalc in Linux

Below you can see some examples of using ipcalc.

Get information about the network address:

# ipcalc 192.168.20.0
Sample Output
Address:   192.168.20.0         11000000.10101000.00010100. 00000000
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111
=>
Network:   192.168.20.0/24      11000000.10101000.00010100. 00000000
HostMin:   192.168.20.1         11000000.10101000.00010100. 00000001
HostMax:   192.168.20.254       11000000.10101000.00010100. 11111110
Broadcast: 192.168.20.255       11000000.10101000.00010100. 11111111
Hosts/Net: 254                   Class C, Private Internet

Calculate a subnet for 192.168.20.0/24.

# ipcalc 192.168.20.0/24
Sample Output
Address:   192.168.20.0         11000000.10101000.00010100. 00000000
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111
=>
Network:   192.168.20.0/24      11000000.10101000.00010100. 00000000
HostMin:   192.168.20.1         11000000.10101000.00010100. 00000001
HostMax:   192.168.20.254       11000000.10101000.00010100. 11111110
Broadcast: 192.168.20.255       11000000.10101000.00010100. 11111111
Hosts/Net: 254                   Class C, Private Internet

Calculate a single subnet with 10 hosts:

# ipcalc  192.168.20.0 -s 10
Sample Output
Address:   192.168.20.0         11000000.10101000.00010100. 00000000
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111
=>
Network:   192.168.20.0/24      11000000.10101000.00010100. 00000000
HostMin:   192.168.20.1         11000000.10101000.00010100. 00000001
HostMax:   192.168.20.254       11000000.10101000.00010100. 11111110
Broadcast: 192.168.20.255       11000000.10101000.00010100. 11111111
Hosts/Net: 254                   Class C, Private Internet

1. Requested size: 10 hosts
Netmask:   255.255.255.240 = 28 11111111.11111111.11111111.1111 0000
Network:   192.168.20.0/28      11000000.10101000.00010100.0000 0000
HostMin:   192.168.20.1         11000000.10101000.00010100.0000 0001
HostMax:   192.168.20.14        11000000.10101000.00010100.0000 1110
Broadcast: 192.168.20.15        11000000.10101000.00010100.0000 1111
Hosts/Net: 14                    Class C, Private Internet

Needed size:  16 addresses.
Used network: 192.168.20.0/28
Unused:
192.168.20.16/28
192.168.20.32/27
192.168.20.64/26
192.168.20.128/25

If you want to suppress the binary output, you can use the -b option as shown.

# ipcalc -b 192.168.20.100
Sample Output
Address:   192.168.20.100
Netmask:   255.255.255.0 = 24
Wildcard:  0.0.0.255
=>
Network:   192.168.20.0/24
HostMin:   192.168.20.1
HostMax:   192.168.20.254
Broadcast: 192.168.20.255
Hosts/Net: 254                   Class C, Private Internet

To find more about the ipcalc usage, you can use:

# ipcalc --help
# man ipcalc

You can find the official ipcalc website at http://jodies.de/ipcalc.

Conclusion

This was a simple tutorial, showing how to use ipcalc tool with some basic examples. If you have any questions or advice, make sure to submit them in the comment section below.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Marin Todorov

I am a bachelor in computer science and a Linux Foundation Certified System Administrator. Currently working as a Senior Technical support in the hosting industry. In my free time I like testing new software and inline skating.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

4 Responses

  1. spezialist says:

    I agree, a good tutorial, but there is one sad nuance: under RHEL/CentOS, the functionality of the ipcalc utility is very limited :-(. Because of this, all the above mentioned practical examples of using the ipcalc utility are not applicable under RHEL/CentOS.

    # rpm -q initscripts
    
    initscripts-9.49.46-1.el7.x86_64
    
    # ipcalc 192.168.20.0/24
    
    Usage: ipcalc [OPTION...]
      -c, --check         Validate IP address for specified address family
      -4, --ipv4          IPv4 address family (default)
      -6, --ipv6          IPv6 address family
      -b, --broadcast     Display calculated broadcast address
      -h, --hostname      Show hostname determined via DNS
      -m, --netmask       Display default netmask for IP (class A, B, or C)
      -n, --network       Display network address
      -p, --prefix        Display network prefix
      -s, --silent        Don't ever display error messages
    
    Help options:
      -?, --help          Show this help message
      --usage             Display brief usage message
    
  2. Stefan Lasiewski says:

    Great tutorial, thanks. From the comments that I read on Facebook, many people would have benefited from an example that showed a couple of uncommon networks, such as 192.168.20.0/23, instead of a /24.

    Thanks for working on this.

  3. Allwin says:

    Do you have similar tool for windows based machines.

    • Stefan Lasiewski says:

      Download Windows Subsystem for Linux, install Ubuntu, and not only will you get ipcalc but you’ll get Ubuntu’s powerful Bash environment.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.