FlowingDev

Number Bases, Explained: Why Computers Count Funny

Learn how number base systems like binary, octal, decimal, and hexadecimal work to represent the same number in different ways, a key concept in computing.

Try the tool: Base Converter

In one sentence

Number base conversion is the art of translating a number from one counting system (like our familiar ten-digit decimal) to another (like the computer's native two-digit binary), without changing its actual value.

The problem it solves

Humans, for the most part, have ten fingers. This biological hardware made counting in groups of ten—the decimal or base-10 system—feel incredibly natural. We have ten unique symbols (0 through 9), and once we hit nine, we roll over: we add a new digit to the left and start back at zero. Ten is 10, one hundred is 100, and so on. Easy peasy.

Computers, on the other hand, have different "fingers." Their fundamental hardware is the transistor, a microscopic switch that can be either on or off. That's it. Two states. This makes a two-symbol system—binary or base-2—the computer's native language. The two symbols are 0 (off) and 1 (on).

This creates a translation problem. To a computer, the human number 237 is meaningless. It needs to be represented as a series of ons and offs. That same number, 237, in binary is 11101101.

While computers are fluent in binary, humans are... not. Reading a long string of ones and zeros is a recipe for a headache and eye strain. To bridge this gap, developers came up with convenient shorthands: octal (base-8) and hexadecimal (base-16). These "power of two" bases are trivial to convert to and from binary, but they compress long binary strings into much more readable chunks.

Number bases exist to solve this fundamental mismatch between how humans think about numbers and how machines physically store them. They are the rosetta stone that lets us peek into the machine's mind without getting lost in a sea of ones and zeros.

How it works under the hood

The magic behind any number base is a concept called positional notation. The position of a digit determines its value. Let's break it down.

What's a "base," anyway?

Think of your car's odometer. When the rightmost digit goes from 9 to 0, the digit to its left clicks up by one. Each digit's "place" represents a power of ten.

The number 427 in our everyday base-10 system really means:

  • 4 hundreds (4 × 10²)
  • 2 tens (2 × 10¹)
  • 7 ones (7 × 10⁰)

Add them up: 400 + 20 + 7 = 427.

A "base" is just the number we're raising to a power for each position. For base-10, it's 10. For binary (base-2), it's 2. For hexadecimal (base-16), it's 16. The formula is the same, only the base (b) changes:

... + (digit × b²) + (digit × b¹) + (digit × b⁰)

From our world (Decimal) to theirs (Any Base)

Let's convert our decimal number 427 to binary (base-2). The algorithm is "repeatedly divide by the target base and record the remainder."

Division Result Remainder
427 ÷ 2 213 1
213 ÷ 2 106 1
106 ÷ 2 53 0
53 ÷ 2 26 1
26 ÷ 2 13 0
13 ÷ 2 6 1
6 ÷ 2 3 0
3 ÷ 2 1 1
1 ÷ 2 0 1

Now, read the remainders from the bottom up.

So, decimal 427 is binary 110101011.

This method works for any base. To convert 427 to hexadecimal (base-16), you just divide by 16. (Note: In base-16, we need more than 10 symbols, so we use A for 10, B for 11, ..., up to F for 15).

  • 427 ÷ 16 = 26 with a remainder of 11 (which is B in hex).
  • 26 ÷ 16 = 1 with a remainder of 10 (which is A in hex).
  • 1 ÷ 16 = 0 with a remainder of 1.

Reading bottom-up gives us 1AB. So, decimal 427 is hex 1AB.

From their world (Any Base) back to ours (Decimal)

To go the other way, we use the positional notation formula we saw earlier. Let's convert binary 110101011 back to decimal. We multiply each digit by 2 raised to the power of its position (starting from 0 on the right).

  1 * 2^8 = 256
+ 1 * 2^7 = 128
+ 0 * 2^6 = 0
+ 1 * 2^5 = 32
+ 0 * 2^4 = 0
+ 1 * 2^3 = 8
+ 0 * 2^2 = 0
+ 1 * 2^1 = 2
+ 1 * 2^0 = 1
----------------
Total     = 427

It works! Let's try it with hex 1AB:

  1 * 16^2 = 256
+ A * 16^1 = (10 * 16) = 160
+ B * 16^0 = (11 * 1)  = 11
-------------------------
Total      = 427

Boom. Same number, different outfits.

The Hex and Octal Shortcut

So why bother with hex and octal? Because they are "power-of-two" bases.

  • Octal is base-8, and 8 = 2³. This means every single octal digit maps perfectly to a group of three binary digits.
  • Hex is base-16, and 16 = 2⁴. This means every single hex digit maps perfectly to a group of four binary digits (called a "nibble").

Let's take a big binary number: 1101011101001111 To read this, a human has to scan every digit. But to convert it to hex, you just chunk it into groups of four from the right:

1101 | 0111 | 0100 | 1111

Now, convert each chunk:

  • 1101 is 8+4+0+1 = 13, which is D
  • 0111 is 0+4+2+1 = 7
  • 0100 is 0+4+0+0 = 4
  • 1111 is 8+4+2+1 = 15, which is F

So, 1101011101001111 is simply D74F in hex. Infinitely more readable and less error-prone. This is not just a calculation; it's a direct transcription. This is why developers love hexadecimal: it's the perfect human-readable wrapper for binary data.

Real-world stories

The Case of the Cryptic Color

A junior front-end developer receives a design mockup from a UI designer. The brand's primary color is listed as #E63946. The developer knows this is a shade of red, but how much red? And what about the other colors? They pop the hex code into a converter. E63946 is actually three separate hex numbers: E6 for Red, 39 for Green, and 46 for Blue.

  • E6 in hex converts to 230 in decimal. Okay, so it's a lot of red (out of a max of 255).
  • 39 in hex converts to 57 in decimal. A little bit of green.
  • 46 in hex converts to 70 in decimal. A little bit of blue.

By breaking down the hex code, the developer understands the color's composition. It's not just "red," it's "mostly red, with a small, similar amount of green and blue to make it less stark."

The lesson: Hexadecimal is the language of color on the web. Understanding it helps you move beyond copying-and-pasting codes and truly understand the colors you're working with.

The Filesystem Permissions Puzzle

A sysadmin is trying to secure a newly uploaded script, deploy.sh, on a Linux server. They need the owner to be able to read, write, and execute it, but the group and everyone else should only be able to read and execute it. They've seen the command chmod 755 deploy.sh used everywhere, but they've always just treated it as a magic incantation.

This time, they look it up. The number 755 is octal. It represents three sets of permissions: Owner, Group, and Others.

  • Owner permission is 7. In binary, 7 is 111.
  • Group permission is 5. In binary, 5 is 101.
  • "Others" permission is 5. In binary, 5 is 101.

Each binary digit corresponds to a specific permission: read (r), write (w), and execute (x).

  • 111 means rwx (Read, Write, Execute are all ON).
  • 101 means r-x (Read and Execute are ON, Write is OFF).

So, chmod 755 sets the permissions to rwxr-xr-x, which is exactly what was needed. The mystery was solved.

The lesson: Octal provides a super-concise shorthand for managing file permissions, which are fundamentally a set of on/off flags (bits).

The Bit-Flipping Bug

A developer building an embedded system for a smart thermostat needs to save device settings to a tiny chunk of memory. To save space, they use a single byte (8 bits) as a "flag register." Each bit represents a setting: isHeating, isCooling, fanOn, hasWifiConnection, etc.

One day, bug reports flood in: "When I turn on the fan, the heat also kicks on!" The developer is baffled. The code for turning on the fan looks right. But when they inspect the settings byte in memory, they see the problem. Let's say the fan is the 2nd bit (value 2¹ = 2) and heat is the 3rd bit (value 2² = 4). The code was supposed to set the byte to ...010 (fan on). Instead, it was setting it to ...110 (fan on AND heat on). The decimal value would have been 6 instead of 2, which is not immediately obvious. But looking at the binary representation 00000110 made the problem crystal clear: two bits were being flipped instead of one. A faulty bitwise operation was the culprit.

The lesson: For low-level programming, memory debugging, or working with hardware registers, thinking in binary isn't optional—it's the only way to see what's actually happening.

Common mistakes and traps

  • Forgetting your prefixes. In many programming languages (like C, Java, or JavaScript), a number starting with 0 is interpreted as octal. 010 is not ten, it's eight! A number starting with 0x is hexadecimal. 0x10 is sixteen. Not knowing this can lead to some truly wild bugs.
  • Mixing up O/0 and I/1. When you're staring at long hex or binary strings, it's easy for your eyes to glaze over and mistake the letter O for a zero, or I for a one. Hex doesn't use O or I, but other base conversions might, and it's a classic "fat-finger" error.
  • Assuming a standard for bases > 16. The characters for binary (0-1), octal (0-7), decimal (0-9), and hex (0-9, A-F) are standardized. But what about base-22 or base-36? Most systems use 0-9 followed by A-Z, but it's not a universal law. Always verify the character set (or "alphabet") being used when dealing with less common bases.
  • Ignoring integer limits. A 64-bit hex number like 0x7FFFFFFFFFFFFFFF represents a gargantuan number. If you try to convert it and store it in a standard 32-bit integer variable in your program, it won't fit. This will cause an "integer overflow," where the number wraps around to a negative value or throws an error.

Why it belongs on your radar

Even if you're not a low-level C programmer, you'll bump into different number bases constantly. You should think about them whenever you're:

  • Picking a color in CSS or from a design tool (#RRGGBB).
  • Dealing with hashed values like API keys or Git commit SHAs, which are almost always hex.
  • Setting permissions on a web server (chmod).
  • Working with low-level data formats, network protocols, or anything that uses bitmasks (e.g., feature flags).
  • Encountering error codes or memory addresses in a debugger.
  • Trying to understand how computers actually work. It's a foundational concept that demystifies a lot of digital magic.

Go deeper

Theory done. Time to get your hands dirty — 100% in your browser.

Try the tool: Base Converter