
ipcalc Command in Linux
The ipcalc command in Linux calculates the IP information of a given host. It offers various options to specify what data it displays to the standard output. Multiple options can also be specified.
Managing a network requires dealing with subnetting. It involves complex mathematical calculations. Some administrators can do it quickly, while others may need help from tools. The ipcalc is a handy tool that can easily calculate the address ranges, netmasks, and subnet masks.
Table of Contents
Here is a comprehensive guide to the options available with the ipcalc command −
- Prerequisites to Use ipcalc Command
- Syntax of ipcalc Command
- Options of ipcalc Command
- Examples of ipcalc Command in Linux
Prerequisites to Use ipcalc Command
The ipcalc command may not be installed on Linux by default. To verify, use the following command −
ipcalc --version

If it does not show the command version, then install it using the instructions given below.
To install ipcalc on Ubuntu, Kali Linux, Raspberry Pi OS, Debian, and other Debian-based distributions, use the command given below −
sudo apt install ipcalc
To install it on Arch Linux, use the command given below −
sudo pacman -s ipcalc
To install it on Cent OS, use −
sudo yum install ipcalc
To install ipcalc on Fedora, use the following command −
sudo dnf install ipcalc
Syntax of ipcalc Command
The syntax of the Linux ipcalc command is as follows −
ipcalc [options] [address]/[prefix | netmask]
The [options] field is used to specify the option to change the command's behavior. The [address] field is used to specify the IP address. The [prefix | netmask] is used to specify the CIDR or netmask. Note that either a CIDR prefix or netmask can be used.
Options of ipcalc Command
The options of the ipcalc command are listed below −
Flags | Options | Description |
---|---|---|
-b | --nobinary | To display only non-binary output |
-c | --color | To display output in ANSI colors (default) |
--class | To display only bit-count-mask only | |
-h | --html | To generate the output in HTML format |
-n | --nocolor | To disable color output |
-s | --split | To split the given IP range into subnets of specified sizes n1, n2 and n3 |
-r | --range | To deaggregate or break down a range of IP addresses into smaller subnets |
-v | --version | To display the version of the command |
--help | To display help related to the command |
Examples of ipcalc Command in Linux
This section demonstrates the usage of the Linux ipcalc command with examples −
Displaying the IP Address Information
To display the IP address information, use the ipcalc command with the IP address and CIDR prefix −
ipcalc 192.168.1.100/24

The above command will display network-related details like network address, broadcast address, and netmask.
Displaying Bit Count Mask Only
To display the bit count mask only, use the --class option −
ipcalc --class 192.168.1.100

Generating the HTML Output
To generate the HTML output, use the -h or --html option to generate the HTML output −
ipcalc -h 192.168.1.100/24

It is useful to embed the results into a webpage or to process the output further in an HTML environment.
To save the HTML output to a file, use the redirection operator (>).
ipcalc -h 192.168.1.100/24 > network.html
Splitting Network into Specified Sizes
To split the network into n1, n2, and n3 sizes, use the -s or --split option −
ipcalc -s 20 30 80 192.168.1.100/24

The above command will split the network address (192.168.1.100) into subnets with 20, 30, and 80 hosts as shown in the output image.
Deaggregating the Address Range
To deaggregate an address range, use the -r or --range option −
ipcalc -r 192.168.1.100-192.168.1.255

This command will break the address range 192.168.1.100 to 192.168.1.255 into smaller, non-overlapping subnets.
Suppressing Binary Output
By default, the ipcalc command displays the binary output, to suppress binary output, use the -b or --bitwise option −
ipcalc -b 192.168.1.100/24

Displaying Output without ANSI Color
By default, the ipcalc command displays output in ANSI color. To disable it, use the -n or --nocolor option −
ipcalc -n 192.168.1.100/24

Displaying Help
To display help related to the ipcalc command, run the command with the --help option −
ipcalc --help
Conclusion
The ipcalc command in Linux is an essential tool for network administrators to simplify subnet calculations and IP address management. It allows the display of detailed information about IP addresses, subnet masks, and network configurations. The command can be used to split networks into smaller subnets, deaggregate address ranges, and generate output in different formats, such as binary or HTML.
From validating IP addresses to managing network ranges and displaying results without color or binary output, ipcalc is a powerful tool that helps automate and simplify complex subnetting calculations. It saves time and reduces errors.
In this tutorial, we explained the ipcalc command, its installation, syntax, options, and usage in Linux with examples.