Utility Coder
Back to Blog
converter

IP To Binary

Andy Pham
ip to binary, ip to binary, ip to binary online

Ready to try IP To Binary?

Access the free online tool now - no registration required

Open Tool

IP To Binary - Complete Guide

IP to binary converter transforms dotted-decimal IPv4 addresses into 32-bit binary representation. Shows the underlying bit pattern of IP addresses, essential for understanding subnetting, network masks, and bitwise operations on addresses.

How It Works

Split IP address by dots into four octets. Convert each octet (0-255) to 8-bit binary, padding with leading zeros as needed. Concatenate or format with dots for readability. Example: 192.168.1.1 = 11000000.10101000.00000001.00000001.

Technical Details

Each octet is converted independently: divide by powers of 2, or use toString(2).padStart(8, '0'). Total output is always 32 bits. Big-endian order (most significant octet first). Invalid octets (>255 or <0) should be rejected.

Common Use Cases

  1. Subnet Calculations: See which bits are network vs host portions.
  2. Wildcard Masks: Understand ACL wildcard patterns in binary.
  3. Network Education: Visualize how IP addressing works at bit level.
  4. CIDR Planning: Plan subnet sizes by counting host bits.

Code Examples

IP to Binary Conversion

function ipToBinary(ip, dotted = true) {
  const octets = ip.split('.');
  if (octets.length !== 4) {
    throw new Error('Invalid IP: need 4 octets');
  }

  const binary = octets.map(octet => {
    const num = parseInt(octet, 10);
    if (isNaN(num) || num < 0 || num > 255) {
      throw new Error(`Invalid octet: ${octet}`);
    }
    return num.toString(2).padStart(8, '0');
  });

  return dotted ? binary.join('.') : binary.join('');
}

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

ipToBinary('192.168.1.1', false);
// "11000000101010000000000100000001"

ipToBinary('255.255.255.0');
// "11111111.11111111.11111111.00000000" (/24 mask)

// Calculate network address
function getNetwork(ip, mask) {
  const ipBin = ipToBinary(ip, false);
  const maskBin = ipToBinary(mask, false);
  let result = '';
  for (let i = 0; i < 32; i++) {
    result += ipBin[i] === '1' && maskBin[i] === '1' ? '1' : '0';
  }
  return binaryToIP(result);
}

Convert each octet to 8-bit binary with padding. Join with or without dots for display.

Tips & Best Practices

  • Always pad to 8 bits per octet
  • Validate octets are 0-255
  • Use for subnet calculations
  • Count 1s in mask = network bits
  • Count 0s in mask = host bits

Common Mistakes to Avoid

  • Not padding with leading zeros
  • Invalid octet values
  • Wrong octet order
  • Forgetting to validate input

When to Use This Tool

Use IP to binary converter for subnet planning, understanding network masks, debugging network issues, and learning IP addressing fundamentals.

Frequently Asked Questions

How do subnet masks work in binary?

Subnet mask has 1s for network portion, 0s for host portion. Contiguous 1s from left. Example: /24 = 24 ones + 8 zeros = 255.255.255.0. AND with IP gives network address.

What is a /24 network?

/24 means 24 bits for network (fixed), 8 bits for hosts (variable). Binary: 11111111.11111111.11111111.00000000. Hosts: 2^8 - 2 = 254 usable (minus network and broadcast addresses).

How do I calculate usable hosts?

Count zero bits in mask = n. Usable hosts = 2^n - 2 (subtract network and broadcast addresses). /24 has 8 zeros: 2^8 - 2 = 254 hosts. /30 has 2 zeros: 2^2 - 2 = 2 hosts (point-to-point).

Why pad with leading zeros?

Each octet must be exactly 8 bits for proper alignment. Without padding, 1 becomes "1" not "00000001", and concatenation breaks. Always pad to 8 bits per octet.

Get Started

Ready to try IP To Binary? Use the tool now - it's free, fast, and works right in your browser.


Last updated: June 27, 2026

Start using IP To Binary

Free, fast, and privacy-focused - try it now

Launch Tool