How to Use the ipcalc Command to Calculate Network Subnets in Linux

What is ipcalc?

Configuring static IP addresses, setting up DHCP scopes, or designing firewall rules requires a solid understanding of subnetting. Calculating subnet masks, broadcast addresses, and usable host ranges manually is prone to human error, especially when dealing with complex CIDR notations like /27 or /23.

ipcalc is a lightweight, incredibly useful command-line utility in Linux designed to perform these calculations instantly. You provide it with an IP address and a subnet mask, and it outputs a neatly formatted, color-coded breakdown of the network.

Step 1: Install ipcalc

While some distributions include it by default, you may need to install it manually.

On Debian, Ubuntu, or Linux Mint:

sudo apt update && sudo apt install ipcalc

On RHEL, CentOS, or Fedora:

sudo dnf install ipcalc

Step 2: Calculate a Basic Subnet

To use the utility, simply type the command followed by an IP address and its subnet mask. You can provide the mask in traditional dotted-decimal format or modern CIDR notation.

For example, if you want to calculate the network details for 192.168.1.50 on a standard /24 subnet, run:

ipcalc 192.168.1.50/24

The command will instantly output a visual table containing critical networking data:

  • Address: The specific IP address you entered (with its binary translation).
  • Netmask: The subnet mask (e.g., 255.255.255.0).
  • Network: The base network address (e.g., 192.168.1.0).
  • HostMin: The very first usable IP address you can assign to a device in this subnet (e.g., 192.168.1.1).
  • HostMax: The very last usable IP address you can assign (e.g., 192.168.1.254).
  • Broadcast: The broadcast address used to send packets to all devices on the subnet (e.g., 192.168.1.255).
  • Hosts/Net: The total number of usable IP addresses available in this subnet (e.g., 254).

Step 3: Deconstruct Complex Subnets

The true value of ipcalc becomes obvious when dealing with non-standard subnets. If a network engineer tells you to put a server on the 10.5.20.0/27 subnet, you might struggle to immediately know the broadcast address or the valid host range.

Simply run:

ipcalc 10.5.20.0/27

The output immediately tells you:

  • Netmask: 255.255.255.224
  • HostMin: 10.5.20.1
  • HostMax: 10.5.20.30
  • Broadcast: 10.5.20.31
  • Total Hosts: 30

You now know exactly which 30 IP addresses are safe to assign to your virtual machines without causing an IP conflict with an adjacent subnet.

Step 4: Suppress Binary Output for Scripts

By default, ipcalc outputs the binary representation (0s and 1s) of the IP addresses alongside the decimal version. This is excellent for learning how subnetting mathematically works on a bitwise level.

However, if you are just looking for quick answers or want to pipe the output into a bash script, the binary data takes up unnecessary screen space. You can suppress the binary output by using the -b (no binary) flag:

ipcalc -b 192.168.1.50/24

This provides a clean, easily readable summary of the network parameters.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.