Convert IPv4 addresses to binary and hexadecimal format
Quick Examples:
About IP Address Formats:
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.
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.
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.
See which bits are network vs host portions.
Understand ACL wildcard patterns in binary.
Visualize how IP addressing works at bit level.
Plan subnet sizes by counting host bits.
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.
Use IP to binary converter for subnet planning, understanding network masks, debugging network issues, and learning IP addressing fundamentals.
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.