Testing Environment: Our tools are currently under heavy testing. You may experience slower performance or temporary issues.

🌐

IPv4 Address Converter

Convert IPv4 addresses between different formats and notations

IP Address Input

Quick Examples

IP Address Formats

🌐

No IP Address Converted

Enter an IP address and click "Convert IP Address" to see all formats.

🌐 IPv4 Conversion Tips

  • Auto-detect: Automatically determines input format for convenience
  • Integer Range: IPv4 integers range from 0 to 4,294,967,295 (2³²-1)
  • Private Ranges: 10.x.x.x, 172.16-31.x.x, 192.168.x.x are private
  • CIDR Notation: Use /24, /16, etc. for subnet analysis
  • Binary Format: Each octet is 8 bits (e.g., 11000000 = 192)
  • Batch Processing: Convert multiple IPs simultaneously for efficiency

About IPv4 Address Conversion

IPv4 address conversion allows you to translate IP addresses between different formats and representations. Network administrators and developers often need to convert between dotted decimal notation, binary representation, hexadecimal format, and integer values for various networking tasks.

  • Convert between dotted decimal, binary, hex, and integer formats
  • Validate IP address formats and ranges
  • Support for CIDR notation and subnet analysis
  • Batch conversion for multiple IP addresses
  • Network class identification and analysis

IPv4 Address Formats

Standard Formats

  • Dotted Decimal: 192.168.1.1 (human-readable)
  • Binary: 11000000.10101000.00000001.00000001
  • Hexadecimal: 0xC0A80101
  • Integer: 3232235777 (32-bit value)

Special Notations

  • CIDR: 192.168.1.0/24 (with subnet)
  • Reverse DNS: 1.1.168.192.in-addr.arpa
  • URL Encoded: 192%2E168%2E1%2E1
  • Octal: 0300.0250.0001.0001

Advertisement

AdSense Banner Ad Placeholder

Frequently Asked Questions

Why would I need to convert IP addresses to different formats?

Different formats serve different purposes: binary for subnet calculations, integer for database storage, hexadecimal for compact representation, and decimal for human readability.

What is the integer representation of an IP address?

The integer representation treats the 4-byte IP address as a single 32-bit number. For example, 192.168.1.1 equals (192×2²⁴)+(168×2¹⁶)+(1×2⁸)+1 = 3,232,235,777.

How do I identify the network class of an IP address?

Network classes are determined by the first octet: Class A (1-126), Class B (128-191), Class C (192-223), Class D for multicast (224-239), and Class E reserved (240-255).

Can I convert private IP addresses the same way as public ones?

Yes, the conversion process is identical. Private IP ranges (10.x.x.x, 172.16-31.x.x, 192.168.x.x) use the same format conversions as public addresses.

IPv4 Conversion Examples

Common IP Addresses:

Localhost: 127.0.0.1
Binary: 01111111.00000000.00000000.00000001
Hex: 0x7F000001
Integer: 2,130,706,433
Google DNS: 8.8.8.8
Binary: 00001000.00001000.00001000.00001000
Hex: 0x08080808
Integer: 134,744,072

Private Network Examples:

Home Router: 192.168.1.1
Binary: 11000000.10101000.00000001.00000001
Hex: 0xC0A80101
Integer: 3,232,235,777
Corporate: 10.0.0.1
Binary: 00001010.00000000.00000000.00000001
Hex: 0x0A000001
Integer: 167,772,161

Sponsored Content

AdSense Square Ad Placeholder

IPv4 Converter Implementation

JavaScript IPv4 Address Converter:

class IPv4AddressConverter {
  constructor() {
    this.privateRanges = [
      { start: [10, 0, 0, 0], end: [10, 255, 255, 255], name: 'Class A Private' },
      { start: [172, 16, 0, 0], end: [172, 31, 255, 255], name: 'Class B Private' },
      { start: [192, 168, 0, 0], end: [192, 168, 255, 255], name: 'Class C Private' }
    ];
    
    this.specialRanges = [
      { start: [127, 0, 0, 0], end: [127, 255, 255, 255], name: 'Loopback' },
      { start: [169, 254, 0, 0], end: [169, 254, 255, 255], name: 'Link-Local' },
      { start: [224, 0, 0, 0], end: [239, 255, 255, 255], name: 'Multicast' },
      { start: [240, 0, 0, 0], end: [255, 255, 255, 255], name: 'Reserved' }
    ];
  }
  
