Hex to Decimal

Hex to IP address converter

Type 8 hex digits or a dotted address. Each byte becomes one octet from 0 to 255. The sections below cover byte structure, conversion in both directions, byte order, hex formats, private ranges, subnet masks, IPv6, where hex addresses appear, code in several languages and common questions.

Four bytes, four octets

Whole number
Binary
Class
Range

How hex represents an IPv4 address

An IPv4 address is a 32-bit number, and 32 bits map to exactly 8 hex digits. Each pair of hex digits represents one byte (octet), with values from 00 to FF (0 to 255 in decimal). Dotted decimal notation writes the same 4 bytes separated by dots.

The hex value C0A80001 and the dotted address 192.168.0.1 are the same 32-bit number: 3,232,235,521. Hex is compact (8 characters against up to 15 for dotted decimal) and lines up with the binary structure. That is why packet headers, log files and low-level network code store addresses in hex.

Flip the bits in the picture to see how the 8 digits form 4 bytes.

How to convert hex to an IP address

  1. Write out the 8 hex digits. Pad with leading zeros if the value has fewer than 8.
  2. Split the digits into four pairs, left to right. Each pair is one byte.
  3. Convert each hex pair to a decimal number from 0 to 255.
  4. Join the four decimal values with dots. The result is the dotted decimal IPv4 address.

Example 1: C0A80001

C0 = 12 × 16 + 0 = 192, A8 = 10 × 16 + 8 = 168, 00 = 0 and 01 = 1. So C0A80001 = 192.168.0.1, the default gateway on most home routers.

Example 2: 7F000001

7F = 7 × 16 + 15 = 127, then 00, 00 and 01. So 7F000001 = 127.0.0.1, the IPv4 loopback address. Traffic sent here never leaves the machine.

Example 3: 08080808

Each 08 = 0 × 16 + 8 = 8. So 08080808 = 8.8.8.8, a public DNS resolver operated by Google.

IP address to hex

To reverse the process, convert each decimal octet to a two-digit hex value and join the four pairs.

  1. Take each octet of the dotted address.
  2. Divide by 16. The quotient is the first hex digit, and the remainder is the second.
  3. Write each result as two hex digits, with a leading zero when the value is below 16.
  4. Join the four pairs into a single 8-digit hex string.

Example: 10.0.0.1 to hex

10 ÷ 16 = 0 remainder 10 (A), so 10 is 0A. Then 0 is 00, 0 is 00 and 1 is 01. So 10.0.0.1 = 0A000001, the first usable address in the 10.0.0.0/8 private range.

Byte order: network vs host

Network byte order is big endian: the most significant byte comes first. Protocol headers, packet captures and the converter above use network byte order by default, so C0A80001 reads as 192.168.0.1 from left to right.

Host byte order on x86 and most ARM processors is little endian: the least significant byte comes first. Linux exposes socket addresses in host byte order in /proc/net/tcp and /proc/net/tcp6. On a little-endian machine, the loopback address 127.0.0.1 appears as 0100007F, with the bytes reversed.

Switch the converter above to “Reversed (/proc/net)” to handle little-endian values. For more on byte order, see the little endian converter.

SourceByte order192.168.0.1 as hex127.0.0.1 as hex
Packet header (IP, TCP, UDP)Big endian (network)C0A800017F000001
/proc/net/tcp on x86 LinuxLittle endian (host)0100A8C00100007F
Wireshark displayBig endianC0A800017F000001

Hex IP address formats

Hex IP addresses appear in several notations, depending on the context. The flat and 0x-prefixed forms are by far the most common. Dotted hex appears in older BSD network tools.

The URL form works because browsers and operating systems accept integer or hex representations of IP addresses in URLs.

Private and special IPv4 ranges in hex

The Internet Assigned Numbers Authority (IANA) reserves several IPv4 blocks for private networks, loopback and other special purposes. The hex boundaries help when you filter addresses in packet captures or firewall rules.

A quick check for private ranges: if the first two digits are 0A, the address is in 10.0.0.0/8. If they are C0A8, it is in 192.168.0.0/16. If they start with AC1 and the fourth digit is 0 through F, it is in 172.16.0.0/12.

