IP to Decimal Converter

Convert an IP address to decimal, hex, binary and octal, or type any of those numbers to get the IP back. Each octet is drawn as 8 bits with their place values, so you can follow the arithmetic.

WHATWG URL Standard and inet_aton parsing · exact 128-bit arithmetic for IPv6 · runs in your browser

Read as dotted

Each octet's 8 bits, with their place values198.51.100.77 = 3,325,256,781
Octet1286432168421HexSum× place= value
19811000110C6128+64+4+2 = 198× 256³16,777,2163,321,888,768
128+64+4+2 × 256³ = 3,321,888,768
51001100113332+16+2+1 = 51× 256²65,5363,342,336
32+16+2+1 × 256² = 3,342,336
100011001006464+32+4 = 100× 25625625,600
64+32+4 × 256 = 25,600
77010011014D64+8+4+1 = 77× 1177
64+8+4+1 × 1 = 77
Total3,325,256,781
= 3,325,256,781
Try

An IP, or its decimal, hex, binary or octal number to get the IP back. Converted in your browser; nothing is sent.

IPv4 · 32 bits

3325256781

198.51.100.77 as one 32-bit number · Documentation address (RFC 5737)

The same number in code

SELECT INET_ATON('198.51.100.77');3325256781
SELECT '198.51.100.77'::inet - '0.0.0.0'::inet;3325256781
int(ipaddress.ip_address('198.51.100.77'))3325256781
ip2long('198.51.100.77')3325256781
Dotted decimal
Decimal
Hex
Binary octets
Octal
Hex octets
Octal octets
In a browser (each opens 198.51.100.77)
Reverse DNS name
As IPv6 (mapped)
IPv4 → IPv6

How do I convert an IP address to decimal?

Multiply the four numbers by 256³, 256², 256 and 1 and add them up: 192.168.1.1 is 192 × 16,777,216 + 168 × 65,536 + 1 × 256 + 1 = 3,232,235,777.

An IPv4 address is one 32-bit number written in four 8-bit pieces, so the dotted form and the decimal form are the same value. MySQL's documentation uses 10.0.5.9 = 167773449 as its example.

192.168.1.1 as one number: each part times its place, then the sum.
IP to decimal converter showing each octet's bits and place values adding up to the numberIP to decimal converter showing each octet's bits and place values adding up to the numberAny form inDotted, decimal, hex, binary, octal or a URL: the field reads them all.Bits and place valuesEach 1 adds its place value: 128 + 64 + 4 + 2 = 198.× 256³, 256², 256, 1Each octet times its weight, then the total.Every form outHex, binary, octal and the URLs browsers accept, each with copy.The numberThe whole address as one 32-bit number, ready to copy, with what kind of address it is.
198.51.100.77 bit by bit: each octet's place values, then × 256³, 256², 256 and 1, adding up to 3,325,256,781.

How do I convert decimal to an IP address?

Divide by 16,777,216, then divide the remainder by 65,536, then by 256: the three quotients and the last remainder are the four numbers, so 3232235777 is 192.168.1.1.

Type the number in the converter and it does the same, along with hex, binary, octal and the forms browsers accept. Numbers above 4,294,967,295 aren't IPv4 addresses; the converter reads them as IPv6 numbers and says so.

3,232,235,777 back to 192.168.1.1 by division.

How do I convert an IP address to binary?

Write each of the four numbers as 8 bits with the place values 128, 64, 32, 16, 8, 4, 2 and 1: 192 is 128 + 64, so 11000000, and 192.168.1.1 is 11000000.10101000.00000001.00000001.

Go through the place values from the left: write 1 and subtract when the value fits, otherwise write 0. For 168: 128 fits (40 left), 64 doesn't, 32 fits (8 left), 16 doesn't, 8 fits, so 10101000. Back from binary, add the place values of the 1s.

Each octet of 192.168.1.1 against the place values 128 to 1.

How do I convert an IP address to hex?

Split each octet's 8 bits into two halves of 4 and write each half as one hex digit: 192 is 1100 0000, which is C0, so 192.168.1.1 is 0xC0A80101.