  // Convert IP address to all formats
  convertIP(input, inputFormat = 'decimal') {
    try {
      let octets;
      
      // Parse input based on format
      switch (inputFormat.toLowerCase()) {
        case 'decimal':
        case 'dotted':
          octets = this.parseDecimalIP(input);
          break;
        case 'integer':
          octets = this.parseIntegerIP(input);
          break;
        case 'hex':
        case 'hexadecimal':
          octets = this.parseHexIP(input);
          break;
        case 'binary':
          octets = this.parseBinaryIP(input);
          break;
        default:
          octets = this.autoDetectFormat(input);
      }
      
      if (!octets) {
        return { success: false, error: 'Invalid IP address format' };
      }
      
      // Validate octets
      if (!this.validateOctets(octets)) {
        return { success: false, error: 'Invalid IP address range' };
      }
      
      return {
        success: true,
        input: input,
        inputFormat: inputFormat,
        octets: octets,
        formats: this.generateAllFormats(octets),
        analysis: this.analyzeIP(octets)
      };
      
    } catch (error) {
      return { success: false, error: error.message };
    }
  }
  
  // Parse dotted decimal IP (192.168.1.1)
  parseDecimalIP(ip) {
    const octets = ip.toString().split('.');
    if (octets.length !== 4) return null;
    
    return octets.map(octet => {
      const num = parseInt(octet, 10);
      return isNaN(num) ? null : num;
    }).filter(octet => octet !== null);
  }
  
  // Parse integer IP (3232235777)
  parseIntegerIP(integer) {
    const num = parseInt(integer, 10);
    if (isNaN(num) || num < 0 || num > 4294967295) return null;
    
    return [
      (num >>> 24) & 0xFF,
      (num >>> 16) & 0xFF,
      (num >>> 8) & 0xFF,
      num & 0xFF
    ];
  }
  
  // Parse hexadecimal IP (0xC0A80101)
  parseHexIP(hex) {
    let cleanHex = hex.toString().toLowerCase();
    if (cleanHex.startsWith('0x')) {
      cleanHex = cleanHex.slice(2);
    }
    
    if (cleanHex.length !== 8 || !/^[0-9a-f]+$/.test(cleanHex)) {
      return null;
    }
    
    const integer = parseInt(cleanHex, 16);
    return this.parseIntegerIP(integer);
  }
  
  // Parse binary IP (11000000.10101000.00000001.00000001)
  parseBinaryIP(binary) {
    const binaryOctets = binary.toString().split('.');
    if (binaryOctets.length !== 4) return null;
    
    return binaryOctets.map(octet => {
      if (octet.length !== 8 || !/^[01]+$/.test(octet)) {
        return null;
      }
      return parseInt(octet, 2);
    }).filter(octet => octet !== null);
  }
  
  // Auto-detect IP format
  autoDetectFormat(input) {
    const str = input.toString().trim();
    
    // Check for dotted decimal
    if (str.includes('.') && str.split('.').length === 4) {
      return this.parseDecimalIP(str);
    }
    
    // Check for hexadecimal
    if (str.startsWith('0x') || /^[0-9a-f]+$/i.test(str)) {
      return this.parseHexIP(str);
    }
    
    // Check for pure integer
    if (/^\d+$/.test(str)) {
      return this.parseIntegerIP(str);
    }
    
    return null;
  }
  
  // Validate octets are in valid range
  validateOctets(octets) {
    return octets.length === 4 && 
           octets.every(octet => octet >= 0 && octet <= 255);
  }
  
