IPv4 Address Calculator

IP address/mask length:
network address: 192.168.0.0 netmask address: 255.255.255.0
broadcast address: 192.168.0.255 count: 256
reverse name: 0.0.168.192.in-addr.arpa

Preset

current IPv4 addresses 0.0-255.0-255.0-255
class A private IPv4 addresses 10.0-255.0-255.0-255
shared IPv4 addresses 100.64-127.0-255.0-255
loopback IPv4 addresses 127.0-255.0-255.0-255
link-local IPv4 addresses 169.254.0-255.0-255
class B private IPv4 addresses 172.16-31.0-255.0-255
IETF protocol IPv4 addresses 192.0.0.0-255
dual-stack lite IPv4 addresses 192.0.0.0-7
test-net-1 IPv4 addresses 192.0.2.0-255
benchmark IPv4 addresses 198.18-19.0-255.0-255
test-net-2 IPv4 addresses 198.51.100.0-255
deplicated 6to4 IPv4 addresses 192.88.99.0-255
class C private IPv4 addresses 192.168.0-255.0-255
test-net-3 IPv4 addresses 203.0.113.0-255
class D multicast IPv4 addresses 224-239.0-255.0-255.0-255
class E reserved IPv4 addresses 240-255.0-255.0-255.0-255
limited broadcast IPv4 addresses 240-255.0-255.0-255.0-255

IPv4 | IPv6

Javascript

Systax
inet_aton(string)
inet_ntoa(number)
inet_mask(h)
inet_ntoa_reverse(number)
Parameters
string - IPv4 address string
number - IPv4 address number
h - shift-left count
Return value
inet_aton returns 32-bit integer value of IPv4 address.
inet_ntoa returns string of IPv4 address.
inet_mask returns 32-bit integer value of IPv4 netmask address.
inet_ntoa_reverse returns domain name of IPv4 address for reverse lookup.
Usage
inet_aton("0.0.255.255"); // 65535
inet_ntoa(65535); // "0.0.255.255"
inet_mask(8); // -256 == 0xffffff00
inet_ntoa_reverse(65535); // "255.255.0.0.in-addr.arpa"

Calculate

To get the network address 192.168.0.0 and the broadcast address 192.168.0.255 from 192.168.0.1/24, the 32-bit interger \(w\) such as \[ \begin{aligned} w &= \text{255.255.255.255}\\ &= \underbrace{\underbrace{\text{11111111}_{(2)}}_{8\text{-bit}}.\underbrace{\text{11111111}_{(2)}}_{8\text{-bit}}.\underbrace{\text{11111111}_{(2)}}_{8\text{-bit}}.\underbrace{\text{11111111}_{(2)}}_{8\text{-bit}}}_{32\text{-bit}}\\ &= \lnot 0 \land (\text{ffffffff})_{16}. \end{aligned} \] The network address \(n\) and the broadcast address \(b\) are obtained as follows: \[ \begin{aligned} n &= a \land (w \ll (32 - l) \land w) = \text{192.168.0.0},\\ b &= a \lor \lnot(w \ll (32 - l) \land w) = \text{192.168.0.255}, \end{aligned} \] where \(\ll\) means logical shift left, \(a = \text{192.168.0.1}\), \(l = 24\) and \(w\ll (32 - l) = \text{255.255.255.0} \land w\) means the netmask address such as \[ \begin{aligned} h &= 32 - l,\\ w \ll h \land w &= \underbrace{\underbrace{\text{11111111}_{(2)}.\text{11111111}_{(2)}.\text{11111111}_{(2)}}_{l(24)\text{-bit}}.\underbrace{\text{00000000}_{(2)}}_{h(8)\text{-bit}}}_{32\text{-bit}}\\ &= \text{255.255.255.0}. \end{aligned} \] The address \(a\) is represented by the network part and the host part as follows: \[ \begin{aligned} a &= \text{192.168.0.1}/24,\\ &= \underbrace{\text{11000000}_{(2)}.\text{10101000}_{(2)}.\text{00000000}_{(2)}}_{l(24)\text{-bit network part}}.\underbrace{\text{00000001}_{(2)}}_{h(8)\text{-bit host part}}\\ \end{aligned} \]

The number of addresses \(N\) is clearly \[ \begin{aligned} N &= 2^{32 - l} = 2^h\\ &= 2^8 = 256. \end{aligned} \]

Reverse lookup .in-addr.arpa domain name is a 32-bit address with 8 bits each in reverse order and join them with a period in decimal such as \[ \begin{aligned} &\text{``1.0.168.192.in-addr.arpa''}. \end{aligned} \]

Written by Taiji Yamada <taiji@aihara.co.jp>