Why use this calculator
Every developer, network engineer and electronics student meets the same four bases constantly, and translating between them by hand is slow and error-prone. Binary is how hardware actually stores everything, so it explains overflow, bit masks and why a signed byte stops at 127. Hexadecimal is a compact shorthand for binary, because one hex digit is exactly four bits, which is why memory addresses, MAC addresses, hash digests and CSS colours are all written in it.
Octal survives mainly in Unix file permissions, where each digit encodes three permission bits. This converter shows all four at once rather than one at a time, so you can see the relationships instead of just the answers, and it validates the input against the base you chose rather than silently misreading it.
How to use it
- Choose the base your value is already written in first, because the same characters mean different numbers in different bases and 101 is five in binary, sixty-five in octal and two hundred and fifty-seven in hexadecimal. Then type the value.
- Prefixes are handled for you, so pasting 0xFF from source code, 0b1010 from a Python literal or 0o755 from a shell script all work without editing, and spaces, underscores and commas used as digit separators are ignored.
- The input is checked against the base you selected, so typing a digit that cannot exist in that base returns a clear message rather than a wrong answer.
- Values are supported up to 9,007,199,254,740,991, the largest integer JavaScript represents exactly.
What each result means
- Decimal (base 10)
- The everyday value with ten digits and place values that are powers of ten. This is the pivot every other conversion runs through.
- Binary (base 2)
- The value as a row of on and off bits, which is how it is physically held in registers, memory and on disk.
- Hexadecimal (base 16)
- Base sixteen using A to F for ten to fifteen. One hex digit is exactly four bits, so it is compact shorthand for binary.
- Octal (base 8)
- Base eight, three bits per digit. Its main modern survival is Unix and Linux file permission modes such as 755.
- Hex with prefix
- The 0x literal form that C, Java, Python, JavaScript and most assemblers accept directly in source code.
- Binary with prefix
- The 0b literal form accepted by Python, Rust, Go, modern C++ and JavaScript for writing bit patterns clearly.
- Binary grouped in nibbles
- The same bits padded and split into groups of four, because each group of four maps to exactly one hexadecimal digit.
- Bits required
- How many binary digits the value needs. It tells you whether the value fits in a given field width or register.
- Bytes required
- Bits rounded up to whole bytes, since memory and file storage are allocated in bytes rather than individual bits.
The formula
A number written in base b with digits d0 to dn has the value d0 x b^0 + d1 x b^1 and so on, where each digit is multiplied by the base raised to its position.
Binary
b = 2 with digits 0 and 1
Octal
b = 8 with digits 0 to 7
Decimal
b = 10
Hexadecimal
b = 16 with A to F standing for 10 to 15
Converting the other way repeatedly divides by the base and reads the remainders in reverse.
Bits required = floor(log2(value)) + 1
Bytes = bits divided by 8, rounded up
How this number is used in practice
Hexadecimal earns its place because of a single fact: one hex digit is exactly four bits, so two hex digits are exactly one byte. That is why a colour is written as six hex digits for three bytes of red, green and blue, why a MAC address is six hex pairs, why memory dumps and hash values are printed in hex, and why byte-level protocol documentation uses it throughout.
Reading FF as 255 and as eight bits all set becomes automatic quickly, and it makes bit masks legible in a way decimal never does.
Binary is where the limits of a system become visible. A single byte holds 0 to 255 unsigned, or -128 to 127 signed, which is why so many older systems had a ceiling of 255 items and why the number 127 turns up as a maximum in file formats and protocols.
Sixteen bits gives 65,535, the highest TCP or UDP port number and the reason for that particular figure. Thirty-two bits gives 4,294,967,295, the size of the entire IPv4 address space, which is exactly why IPv6 exists.
Octal looks like a curiosity until you use chmod. A Unix permission mode such as 755 is three octal digits, one each for owner, group and others, and each digit is three bits meaning read, write and execute. Seven is 111, so all three permissions; five is 101, so read and execute but not write.
Once you see it as binary it stops being a memorised incantation. Networking works the same way: a subnet mask is easiest to understand in binary, where /24 is simply twenty-four leading one bits.
Worked examples
Decimal 255, the value of one full byte
Binary 11111111, hexadecimal FF, octal 377, needing 8 bits and 1 byte.
Binary 10101010, a common test bit pattern
Decimal 170, hexadecimal AA, octal 252.
Hexadecimal FF0000, pure red in a CSS colour
Decimal 16,711,680, occupying 24 bits or 3 bytes of red, green and blue.
Octal 755, the Unix permission mode for an executable directory
Decimal 493 and binary 111101101, which reads as rwxr-xr-x across three groups of three bits.
When people use it
- Reading hex values out of a memory dump, packet capture or hash digest
- Converting a CSS or design-tool colour between hex and decimal RGB components
- Working out a Unix file permission mode from the read, write and execute bits you want
- Checking how many bits and bytes a value needs before choosing a field or column type
- Studying for a computer science, networking or digital electronics exam
Tips
- One hexadecimal digit is exactly four bits and two hex digits are exactly one byte. Almost every hex convention follows from that.
- Learn the powers of two to 1024 by sight. Recognising 255, 1023, 4095 and 65535 explains most arbitrary-looking limits in computing.
- Prefixes tell you the base in source code: 0x is hexadecimal, 0b is binary, 0o is octal, and a bare leading zero means octal in C.
- Group long binary strings into fours from the right before converting by hand, because each group becomes one hex digit.
- A Unix mode such as 644 is octal, not decimal. Each digit is three permission bits for owner, group and others in that order.
- Hex is not case sensitive, but pick one convention and keep it. Lowercase is conventional in CSS and uppercase in hardware documentation.
- When a value looks wrong, check the base you selected first. The string 101 is a valid number in all four bases and means something different in each.
What it assumes, and where it stops being accurate
- Only non-negative whole numbers are converted. Negative values, two's complement representation and fractions are out of scope.
- The maximum supported value is 9,007,199,254,740,991, the largest integer JavaScript can hold exactly.
- Prefixes 0x, 0b and 0o are stripped before parsing, and spaces, underscores and commas are ignored as digit separators.
- The value is validated against the base you selected, so a digit invalid in that base is rejected rather than partially parsed.
- Bits required is the minimum needed for the value itself and ignores sign bits, padding and alignment that a real data type would add.
Terms used on this page
- Bit
- A single binary digit, either 0 or 1. The smallest unit of information a computer stores.
- Byte
- Eight bits, holding 256 distinct values. Written as exactly two hexadecimal digits.
- Nibble
- Four bits, or half a byte, which is exactly what one hexadecimal digit represents.
- Radix
- Another word for the base of a number system: 2 for binary, 8 for octal, 10 for decimal, 16 for hexadecimal.
- Two's complement
- The standard way hardware represents negative integers, where the value depends on the width of the field.
Questions people ask
- What is binary and why does everything use it?
- Binary is base two, using only 0 and 1, which map directly onto the two stable states of an electronic switch. Every value in a computer, from an integer to a photograph, is ultimately a pattern of those states. Using two states rather than ten makes the hardware dramatically simpler and more reliable, which is why the entire industry settled on it.
- What does 0xFF mean?
- The 0x prefix marks a hexadecimal literal, so 0xFF is hexadecimal FF, which is 255 in decimal and 11111111 in binary. That is one full byte with every bit set. In colours, #FF0000 means the red channel at maximum with green and blue at zero, which renders as pure red on screen.
- Why is hexadecimal used instead of binary?
- Because it is far shorter and converts back perfectly. One hex digit represents exactly four bits, so a 32-bit value takes eight hex digits instead of thirty-two ones and zeros, with no ambiguity and no arithmetic needed to switch between them. That exact four-to-one mapping is why memory addresses, colours and hash values are all printed in hex.
- Where is octal still used?
- Almost entirely in Unix and Linux file permissions. A mode such as 755 is three octal digits, one each for owner, group and others, and each digit is three bits for read, write and execute. Seven means all three, five means read and execute. Octal also appears in some older file formats and in C literals written with a leading zero.
- Why do computing limits land on numbers like 255 and 65535?
- Because they are one less than a power of two. Eight bits hold 256 distinct values, so the largest unsigned value is 255. Sixteen bits hold 65,536 values, so the maximum is 65,535, which is also the highest TCP or UDP port number. Thirty-two bits give 4,294,967,295, the size of the whole IPv4 address space.
- Can this convert negative numbers or fractions?
- No. It handles non-negative whole numbers only. Negative values in real hardware are stored in two's complement, which depends on how wide the field is, so -1 is FF in eight bits and FFFFFFFF in thirty-two. Fractional binary uses floating point under IEEE 754, which is a separate representation with its own rounding behaviour.
Use this with
Number Base Converter answers one part of the question. These pick up where it stops: IPv4 Subnet Calculator, Data Storage Converter, Roman Numeral Converter and Screen PPI Calculator.
Where these figures come from
This calculation is jurisdiction-neutral arithmetic. No country-specific rules are applied.
- RFC 4648: The Base16, Base32, and Base64 Data Encodings. Normative definition of base 16 notation used in internet protocols
- W3C CSS Color Module Level 4. Hexadecimal colour notation on the web
- IEEE Standards Association. IEEE 754 floating point and related binary representation standards
Number Base Converter produces an estimate for general information. It is not financial, tax, medical, legal or engineering advice. read the full disclaimer. Spotted a wrong number? Report it and it gets fixed. The form picks up this calculator and the inputs you used.