Hex is also how IPv6 writes an embedded IPv4 address: ::ffff:c0a8:101 is 192.168.1.1. Browsers accept the hex number as a host: http://0xC0A80101/ opens 192.168.1.1.

Four bits per hex digit: 192.168.1.1 is C0 A8 01 01.

Why does http://3232235777 open 192.168.1.1?

Because browsers read a host made only of numbers as an IPv4 address in any of the old inet_aton forms, one decimal number included, and then load the dotted address.

Each part may be decimal (the URL Standard), hex with 0x or octal with a leading 0, and fewer than four parts let the last one fill the remaining bytes. So http://192.168.1/ opens 192.168.0.1, not 192.168.1.1. ping and curl accept the same forms.

Numbers past 32 bits, an 8 or 9 in a part that starts with 0, and a fifth part are refused.

Typed in the address barOpens
http://3232235777/192.168.1.1
http://0xC0A80101/192.168.1.1
http://0300.0250.1.1/192.168.1.1
http://127.1/127.0.0.1
http://192.168.1/192.168.0.1
http://4294967296/Refused
http://09/Refused
http://192.0.2.1.5/Refused
What the WHATWG URL parser does with each host.

Why do alternate IP address forms matter for security?

Because a filter that compares addresses as text can be fooled: 2130706433, 0x7f.1, 127.1 and ::ffff:127.0.0.1 are all 127.0.0.1, so filters must compare the numeric value, not the string.

OWASP lists these encodings among the ways around SSRF defences. Libraries have shipped this bug: the npm packages netmask and ip, Python's ipaddress and Go's net package all misread leading zeros or alternate forms at some point and have since been fixed.

Parse with a strict reader, convert to a number, then compare ranges. Block IPv4-mapped addresses of blocked ranges too.

deny 127.0.0.1

Compared as text

127.0.0.1blocked

2130706433gets through

0x7f.1gets through

127.1gets through

::ffff:127.0.0.1gets through

Compared as a number

127.0.0.12130706433 · blocked

21307064332130706433 · blocked

0x7f.12130706433 · blocked

127.12130706433 · blocked

::ffff:127.0.0.12130706433 · blocked

CVE-2021-28918netmask (npm)CVE-2021-29418netmask (npm)CVE-2021-29424Net::Netmask (Perl)CVE-2021-29921Python ipaddressCVE-2021-29923Go netCVE-2024-29415ip (npm)
One rule, five spellings of the loopback address; then the advisories.

How do I convert an IPv6 address to decimal?

The same way with eight 16-bit groups: 2001:db8::1 is 42540766411282592856903984951653826561, a number of up to 39 digits that needs BigInt in JavaScript.

There are 2^128 IPv6 addresses. JavaScript numbers hold integers exactly only up to 2^53 − 1, so ordinary arithmetic silently rounds IPv6 values. Python's int(ipaddress.ip_address(…)) is exact.

2001:db8::1 as one number, and what a plain JavaScript number makes of it.

How do I convert IP addresses to numbers in code and databases?

Use the platform's own functions with an unsigned type: MySQL's INET_ATON() into INT UNSIGNED, PostgreSQL's inet subtraction, Python's int(ipaddress.ip_address(…)), and >>> 0 after shifts in JavaScript.

A signed 32-bit integer can't hold addresses from 128.0.0.0 up: JavaScript's << gives -1062731519 for 192.168.1.1, and PHP's ip2long() goes negative on 32-bit builds. For IPv6, MySQL uses INET6_ATON() and VARBINARY(16).

› SELECT INET_ATON('192.168.1.1'), INET_NTOA(3232235777);
3232235777 | 192.168.1.1

MySQL 8.4

› SELECT '192.168.1.1'::inet - '0.0.0.0'::inet,
       '0.0.0.0'::inet + 3232235777;
3232235777 | 192.168.1.1

PostgreSQL 16

› import ipaddress
int(ipaddress.ip_address('192.168.1.1')), ipaddress.IPv4Address(3232235777)
(3232235777, IPv4Address('192.168.1.1'))

Python ipaddress

› '192.168.1.1'.split('.').reduce((n, o) => (n << 8) | +o, 0) >>> 0
3232235777

JavaScript