Range (CIDR)Hex startHex endAddressesUse
10.0.0.0/80A0000000AFFFFFF16,777,216Private network (large)
172.16.0.0/12AC100000AC1FFFFF1,048,576Private network (medium)
192.168.0.0/16C0A80000C0A8FFFF65,536Private network (small)
127.0.0.0/87F0000007FFFFFFF16,777,216Loopback
169.254.0.0/16A9FE0000A9FEFFFF65,536Link-local (auto-assigned)
0.0.0.0/80000000000FFFFFF16,777,216This network
224.0.0.0/4E0000000EFFFFFFF268,435,456Multicast
240.0.0.0/4F0000000FFFFFFFF268,435,456Reserved

Subnet masks in hex

A subnet mask is a 32-bit value with a run of 1-bits followed by 0-bits. In hex, common masks form recognisable patterns: /24 is FFFFFF00, and /16 is FFFF0000.

To find the network address in hex, perform a bitwise AND between the IP address and the mask. For 192.168.1.130 with a /25 mask, C0A80182 AND FFFFFF80 = C0A80180. That is 192.168.1.128, the start of the subnet. Move the slider to try other prefix lengths.

CIDRDotted decimalHexBinary
/8255.0.0.0FF00000011111111 00000000 00000000 00000000
/16255.255.0.0FFFF000011111111 11111111 00000000 00000000
/24255.255.255.0FFFFFF0011111111 11111111 11111111 00000000
/25255.255.255.128FFFFFF8011111111 11111111 11111111 10000000
/26255.255.255.192FFFFFFC011111111 11111111 11111111 11000000
/27255.255.255.224FFFFFFE011111111 11111111 11111111 11100000
/28255.255.255.240FFFFFFF011111111 11111111 11111111 11110000
/32255.255.255.255FFFFFFFF11111111 11111111 11111111 11111111

IPv6 and hexadecimal

IPv6 addresses are 128 bits long, written as eight groups of four hex digits separated by colons. Each group represents 16 bits (2 bytes), and the full address uses 32 hex digits. IPv4 has 32 bits (8 hex digits) and about 4.3 billion addresses. IPv6 has about 3.4 × 10³⁸.

IPv6 shorthand rules

  1. Drop leading zeros within each group: 0db8 becomes db8, and 0000 becomes 0.
  2. Replace one run of consecutive all-zero groups with ::. You can do this once per address.

The full address 2001:0db8:0000:0000:0000:0000:0000:0001 shortens to 2001:db8::1.

IPv4-mapped IPv6 addresses

IPv6 can embed an IPv4 address in its last 32 bits. The prefix ::ffff: followed by the IPv4 address marks an IPv4-mapped address. For 192.168.0.1 the full form is 0000:0000:0000:0000:0000:ffff:c0a8:0001, and the short forms are ::ffff:192.168.0.1 and ::ffff:c0a8:1. Dual-stack servers use this format to handle IPv4 traffic through IPv6 sockets.

Where hex IP addresses appear

Packet captures

Wireshark, tcpdump and other packet analysers show IPv4 and IPv6 headers with addresses in hex in the hex dump pane. The IP header stores the source address at byte offset 12 and the destination at byte offset 16, each as 4 hex bytes in network byte order.

Linux /proc filesystem

The files /proc/net/tcp and /proc/net/udp, and their IPv6 counterparts, list open sockets with addresses in hex. On little-endian machines the bytes are reversed, so 0100007F is 127.0.0.1 and not 1.0.0.127.

Server logs and firewall rules

Some web servers and firewalls log client addresses in hex, especially in raw access logs or binary log formats. The iptables u32 match works on 32-bit values, which administrators often write in hex.

URL encoding

Browsers accept hex IP addresses in URLs. Navigating to http://0x7F000001/ resolves to 127.0.0.1 on most operating systems. Security researchers study this format because it can bypass naive URL blocklists that check only for dotted decimal.

Socket programming

The C sockaddr_in structure stores IPv4 addresses as a 32-bit integer in network byte order. The functions inet_pton and inet_ntop convert between that integer and the dotted string. The Python socket module wraps the same C functions.

Hex to IP address in programming

Pick a language to see the call and its output for your value.

Python

import ipaddress
h = 'C0A80001'
n = int(h, 16)
str(ipaddress.IPv4Address(n))   # '192.168.0.1'

