PHPackages                             rupadana/ipv4-calculator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rupadana/ipv4-calculator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rupadana/ipv4-calculator
========================

Network calculator for subnet mask and other classless (CIDR) network information.

v1.0.0(2y ago)03MITPHPPHP &gt;=7.2.0

Since Sep 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/rupadana/ipv4-calculator)[ Packagist](https://packagist.org/packages/rupadana/ipv4-calculator)[ Docs](https://github.com/rupadana/ipv4-calculator)[ RSS](/packages/rupadana-ipv4-calculator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

IPv4 Calculator (PHP)
=====================

[](#ipv4-calculator-php)

Network calculator for subnet mask and other classless (CIDR) network information.

[![Coverage Status](https://camo.githubusercontent.com/58a46f789a2865e1dc25c75253f1314be25f9aa02ca663aaaa075c78dc6fd8d0/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d61726b726f676f79736b692f697076342d7375626e65742d63616c63756c61746f722d7068702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/markrogoyski/ipv4-subnet-calculator-php?branch=master)[![License](https://camo.githubusercontent.com/11f0e9c92718bfe2c34420fdc7d615c108bc177c1e6cd7149f0d88acc53a9562/68747470733a2f2f706f7365722e707567782e6f72672f6d61726b726f676f79736b692f6d6174682d7068702f6c6963656e7365)](https://packagist.org/packages/markrogoyski/ipv4-subnet-calculator-php)

Features
--------

[](#features)

Given an IP address and CIDR network size, it calculates the network information and provides all-in-one aggregated reports.

### Calculations

[](#calculations)

- IP address
- Network size
- Subnet mask
- Network portion
- Host portion
- Number of IP addresses in the network
- Number of addressable hosts in the network
- IP address range
- Broadcast address
- Min and max host
- All IP addresses
- Is an IP address in the subnet
- IPv4 ARPA domain

Provides each data in dotted quads, hexadecimal, and binary formats, as well as array of quads.

### Aggregated Network Calculation Reports

[](#aggregated-network-calculation-reports)

- Associative array
- JSON
- String
- Printed to STDOUT

### Standard Interfaces

[](#standard-interfaces)

- JsonSerializable

Setup
-----

[](#setup)

Add the library to your `composer.json` file in your project:

```
{
  "require": {
      "markrogoyski/ipv4-subnet-calculator": "4.*"
  }
}
```

Use [composer](http://getcomposer.org) to install the library:

```
$ php composer.phar install
```

Composer will install IPv4 Subnet Calculator inside your vendor folder. Then you can add the following to your .php files to the use library with Autoloading.

```
require_once(__DIR__ . '/vendor/autoload.php');
```

Alternatively, use composer on the command line to require and install IPv4 SubnetCalculator:

```
$ php composer.phar require markrogoyski/ipv4-subnet-calculator:4.*

```

### Minimum Requirements

[](#minimum-requirements)

- PHP 7.2

Note: For PHP 5.5 through 7.1, use v3.0 (`markrogoyski/ipv4-subnet-calculator:3.*`)

Usage
-----

[](#usage)

### Create New SubnetCalculator

[](#create-new-subnetcalculator)

```
// For network 192.168.112.203/23
$sub = new IPv4\SubnetCalculator('192.168.112.203', 23);
```

### Various Network Information

[](#various-network-information)

```
$numbeIpAddresses     = $sub->getNumberIPAddresses();      // 512
$numberHosts          = $sub->getNumberAddressableHosts(); // 510
$addressRange         = $sub->getIPAddressRange();         // [192.168.112.0, 192.168.113.255]
$addressableHostRange = $sub->getAddressableHostRange();   // [192.168.112.1, 192.168.113.254]
$networkSize          = $sub->getNetworkSize();            // 23
$broadcastAddress     = $sub->getBroadcastAddress();       // 192.168.113.255
```

### IP Address

[](#ip-address)

```
$ipAddress        = $sub->getIPAddress();        // 192.168.112.203
$ipAddressQuads   = $sub->getIPAddressQuads();   // [192, 168, 112, 203]
$ipAddressHex     = $sub->getIPAddressHex();     // C0A870CB
$ipAddressBinary  = $sub->getIPAddressBinary();  // 11000000101010000111000011001011
$ipAddressInteger = $sub->getIPAddressInteger(); // 3232264395;
```

### Subnet Mask

[](#subnet-mask)

```
$subnetMask        = $sub->getSubnetMask();        // 255.255.254.0
$subnetMaskQuads   = $sub->getSubnetMaskQuads();   // [255, 255, 254, 0]
$subnetMaskHex     = $sub->getSubnetMaskHex();     // FFFFFE00
$subnetMaskBinary  = $sub->getSubnetMaskBinary();  // 11111111111111111111111000000000
$subnetMaskInteger = $sub->getSubnetMaskInteger(); // 4294966784
```

### Network Portion

[](#network-portion)

```
$network        = $sub->getNetworkPortion();        // 192.168.112.0
$networkQuads   = $sub->getNetworkPortionQuads();   // [192, 168, 112, 0]
$networkHex     = $sub->getNetworkPortionHex();     // C0A87000
$networkBinary  = $sub->getNetworkPortionBinary();  // 11000000101010000111000000000000
$networkInteger = $sub->getNetworkPortionInteger(); // 3232264192
```

### Host Portion

[](#host-portion)

```
$host        = $sub->getHostPortion();        // 0.0.0.203
$hostQuads   = $sub->getHostPortionQuads();   // [0, 0, 0, 203]
$hostHex     = $sub->getHostPortionHex();     // 000000CB
$hostBinary  = $sub->getHostPortionBinary();  // 00000000000000000000000011001011
$hostInteger = $sub->getHostPortionInteger(); // 203
```

### Min and Max Host

[](#min-and-max-host)

```
$minHost        = $sub->getMinHost();        // 192.168.112.1
$minHostQuads   = $sub->getMinHostQuads();   // [192, 168, 112, 1]
$minHostHex     = $sub->getMinHostHex();     // C0A87001
$minHostBinary  = $sub->getMinHostBinary();  // 11000000101010000111000000000001
$minHostInteger = $sub->getMinHostInteger(); // 3232264193

$maxHost        = $sub->getMaxHost();        // 192.168.113.254
$maxHostQuads   = $sub->getMaxHostQuads();   // [192, 168, 113, 254]
$maxHostHex     = $sub->getMaxHostHex();     // C0A871FE
$maxHostBinary  = $sub->getMaxHostBinary();  // 11000000101010000111000111111110
$maxHostInteger = $sub->getMaxHostInteger(); // 3232264702
```

### All IP Addresses

[](#all-ip-addresses)

```
foreach ($sub->getAllIPAddresses() as $ipAddress) {
    echo $ipAddress;
}

foreach ($sub->getAllHostIPAddresses() as $hostAddress) {
    echo $hostAddress;
}
```

### Is IP Address in Subnet

[](#is-ip-address-in-subnet)

```
$boolTrue  = $sub->isIPAddressInSubnet('192.168.112.5');
$boolFalse = $sub->isIPAddressInSubnet('192.168.111.5');
```

### Reverse DNS Lookup (ARPA Domain)

[](#reverse-dns-lookup-arpa-domain)

```
$ipv4ArpaDomain = $sub->getIPv4ArpaDomain(); // 203.112.168.192.in-addr.arpa
```

### Reports

[](#reports)

#### Printed Report

[](#printed-report)

```
$sub->printSubnetReport();
/*
192.168.112.203/23           Quads      Hex                           Binary    Integer
------------------ --------------- -------- -------------------------------- ----------
IP Address:        192.168.112.203 C0A870CB 11000000101010000111000011001011 3232264395
Subnet Mask:         255.255.254.0 FFFFFE00 11111111111111111111111000000000 4294966784
Network Portion:     192.168.112.0 C0A87000 11000000101010000111000000000000 3232264192
Host Portion:            0.0.0.203 000000CB 00000000000000000000000011001011        203

Number of IP Addresses:      512
Number of Addressable Hosts: 510
IP Address Range:            192.168.112.0 - 192.168.113.255
Broadcast Address:           192.168.113.255
Min Host:                    192.168.112.1
Max Host:                    192.168.113.254
IPv4 ARPA Domain:            203.112.168.192.in-addr.arpa
*/
```

#### Array Report

[](#array-report)

```
$sub->getSubnetArrayReport();
/*
(
    [ip_address_with_network_size] => 192.168.112.203/23
    [ip_address] => Array
        (
            [quads] => 192.168.112.203
            [hex] => C0A870CB
            [binary] => 11000000101010000111000011001011
            [integer] => 3232264395
        )

    [subnet_mask] => Array
        (
            [quads] => 255.255.254.0
            [hex] => FFFFFE00
            [binary] => 11111111111111111111111000000000
            [integer] => 4294966784
        )

    [network_portion] => Array
        (
            [quads] => 192.168.112.0
            [hex] => C0A87000
            [binary] => 11000000101010000111000000000000
            [integer] => 3232264192
        )

    [host_portion] => Array
        (
            [quads] => 0.0.0.203
            [hex] => 000000CB
            [binary] => 00000000000000000000000011001011
            [integer] => 203
        )

    [network_size] => 23
    [number_of_ip_addresses] => 512
    [number_of_addressable_hosts] => 510
    [ip_address_range] => Array
        (
            [0] => 192.168.112.0
            [1] => 192.168.113.255
        )

    [broadcast_address] => 192.168.113.255
    [min_host] => 192.168.112.1
    [max_host] => 192.168.113.254
    [ipv4_arpa_domain] => 203.112.168.192.in-addr.arpa
)
*/
```

#### JSON Report

[](#json-report)

```
$sub->getSubnetJSONReport();
/*
{
    "ip_address_with_network_size": "192.168.112.203\/23",
    "ip_address": {
        "quads": "192.168.112.203",
        "hex": "C0A870CB",
        "binary": "11000000101010000111000011001011",
        "integer": 3232264395
    },
    "subnet_mask": {
        "quads": "255.255.254.0",
        "hex": "FFFFFE00",
        "binary": "11111111111111111111111000000000",
        "integer": 4294966784
    },
    "network_portion": {
        "quads": "192.168.112.0",
        "hex": "C0A87000",
        "binary": "11000000101010000111000000000000",
        "integer": 3232264192
    },
    "host_portion": {
        "quads": "0.0.0.203",
        "hex": "000000CB",
        "binary": "00000000000000000000000011001011",
        "integer": 203
    },
    "network_size": 23,
    "number_of_ip_addresses": 512,
    "number_of_addressable_hosts": 510,
    "ip_address_range": [
        "192.168.112.0",
        "192.168.113.255"
    ],
    "broadcast_address": "192.168.113.255",
    "min_host": "192.168.112.1",
    "max_host": "192.168.113.254",
    "ipv4_arpa_domain": "203.112.168.192.in-addr.arpa"
}
*/
```

#### String Report

[](#string-report)

```
$stringReport = $sub->getPrintableReport();
/*
192.168.112.203/23           Quads      Hex                           Binary    Integer
------------------ --------------- -------- -------------------------------- ----------
IP Address:        192.168.112.203 C0A870CB 11000000101010000111000011001011 3232264395
Subnet Mask:         255.255.254.0 FFFFFE00 11111111111111111111111000000000 4294966784
Network Portion:     192.168.112.0 C0A87000 11000000101010000111000000000000 3232264192
Host Portion:            0.0.0.203 000000CB 00000000000000000000000011001011        203

Number of IP Addresses:      512
Number of Addressable Hosts: 510
IP Address Range:            192.168.112.0 - 192.168.113.255
Broadcast Address:           192.168.113.255
Min Host:                    192.168.112.1
Max Host:                    192.168.113.254
IPv4 ARPA Domain:            203.112.168.192.in-addr.arpa
*/
```

#### Printing - String Representation

[](#printing---string-representation)

```
print($sub);
/*
192.168.112.203/23           Quads      Hex                           Binary    Integer
------------------ --------------- -------- -------------------------------- ----------
IP Address:        192.168.112.203 C0A870CB 11000000101010000111000011001011 3232264395
Subnet Mask:         255.255.254.0 FFFFFE00 11111111111111111111111000000000 4294966784
Network Portion:     192.168.112.0 C0A87000 11000000101010000111000000000000 3232264192
Host Portion:            0.0.0.203 000000CB 00000000000000000000000011001011        203

Number of IP Addresses:      512
Number of Addressable Hosts: 510
IP Address Range:            192.168.112.0 - 192.168.113.255
Broadcast Address:           192.168.113.255
Min Host:                    192.168.112.1
Max Host:                    192.168.113.254
IPv4 ARPA Domain:            203.112.168.192.in-addr.arpa
*/
```

### Standard Interfaces

[](#standard-interfaces-1)

#### JsonSerializable

[](#jsonserializable)

```
$json = \json_encode($sub);
```

Unit Tests
----------

[](#unit-tests)

```
$ cd tests
$ phpunit
```

[![Coverage Status](https://camo.githubusercontent.com/58a46f789a2865e1dc25c75253f1314be25f9aa02ca663aaaa075c78dc6fd8d0/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d61726b726f676f79736b692f697076342d7375626e65742d63616c63756c61746f722d7068702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/markrogoyski/ipv4-subnet-calculator-php?branch=master)

Standards
---------

[](#standards)

IPv4 Subnet Calculator (PHP) conforms to the following standards:

- PSR-1 - Basic coding standard ()
- PSR-4 - Autoloader ()
- PSR-12 - Extended coding style guide ()

License
-------

[](#license)

IPv4 Subnet Calculator (PHP) is licensed under the MIT License.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

978d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/29f8343484c8567d8f24dcf1e4fb4978f2ac8442e90448c6405a32ba511ee246?d=identicon)[rupadana](/maintainers/rupadana)

---

Top Contributors

[![rupadana](https://avatars.githubusercontent.com/u/34137674?v=4)](https://github.com/rupadana "rupadana (3 commits)")

---

Tags

addressIPnetworkcalculatoripv4cidrsubnet

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rupadana-ipv4-calculator/health.svg)

```
[![Health](https://phpackages.com/badges/rupadana-ipv4-calculator/health.svg)](https://phpackages.com/packages/rupadana-ipv4-calculator)
```

###  Alternatives

[markrogoyski/ipv4-subnet-calculator

Network calculator for subnet mask and other classless (CIDR) network information.

177813.7k6](/packages/markrogoyski-ipv4-subnet-calculator)[s1lentium/iptools

PHP Library for manipulating network addresses (IPv4 and IPv6)

2446.2M24](/packages/s1lentium-iptools)[mlocati/ip-lib

Handle IPv4, IPv6 addresses and ranges

3126.4M44](/packages/mlocati-ip-lib)[jaaulde/php-ipv4

PHP classes for working with IPV4 addresses and networks.

1034.6k](/packages/jaaulde-php-ipv4)[longman/ip-tools

PHP IP Tools for manipulation with IPv4 and IPv6

147245.6k6](/packages/longman-ip-tools)[rlanvin/php-ip

IPv4/IPv6 manipulation library for PHP

180738.8k11](/packages/rlanvin-php-ip)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
