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.

If you read this far, tweet to the author to show them you care. Tweet a thanks
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.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

4 thoughts on “How to Calculate IP Subnet Address with ipcalc Tool”

  1. 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
    
    Reply
  2. 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.

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

      Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.