› echo ip2long('192.168.1.1'), ' ', long2ip(3232235777);
3232235777 192.168.1.1

PHP 8

192.168.1.1 as a number and back in two databases and three languages.

Frequently asked questions

What is 192.168.1.1 in decimal?

3232235777. Multiply each part by its place value and add: 192 × 16,777,216 + 168 × 65,536 + 1 × 256 + 1 = 3,232,235,777. The same number is 0xC0A80101 in hex and 11000000.10101000.00000001.00000001 in binary. Browsers accept it as a host too, so http://3232235777/ opens the same address as http://192.168.1.1/.

What is the largest decimal value of an IPv4 address?

4,294,967,295, which is 255.255.255.255. An IPv4 address is a 32-bit number, so there are 2^32 = 4,294,967,296 of them, from 0 (0.0.0.0) up to 4,294,967,295. Larger numbers aren't IPv4 addresses: browsers refuse http://4294967296/, and this converter reads such numbers as 128-bit IPv6 values instead and tells you so.

How do I convert 3232235777 back to an IP address?

Divide by 16,777,216 for the first part: 192, remainder 11,010,305. Divide that remainder by 65,536 for the second part: 168, remainder 257. Divide 257 by 256 for the third part: 1, remainder 1, which is the fourth part. The answer is 192.168.1.1. Type the number into the converter and it shows each octet's bits as well.

What does a leading zero like 010 mean in an IP address?

It depends on the program. Browsers and inet_aton read a part with a leading zero as octal, so 192.0.2.010 is 192.0.2.8, while tools that ignore the zero read 192.0.2.10. Python and Go now reject such addresses outright, after bugs where the two readings let requests slip past IP filters. Never write leading zeros in IPv4 addresses.

Why does 192.168.1 open 192.168.0.1?

Because a three-part address fills the last 16 bits with its last part. In 192.168.1 the final 1 becomes the 16-bit number 1, which is 0.1, so the address is 192.168.0.1. That is how inet_aton and browsers read short forms, and 192.168.257 would be 192.168.1.1. PostgreSQL's cidr type reads 192.168.1 differently, as the network 192.168.1.0/24.

How do I convert an IP address to binary by hand?

For each of the four numbers, go through the place values 128, 64, 32, 16, 8, 4, 2 and 1: write 1 and subtract when the place fits, otherwise write 0. For 168: 128 fits (40 left), 64 doesn't, 32 fits (8 left), 16 doesn't, 8 fits (0 left), so 10101000. Join the four 8-bit groups with dots.

How do I store IP addresses as numbers in MySQL?

Convert with INET_ATON('10.0.5.9'), which returns 167773449, and store the result in an INT UNSIGNED column: a signed INT can't hold addresses above 127.255.255.255. INET_NTOA turns the number back into text. For IPv6 use INET6_ATON and a VARBINARY(16) column, because 128-bit values don't fit any integer type. Don't rely on INET_ATON for short forms like 127.1.

Why is my IP number negative in JavaScript or PHP?

Because it was treated as a signed 32-bit integer. JavaScript's << operator returns signed results, so 192.168.1.1 built with shifts gives -1062731519; add >>> 0 to get 3232235777. PHP's ip2long behaves the same on 32-bit builds, where sprintf('%u', …) prints the unsigned value. Only addresses from 128.0.0.0 upward are affected, which is why the bug often goes unnoticed.

Can an IPv6 address be converted to decimal?

Yes. An IPv6 address is a 128-bit number, so 2001:db8::1 is 42540766411282592856903984951653826561, and the largest value has 39 digits. Ordinary JavaScript numbers lose precision beyond 2^53, so tools must use BigInt, and some online converters get the last digits wrong. Python's int(ipaddress.ip_address('2001:db8::1')) gives the exact value.

Is http://0x7f000001/ the same as 127.0.0.1?

Yes. Browsers and many command-line tools read a host of hex digits after 0x as one 32-bit number, so 0x7f000001, 2130706433, 0x7f.1 and 127.1 all mean 127.0.0.1, the loopback address. That is why security filters must compare the numeric value rather than the text, which is the advice of RFC 3986 and OWASP's SSRF cheat sheet.

Missing something?Suggest a feature or a new tool