TypeScript icon, indicating that this package has built-in type declarations

1.3.2 • Public • Published


ipv4 and ipv6 address and cidr range utilities


To install npm package, run the following in your project:

npm install cidr-block

or if you're using yarn instead of npm

yarn add cidr-block

The package is written completely in TypeScript and exports all of it's types automatically, meaning you don't need to install any additional @types typings.

Getting Started

Start by defining a cidr range

import { ipv4 as ip } from 'cidr-block'

const myCidr = ip.cidr('')

To get the next logical cidr block

console.log(myCidr.nextBlock().toString()) //

All cidr-block functions and methods are immutable, meaning a new instance will always be returned instead of trying to modify the current value.

Once you have a cidr, you have access to all of it's related utilities:

myCidr.netmask //
myCidr.firstUsableIp // (remember that methods act immutable, so this is still at
myCidr.lastUsableIp //
myCidr.includes(ip.address('')) // true

Documentation and API Reference

The full documentation and API reference can be found at


Q: Why are the imports in all the example code like that?

A: The imports in all example code are formatted as the following:

// esm
import { ipv4 as ip } from 'cidr-block'
// commonjs
const { ipv4: ip } = require('cidr-block')

While you don't have to follow this convention, the API is design like this on purpose to help speed up a refactoring of ipv4 to ipv6, as you would only need to change the number on the import.

Package Sidebar


npm i cidr-block

Weekly Downloads






Unpacked Size

61.2 kB

Total Files


Last publish


  • brandonburrus