Utility Coder
← Back to Blog
Networking8 min read

IP Address and Binary Conversion Guide

Convert IP addresses to binary and back. Understand IP addressing, subnetting, and binary representation.

By Andy Pham

IP Address and Binary Conversion Guide

Understanding IP addresses in binary format is essential for networking, subnetting, and security.

IP Address Basics

IPv4 Format

  • 4 octets (bytes)
  • Each octet: 0-255
  • Example: 192.168.1.1
  • Total: 32 bits

Binary Representation

192.168.1.1 in binary:
192 = 11000000
168 = 10101000
1   = 00000001
1   = 00000001

Full: 11000000.10101000.00000001.00000001

Conversion Examples

IP to Binary

function ipToBinary(ip) {
  return ip.split('.')
    .map(octet => parseInt(octet).toString(2).padStart(8, '0'))
    .join('.');
}

ipToBinary('192.168.1.1');
// '11000000.10101000.00000001.00000001'

Binary to IP

function binaryToIp(binary) {
  return binary.split('.')
    .map(octet => parseInt(octet, 2))
    .join('.');
}

binaryToIp('11000000.10101000.00000001.00000001');
// '192.168.1.1'

Subnet Masks

Common Subnet Masks

CIDR Subnet Mask Binary Hosts
/8 255.0.0.0 11111111.00000000... 16M
/16 255.255.0.0 11111111.11111111... 65K
/24 255.255.255.0 11111111...11111111.00000000 254
/32 255.255.255.255 All 1s 1

Calculate Network Address

function getNetworkAddress(ip, mask) {
  const ipParts = ip.split('.').map(Number);
  const maskParts = mask.split('.').map(Number);

  const network = ipParts.map((octet, i) => octet & maskParts[i]);
  return network.join('.');
}

getNetworkAddress('192.168.1.100', '255.255.255.0');
// '192.168.1.0'

Special IP Addresses

Address Purpose
127.0.0.1 Localhost
0.0.0.0 Any address
255.255.255.255 Broadcast
10.x.x.x Private Class A
172.16-31.x.x Private Class B
192.168.x.x Private Class C

IPv6 Preview

IPv6: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
128 bits (vs 32 for IPv4)

Try Our IP Tools

Conclusion

Binary understanding is fundamental for network configuration and troubleshooting.

Share this article