ipv4 and ipv6 address and cidr range utilities

Usage no npm install needed!

<script type="module">
  import cidrBlock from '';



ipv4 and ipv6 address and cidr range utilities


This package is still in very early stages and should NOT be used in production code!


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:

import { ipv4 as ip } from 'cidr-block'
// or commonjs-style
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.