Back to tool
Tools / Number Bases
Convert

Number Base Converter

Binary, octal, decimal, hex and any base from 2 to 36 — all shown at once, with the bit width and which integer type will hold the value.

Base Conversion

ready
Prefixes are accepted and stripped automatically: 0x for hex, 0b for binary, 0o for octal. Underscores and spaces are ignored.
Decimal value
Binary (2)
Octal (8)
Hex (16)
Custom
Bits needed
Bytes
Fits in
Base36
Padded bit patterns
You might also need
Base64 Encoder & DecoderUnix Timestamp ConverterSlug Generator

What a number base actually is

A base is a counting convention, not a property of a number. The quantity you know as two hundred and fifty-five is written 255 in decimal, FF in hexadecimal and 11111111 in binary. All three notations denote the same thing. Nothing about the value changes — only the symbols used to record it.

Every positional system works the same way: each digit position carries a weight that is a power of the base, and the value is the sum of digit × weight.

Positional notation
Decimal 255 = 2×10² + 5×10¹ + 5×10⁰ = 200 + 50 + 5

Hex FF     = 15×16¹ + 15×16⁰ = 240 + 15 = 255

Binary 11111111 = 128+64+32+16+8+4+2+1 = 255

Base 36 is the practical upper limit for a converter like this, because it exhausts the ten digits plus twenty-six letters. Beyond that you would need to invent new symbols or use a different scheme entirely, which is what Base64 does.

Why hexadecimal won

Hex is not arbitrary. It survives because 16 is 2⁴, which means one hex digit maps onto exactly four bits with no remainder and no ambiguity. That single property makes hex a compact, lossless shorthand for binary that a human can actually read.

HexBinaryDecimalHexBinaryDecimal
000000810008
100011910019
200102A101010
300113B101111
401004C110012
501015D110113
601106E111014
701117F111115

Because a byte is eight bits, a byte is always exactly two hex digits — 00 to FF. This is why memory addresses, colour codes, hashes, MAC addresses and byte dumps are all written in hex. A colour like #CC2936 is three bytes: red CC (204), green 29 (41), blue 36 (54).

Octal, base 8, has the same property against three bits and survives mainly in Unix file permissions. chmod 755 is three octal digits, each encoding three permission bits: 7 = 111 = read, write, execute; 5 = 101 = read and execute.

A worked example

Converting decimal 2026 to hexadecimal by repeated division:

  1. 2026 ÷ 16 = 126 remainder 10 → digit A
  2. 126 ÷ 16 = 7 remainder 14 → digit E
  3. 7 ÷ 16 = 0 remainder 7 → digit 7
  4. Read the remainders bottom to top: 7EA

Check by expanding: 7×256 + 14×16 + 10 = 1792 + 224 + 10 = 2026. ✓

Going the other way is a straight positional expansion. Converting back to binary is easier still — expand each hex digit into its four bits: 7 = 0111, E = 1110, A = 1010, giving 0111 1110 1010.

Prefixes and how they are read

PrefixBaseExampleLanguages
0x160xFFC, C++, Java, JS, Python, Go, Rust
0b20b11111111Python, JS (ES6), Java 7+, Rust
0o80o377Python 3, JS (ES6)
0 (leading)80377C, older JS — a classic bug source
#16#CC2936CSS, HTML colours

The bare leading zero deserves a warning. In C and older JavaScript, 010 is octal 8, not decimal 10. This has caused real bugs in date handling, where 09 is not even valid octal and throws. Modern languages either require 0o or treat leading zeros as decimal.

Bit width and what fits where

The converter reports how many bits a value needs and which fixed-width integer type will hold it. This matters when data crosses a boundary — a database column, a network protocol, an embedded register.

TypeBitsUnsigned maxSigned range
uint8 / byte8255−128 to 127
uint16 / short1665,535−32,768 to 32,767
uint32 / int324,294,967,295−2,147,483,648 to 2,147,483,647
uint64 / long6418,446,744,073,709,551,615±9.22 × 1018
On negative numbers. This tool displays negatives as sign-and-magnitude — a minus sign followed by the absolute value's digits. Real hardware stores signed integers in two's complement, where −1 in 8 bits is 11111111, not -1. Two's complement requires a fixed width to be meaningful, and this converter works with arbitrary-precision values that have no inherent width. If you need a two's complement pattern, add 2width to the negative value and convert the result — for −1 in 8 bits: 256 − 1 = 255 = 11111111.

Frequently asked questions

Why does my hex value have a leading zero?
Convention rather than necessity. Hex is usually written in byte pairs, so a value under 16 gets a leading zero: 0F rather than F. The values are identical. The padded bit patterns above show the same idea at 8, 16 and 32 bits.
What is the largest number this handles?
The converter uses BigInt, so precision is limited only by memory rather than by the 2⁵³ safe-integer ceiling of ordinary JavaScript numbers. Inputs up to 2,000 digits are accepted, which is far beyond any practical need.
Why is base 36 the maximum?
Because 10 digits plus 26 letters gives exactly 36 symbols. Going higher requires either case sensitivity (base 62, used in some URL shorteners) or a defined alphabet such as Base64's. Base 36 is the largest base expressible with case-insensitive alphanumerics, which is why it appears in short IDs and licence keys.
How do I convert a fraction or a decimal point?
This tool handles integers only. Fractional conversion works by repeatedly multiplying the fractional part by the target base and taking the integer part each time. Note that many decimal fractions have no exact binary representation — 0.1 in decimal is infinitely repeating in binary, which is the root of nearly every floating-point rounding surprise.
Why is 0.1 + 0.2 not 0.3?
Because neither 0.1 nor 0.2 can be represented exactly in binary floating point, so both are stored as very close approximations whose sum is very slightly above 0.3. It is a base-conversion problem, not a language bug — the same result appears in Python, Java, C and JavaScript alike.
What are octal file permissions?
Three octal digits, one each for owner, group and others. Each digit is three bits: read (4), write (2), execute (1). So 755 means owner 7 = 4+2+1 = read/write/execute, group and others 5 = 4+1 = read/execute. Convert 755 from octal above and the binary pattern 111 101 101 maps directly onto the nine permission flags.

Where bases show up in practice

Base conversion is rarely an end in itself. It appears whenever a value is really a packed collection of bits.

ContextBaseWhy
CSS and HTML colours16Three bytes, two hex digits each: #CC2936
Unix file permissions8Three bits per digit maps onto read/write/execute
Memory addresses, hex dumps16One digit per nibble, so byte boundaries stay visible
MAC addresses16Six bytes, written as twelve hex digits
Unicode code points16U+1F680 is the rocket emoji
Subnet masks2The prefix boundary is only visible in binary
Feature flags and bitmasks2 / 16Each bit is an independent boolean
Short IDs and licence keys36 / 62Maximum density in case-insensitive alphanumerics

Bitmasks: the most common practical use

A bitmask packs several booleans into one integer, each flag occupying a distinct bit. Reading one requires thinking in binary, which is where a converter earns its place.

A permissions bitmask
READ   = 1  = 0b0001
WRITE  = 2  = 0b0010
DELETE = 4  = 0b0100
ADMIN  = 8  = 0b1000

User value 11 = 0b1011 = READ + WRITE + ADMIN (not DELETE)

Testing a flag is value & FLAG; setting one is value | FLAG; clearing one is value & ~FLAG. Paste an unfamiliar permission integer into the converter, read the binary, and the individual flags become obvious immediately — which is far faster than working through the arithmetic by hand.

The same pattern underlies Unix chmod, TCP header flags, CPU status registers and most feature-flag systems. Once you can read an integer as bits, all of them become legible.

Related tools