The ipaddress module accepts a 32-bit integer and returns a formatted IPv4 address. For the full hex-to-decimal guide, see hex to decimal in Python.

JavaScript

const h = 'C0A80001';
const n = parseInt(h, 16);
[(n >>> 24) & 0xFF, (n >>> 16) & 0xFF, (n >>> 8) & 0xFF, n & 0xFF].join('.');
// '192.168.0.1'

JavaScript has no built-in IP library, so the conversion shifts each byte into place with bitwise operators. The >>> (unsigned right shift) avoids sign problems with addresses above 7FFFFFFF. For the full guide, see hex to decimal in JavaScript.

C

#include <stdio.h>
#include <stdint.h>
#include <arpa/inet.h>
int main(void) {
    uint32_t n = 0xC0A80001;
    struct in_addr addr;
    addr.s_addr = htonl(n);
    char buf[INET_ADDRSTRLEN];
    inet_ntop(AF_INET, &addr, buf, sizeof buf);
    printf("%s\n", buf);   /* 192.168.0.1 */
    return 0;
}

htonl converts the host integer to network byte order, and inet_ntop formats it as a dotted string. For the full guide, see hex to decimal in C.

Bash

h='C0A80001'
printf '%d.%d.%d.%d\n' \
  0x${h:0:2} 0x${h:2:2} 0x${h:4:2} 0x${h:6:2}
# 192.168.0.1

Bash substring expansion splits the hex string into four pairs, and printf %d converts each pair to decimal.

Other languages

LanguageMethodExampleResult
JavaInetAddress.getByAddress()Pass the 4-byte array for 0xC0A80001192.168.0.1
PHPlong2ip(hexdec())long2ip(hexdec('C0A80001'))"192.168.0.1"
PowerShellShift and mask each byte$n = 0xC0A80001; (0..3 | % { ($n -shr (24 - 8 * $_)) -band 255 }) -join '.'192.168.0.1
Gonet.IPv4()Shift the bytes of 0xC0A80001192.168.0.1

Frequently asked questions

How do you convert hex to an IP address?
Split the 8 hex digits into four pairs, convert each pair to a decimal number from 0 to 255, and join the four numbers with dots. C0A80001 becomes C0.A8.00.01, then 192.168.0.1.
How many hex digits is an IPv4 address?
Eight hex digits (4 bytes, 32 bits). Each hex digit represents 4 bits, and an IPv4 address is 32 bits long: 32 ÷ 4 = 8 digits.
What is 0x7F000001?
0x7F000001 is 127.0.0.1, the IPv4 loopback address. 7F is 127 in decimal, and the remaining three bytes are 0, 0 and 1. Traffic sent to this address stays on the local machine.
What is C0A80001 in decimal?
C0A80001 is 3,232,235,521 in decimal, which corresponds to the IP address 192.168.0.1. This is the default gateway address on most consumer routers.
Why do Linux files show hex addresses backwards?
Linux stores socket addresses in host byte order, which is little endian on x86 and most ARM processors. The file /proc/net/tcp writes the least significant byte first, so 127.0.0.1 appears as 0100007F. Network byte order (big endian) writes the most significant byte first.
How do you convert an IP address to hex?
Convert each of the four decimal octets to a two-digit hex value and join them. For 10.0.0.1: 10 = 0A, 0 = 00, 0 = 00 and 1 = 01, which gives 0A000001.
What is the hex range for private IP addresses?
The three private ranges in hex are 0A000000–0AFFFFFF (10.0.0.0/8), AC100000–AC1FFFFF (172.16.0.0/12) and C0A80000–C0A8FFFF (192.168.0.0/16). These addresses are not routable on the public internet and are reserved for local networks by IANA.
How is an IPv6 address written in hex?
An IPv6 address is 128 bits written as eight groups of four hex digits separated by colons, such as 2001:0db8:85a3:0000:0000:8a2e:0370:7334. You can drop leading zeros within a group, and you can replace one run of consecutive all-zero groups with ::.
Can a browser open a hex IP address?
Yes, most browsers and operating systems resolve hex IP addresses in URLs. Typing http://0xC0A80001/ resolves to http://192.168.0.1/. This works because the network stack accepts integer and hex representations alongside dotted decimal.