  // Generate all formats from octets
  generateAllFormats(octets) {
    const decimal = octets.join('.');
    const integer = (octets[0] << 24) + (octets[1] << 16) + (octets[2] << 8) + octets[3];
    // Use unsigned right shift to handle negative numbers correctly
    const unsignedInteger = integer >>> 0;
    
    return {
      decimal: decimal,
      binary: octets.map(octet => 
        octet.toString(2).padStart(8, '0')
      ).join('.'),
      binaryCompact: octets.map(octet => 
        octet.toString(2).padStart(8, '0')
      ).join(''),
      hexadecimal: '0x' + octets.map(octet => 
        octet.toString(16).padStart(2, '0').toUpperCase()
      ).join(''),
      integer: unsignedInteger,
      octal: octets.map(octet => 
        '0' + octet.toString(8).padStart(3, '0')
      ).join('.'),
      reverseDNS: [...octets].reverse().join('.') + '.in-addr.arpa',
      urlEncoded: octets.join('%2E')
    };
  }
  
  // Analyze IP address properties
  analyzeIP(octets) {
    const analysis = {
      class: this.getIPClass(octets[0]),
      type: this.getIPType(octets),
      isPrivate: this.isPrivateIP(octets),
      isPublic: !this.isPrivateIP(octets) && !this.isSpecialIP(octets),
      isReserved: this.isSpecialIP(octets),
      isMulticast: octets[0] >= 224 && octets[0] <= 239,
      isBroadcast: octets.every(octet => octet === 255)
    };
    
    // Add specific type information
    const specialRange = this.getSpecialRange(octets);
    if (specialRange) {
      analysis.specialType = specialRange.name;
    }
    
    return analysis;
  }
  
  // Determine IP class
  getIPClass(firstOctet) {
    if (firstOctet >= 1 && firstOctet <= 126) return 'A';
    if (firstOctet >= 128 && firstOctet <= 191) return 'B';
    if (firstOctet >= 192 && firstOctet <= 223) return 'C';
    if (firstOctet >= 224 && firstOctet <= 239) return 'D';
    if (firstOctet >= 240 && firstOctet <= 255) return 'E';
    return 'Invalid';
  }
  
  // Determine if IP is private
  isPrivateIP(octets) {
    return this.privateRanges.some(range => 
      this.isIPInRange(octets, range.start, range.end)
    );
  }
  
  // Determine if IP is special/reserved
  isSpecialIP(octets) {
    return this.specialRanges.some(range => 
      this.isIPInRange(octets, range.start, range.end)
    );
  }
  
  // Get special range information
  getSpecialRange(octets) {
    return [...this.privateRanges, ...this.specialRanges].find(range =>
      this.isIPInRange(octets, range.start, range.end)
    );
  }
  
  // Check if IP is in range
  isIPInRange(ip, start, end) {
    for (let i = 0; i < 4; i++) {
      if (ip[i] < start[i] || ip[i] > end[i]) {
        return false;
      }
    }
    return true;
  }
  
  // Get IP type description
  getIPType(octets) {
    if (this.isPrivateIP(octets)) return 'Private';
    if (this.isSpecialIP(octets)) return 'Special/Reserved';
    if (octets[0] >= 224 && octets[0] <= 239) return 'Multicast';
    return 'Public';
  }
  
  // Batch convert multiple IPs
  batchConvert(ips, inputFormat = 'decimal') {
    return ips.map((ip, index) => ({
      index: index,
      input: ip,
      result: this.convertIP(ip, inputFormat)
    }));
  }
  
  // Convert with CIDR notation
  convertWithCIDR(ipWithCIDR) {
    const [ip, cidr] = ipWithCIDR.split('/');
    const cidrNum = parseInt(cidr, 10);
    
    if (!ip || isNaN(cidrNum) || cidrNum < 0 || cidrNum > 32) {
      return { success: false, error: 'Invalid CIDR notation' };
    }
    
    const ipResult = this.convertIP(ip);
    if (!ipResult.success) {
      return ipResult;
    }
    
    // Calculate network information
    const networkInfo = this.calculateNetwork(ipResult.octets, cidrNum);
    
    return {
      ...ipResult,
      cidr: cidrNum,
      network: networkInfo
    };
  }
  
