Calculate the minimum prefix length for an IPv4 subnet based on a desired number of host accounting for broadcast and network addresses
minPrefixLength(8) => 28
$ npm install --save min-prefix-length
const minPrefixLength = require('min-prefix-length');
const prefix = minPrefixLength(28);
const CIDR = `192.168.1.0/${prefix}`
console.log(CIDR)
// => "192.168.1.0/28"
Returns the minimum prefix length needed to support n of hosts accounting for the network and broadcast address
n number of desired hosts
min-host-bits - 💻 Calculate minimum host bits needed for desired number of hosts
ip-class - 🔠 Return the classful network class (A, B, C, D, E) of an IPv4 address
MIT © Brandon Him