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
- Write out the 8 hex digits. Pad with leading zeros if the value has fewer than 8.
- Split the digits into four pairs, left to right. Each pair is one byte.
- Convert each hex pair to a decimal number from 0 to 255.
- 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.
- Take each octet of the dotted address.
- Divide by 16. The quotient is the first hex digit, and the remainder is the second.
- Write each result as two hex digits, with a leading zero when the value is below 16.
- 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.
| Source | Byte order | 192.168.0.1 as hex | 127.0.0.1 as hex |
|---|---|---|---|
| Packet header (IP, TCP, UDP) | Big endian (network) | C0A80001 | 7F000001 |
/proc/net/tcp on x86 Linux | Little endian (host) | 0100A8C0 | 0100007F |
| Wireshark display | Big endian | C0A80001 | 7F000001 |
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 start | Hex end | Addresses | Use |
|---|---|---|---|---|
| 10.0.0.0/8 | 0A000000 | 0AFFFFFF | 16,777,216 | Private network (large) |
| 172.16.0.0/12 | AC100000 | AC1FFFFF | 1,048,576 | Private network (medium) |
| 192.168.0.0/16 | C0A80000 | C0A8FFFF | 65,536 | Private network (small) |
| 127.0.0.0/8 | 7F000000 | 7FFFFFFF | 16,777,216 | Loopback |
| 169.254.0.0/16 | A9FE0000 | A9FEFFFF | 65,536 | Link-local (auto-assigned) |
| 0.0.0.0/8 | 00000000 | 00FFFFFF | 16,777,216 | This network |
| 224.0.0.0/4 | E0000000 | EFFFFFFF | 268,435,456 | Multicast |
| 240.0.0.0/4 | F0000000 | FFFFFFFF | 268,435,456 | Reserved |
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.
| CIDR | Dotted decimal | Hex | Binary |
|---|---|---|---|
| /8 | 255.0.0.0 | FF000000 | 11111111 00000000 00000000 00000000 |
| /16 | 255.255.0.0 | FFFF0000 | 11111111 11111111 00000000 00000000 |
| /24 | 255.255.255.0 | FFFFFF00 | 11111111 11111111 11111111 00000000 |
| /25 | 255.255.255.128 | FFFFFF80 | 11111111 11111111 11111111 10000000 |
| /26 | 255.255.255.192 | FFFFFFC0 | 11111111 11111111 11111111 11000000 |
| /27 | 255.255.255.224 | FFFFFFE0 | 11111111 11111111 11111111 11100000 |
| /28 | 255.255.255.240 | FFFFFFF0 | 11111111 11111111 11111111 11110000 |
| /32 | 255.255.255.255 | FFFFFFFF | 11111111 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
- Drop leading zeros within each group: 0db8 becomes db8, and 0000 becomes 0.
- 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.1Bash substring expansion splits the hex string into four pairs, and printf %d converts each pair to decimal.
Other languages
| Language | Method | Example | Result |
|---|---|---|---|
| Java | InetAddress.getByAddress() | Pass the 4-byte array for 0xC0A80001 | 192.168.0.1 |
| PHP | long2ip(hexdec()) | long2ip(hexdec('C0A80001')) | "192.168.0.1" |
| PowerShell | Shift and mask each byte | $n = 0xC0A80001; (0..3 | % { ($n -shr (24 - 8 * $_)) -band 255 }) -join '.' | 192.168.0.1 |
| Go | net.IPv4() | Shift the bytes of 0xC0A80001 | 192.168.0.1 |
Frequently asked questions
How do you convert hex to an IP address?
How many hex digits is an IPv4 address?
What is 0x7F000001?
What is C0A80001 in decimal?
Why do Linux files show hex addresses backwards?
/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?
What is the hex range for private IP addresses?
How is an IPv6 address written in hex?
::.Can a browser open a hex IP address?
Related tools
- Hex to decimal converter: convert hex to decimal with digit-by-digit steps.
- Decimal to hex converter: convert decimal to hex with the division method.
- Hex to binary converter: see the bit pattern of any hex value.
- Hex to text converter: decode hex bytes into ASCII or UTF-8 text.
- Little endian converter: swap byte order and convert hex to decimal.