  // Calculate network information from CIDR
  calculateNetwork(octets, cidr) {
    const subnetMask = this.cidrToMask(cidr);
    const networkOctets = octets.map((octet, i) => octet & subnetMask[i]);
    const broadcastOctets = octets.map((octet, i) => octet | (255 - subnetMask[i]));
    
    return {
      network: this.generateAllFormats(networkOctets),
      broadcast: this.generateAllFormats(broadcastOctets),
      subnetMask: this.generateAllFormats(subnetMask),
      hostBits: 32 - cidr,
      totalHosts: Math.pow(2, 32 - cidr),
      usableHosts: Math.pow(2, 32 - cidr) - 2
    };
  }
  
  // Convert CIDR to subnet mask octets
  cidrToMask(cidr) {
    const mask = [];
    let remaining = cidr;
    
    for (let i = 0; i < 4; i++) {
      if (remaining >= 8) {
        mask.push(255);
        remaining -= 8;
      } else if (remaining > 0) {
        mask.push(256 - Math.pow(2, 8 - remaining));
        remaining = 0;
      } else {
        mask.push(0);
      }
    }
    
    return mask;
  }
  
  // Generate IP range
  generateRange(startIP, endIP) {
    const start = this.convertIP(startIP);
    const end = this.convertIP(endIP);
    
    if (!start.success || !end.success) {
      return { success: false, error: 'Invalid IP addresses' };
    }
    
    const startInt = start.formats.integer;
    const endInt = end.formats.integer;
    
    if (startInt > endInt) {
      return { success: false, error: 'Start IP must be less than end IP' };
    }
    
    const range = [];
    const maxRange = 1000; // Limit to prevent memory issues
    
    for (let i = startInt; i <= Math.min(endInt, startInt + maxRange - 1); i++) {
      const ip = this.parseIntegerIP(i);
      if (ip) {
        range.push({
          decimal: ip.join('.'),
          integer: i
        });
      }
    }
    
    return {
      success: true,
      start: start.formats.decimal,
      end: end.formats.decimal,
      count: endInt - startInt + 1,
      range: range,
      truncated: endInt - startInt + 1 > maxRange
    };
  }
}

// Usage examples
const ipConverter = new IPv4AddressConverter();

// Convert from different formats
console.log('Decimal IP:', ipConverter.convertIP('192.168.1.1', 'decimal'));
console.log('Integer IP:', ipConverter.convertIP('3232235777', 'integer'));
console.log('Hex IP:', ipConverter.convertIP('0xC0A80101', 'hex'));

// Convert with CIDR
console.log('CIDR Conversion:', ipConverter.convertWithCIDR('192.168.1.0/24'));

// Batch conversion
const ips = ['192.168.1.1', '10.0.0.1', '8.8.8.8'];
console.log('Batch:', ipConverter.batchConvert(ips));
            

IPv4 Network Classes

Class A

  • Range: 1.0.0.0 - 126.255.255.255
  • Networks: 126
  • Hosts/Net: 16,777,214
  • Default Mask: 255.0.0.0 (/8)

Class B

  • Range: 128.0.0.0 - 191.255.255.255
  • Networks: 16,384
  • Hosts/Net: 65,534
  • Default Mask: 255.255.0.0 (/16)

Class C

  • Range: 192.0.0.0 - 223.255.255.255
  • Networks: 2,097,152
  • Hosts/Net: 254
  • Default Mask: 255.255.255.0 (/24)

IPv4 Conversion Best Practices

  • Validate Input: Always verify IP addresses are in valid ranges (0-255 per octet)
  • Handle Edge Cases: Consider special addresses like 0.0.0.0 and 255.255.255.255
  • Use Appropriate Format: Choose the right format for your use case
  • Consider Endianness: Be aware of byte order when working with integers
  • Document Context: Specify whether addresses are network, host, or broadcast
  • Batch Processing: Use efficient algorithms for large-scale conversions
  • Error Handling: Implement robust error checking and reporting

Common Use Cases

  • Network configuration and troubleshooting
  • Database storage optimization
  • Security analysis and filtering
  • Log file analysis and processing
  • Network monitoring and alerting
  • Subnet planning and management
  • Firewall rule configuration
  • API development and integration

Advertisement

AdSense Bottom Ad Placeholder