Binary, hexadecimal and decimal are three ways of writing the same number. The base is simply how many digits the system has before it runs out and starts a new column: two in binary, ten in decimal, sixteen in hex. 11111111, 255 and FF are one quantity in three spellings. Decimal is what people count in, binary is what the hardware physically holds, and hex exists because one hex digit is exactly four binary digits — it is binary you can read without losing your place.
What the base of a number means
A base is a count of available digit symbols. Decimal has ten, 0 to 9. Binary has two, so it exhausts them immediately and columns pile up fast. Hex needs sixteen symbols, and since we only inherited ten, the letters A to F were drafted in to mean 10 through 15.
Each column is worth the base times the column to its right. Decimal 507 is 5×100 plus 0×10 plus 7×1. Binary 101 is 1×4 plus 0×2 plus 1×1, which is five. Hex 1F4 is 1×256 plus 15×16 plus 4×1, which is five hundred. The quantity never moves. Only the notation does, which is why "convert to binary" is a slightly misleading phrase — nothing is exchanged the way currency is. You are re-spelling a number that was already there.
All three are positional systems, and a positional system needs a zero to mark an empty column. That is the one thing Roman numerals never had: no place value, so no empty column, so no need for a symbol meaning none.
Why computers use binary
Because two states are the easiest thing to build and the hardest to misread. A wire is either above a voltage threshold or below it; a memory cell is charged or it is not. The gap between the two is wide, so noise has to be enormous before a 0 looks like a 1. Squeezing ten levels onto one wire would need nine thresholds, and every threshold is another place to guess wrong.
More levels than two do get used where the density is worth the trouble. A flash memory cell stores several bits by holding one of many charge levels, and gigabit Ethernet over copper sends five voltage levels per symbol. That is signalling and storage, though. The logic doing the arithmetic stays binary.
It has been tried the other way. ENIAC counted in decimal with ring counters, ten positions each, and the IBM 650 and 1620 were decimal machines too. Decimal did not vanish afterwards either: IBM's mainframe and POWER processors implement decimal floating point in hardware, because binary fractions cannot represent 0.01 exactly and that matters when the numbers are currency amounts. What changed is the foundation. Everything above the silicon — your integers, your text, your JPEGs — is a convention layered on switches that only know on and off.
Bits, bytes, and why 255 keeps turning up
One binary digit is a bit. Eight bits is a byte, and eight bits have two to the eighth, or 256, possible combinations: 0 through 255. That single fact explains an enormous amount of otherwise arbitrary trivia. An 8-bit colour channel runs 0–255. Each part of an IPv4 address runs 0–255. Endless "maximum length" limits in old file formats sit at 255 because the length was stored in one byte.
Why hex exists instead of just using binary
Sixteen is two to the fourth, so one hex digit covers exactly four bits and never straddles a boundary. Converting between the two is a lookup, not arithmetic — you swap each group of four bits for a single character and you are done. That is the entire reason hex won.
The saving is real. A 32-bit value is 32 characters of binary or 8 characters of hex. Read 11011110101011011011111011101111 aloud and you lose your place; DEADBEEF you read once and remember.
| Binary | Hex | Decimal |
|---|---|---|
| 0000 | 0 | 0 |
| 0001 | 1 | 1 |
| 0010 | 2 | 2 |
| 0011 | 3 | 3 |
| 0100 | 4 | 4 |
| 0101 | 5 | 5 |
| 0110 | 6 | 6 |
| 0111 | 7 | 7 |
| 1000 | 8 | 8 |
| 1001 | 9 | 9 |
| 1010 | A | 10 |
| 1011 | B | 11 |
| 1100 | C | 12 |
| 1101 | D | 13 |
| 1110 | E | 14 |
| 1111 | F | 15 |
Those sixteen rows are the whole of hex. Learn them and a memory dump becomes readable.
How to convert between them by hand
Binary to hex, and back
Split the bits into groups of four starting from the right, pad the leftmost group with zeros, then replace each group with its hex digit. 110110101 becomes 0001 1011 0101, which reads off the table as 1B5. Going the other way, expand each hex digit into its four bits and drop the leading zeros.
Starting from the right matters. Group 110110101 from the left instead and you get DA1, which looks like a perfectly ordinary hex number and is not the one you asked for.
Decimal to binary
This is the awkward direction, because ten has no clean relationship with two. Two methods work. Divide repeatedly by two and collect the remainders, then read them bottom to top. Or subtract the largest power of two that fits, repeatedly, and mark a 1 in each column you used.
Take 200. It contains 128, leaving 72. It contains 64, leaving 8. It contains 8, leaving nothing. Columns 128, 64 and 8 are set and the rest are clear, so 200 is 11001000 — and grouped into fours, 1100 1000, which is C8 in hex.
Doing that by hand is a good way to understand the mechanism and a slow way to get work done. Typing the number into a converter that shows all four bases at once is faster, and it will not quietly round: it uses arbitrary-precision integers, so a 200-digit value comes back with every digit intact. It is integers only, though. It will not convert 3.75, and it stops at base 36 because there is no agreed alphabet past z.
Where you meet each base in practice
- Hex colour codes.
#1E90FFis three bytes — red, green, blue — each written as two hex digits. How hex, RGB and HSL relate covers why the same colour has three notations too. - URLs. Percent-encoding writes each awkward byte as
%plus two hex digits, which is why a space becomes%20. The rules for which characters need encoding are less obvious than they look. - Hashes and IDs. A SHA-256 digest is 256 bits, printed as 64 hex characters. A UUID is 128 bits as 32 hex characters with dashes.
- Addresses. MAC addresses, IPv6 addresses, memory addresses in a stack trace, and error codes beginning
0xare all hex. - File permissions. Octal, base 8, in
chmod 755. - Timestamps. Plain decimal. A Unix timestamp is just a count of seconds, and a ten-digit number is far more likely to be one of those than anything hex.
Binary itself you rarely type. It shows up when individual bits carry separate meanings: permission flags, subnet masks, hardware registers, a bitfield in a protocol header.
Why does octal still exist?
Because eight is two cubed, so one octal digit is exactly three bits — and Unix permissions come in groups of three. In chmod 755, the 7 is 111: read, write, execute. The 5 is 101: read and execute, no write. Once you see the bits, 644 and 755 stop looking like magic numbers.
Outside that corner it is a leftover. The machines that made octal normal packed text into six-bit characters, and six bits is two octal digits exactly against an awkward one and a half hex ones. The IBM 7090's word was 36 bits, the PDP-8's was 12. Hex took over when the eight-bit byte did, because a byte is two hex digits exactly.
What goes wrong when bases get mixed up
A leading zero can mean octal. In C, and in JavaScript outside strict mode, 011 is nine, not eleven. Python 3 refuses the form and makes you write 0o11. Zero-padded numbers pasted out of a spreadsheet get caught by this constantly.
Large integers lose digits silently. JavaScript numbers are doubles, exact only up to two to the 53rd — 9007199254740992. Above that, parseInt and toString(16) return the nearest representable value with no error and no warning. If you are converting a snowflake ID or a hash, you need BigInt arithmetic or you are converting a number that is close to yours rather than yours.
Hex alone does not tell you the sign. In 8 bits, FF is 255 unsigned and −1 signed, and the bits are identical either way. Two's complement stores a negative by wrapping around the width, which is also why a signed byte runs from −128 to 127 rather than −128 to 128: zero occupies one of the positive slots.
Base64 is not base 64. It is a text encoding that slices a byte stream into six-bit groups and maps each to a printable character. It never treats the input as a number, so a base converter cannot produce it and a Base64 decoder is a different tool solving a different problem.
So which one should you use?
Decimal when a human is reading a quantity — prices, counts, durations. Hex when the value is really a pile of bits and you want to see them: bytes, addresses, colours, anything dumped from memory. Binary when individual bits have individual meanings and you need to check one of them.
And always label it. 0x for hex, 0b for binary, 0o for octal, in every language that accepts them. 10 written with no prefix could be two, eight, ten or sixteen, and the difference gets found later, by someone else, in production.
The number base converter here does all four bases at once as you type, shows the bit and byte count, and keeps the two's complement form at 8, 16, 32 and 64 bits in a panel underneath — which is usually the part you came for when a value is reading as negative and you cannot see why. It handles integers only, at any length.
The other half of reading raw data is knowing what the bytes stand for. URL encoding is the everyday case: once you can read two hex digits, a link full of percent signs turns back into ordinary text.
Frequently asked questions
What is the difference between binary, hex and decimal?
They are the same numbers written with different numbers of digits: two in binary, ten in decimal, sixteen in hex. 11111111, 255 and FF all mean one quantity. The base changes the notation, never the value.
Why do programmers use hexadecimal instead of binary?
Because 16 is 2 to the fourth, so one hex digit is exactly four bits and conversion is a lookup rather than arithmetic. A 32-bit value takes 32 characters in binary but only 8 in hex. It is the same information, four times shorter and far easier to read aloud.
How do I convert binary to hex quickly?
Group the bits into fours starting from the right, pad the leftmost group with zeros, then swap each group for its hex digit. 110110101 becomes 0001 1011 0101, which is 1B5. Grouping from the left instead of the right gives the wrong answer.
Is hexadecimal faster for a computer than decimal?
No. The hardware works in binary regardless of how you wrote the number, and the notation is discarded the moment the value is parsed. Hex is a convenience for the person reading the code, not a performance choice.
What does 0x mean in front of a number?
It marks the digits that follow as hexadecimal. 0x10 is sixteen, not ten, and 0x1F is 31. The same convention gives 0b for binary and 0o for octal. Without a prefix, a string of digits is ambiguous, and a leading zero on its own means octal in several languages.
Why is 255 such a common limit?
Because it is the largest number that fits in one byte: eight bits give 256 combinations, counted from 0. Colour channels, IPv4 address parts and plenty of old file format limits all stop there for that reason.
Last updated September 19, 2026