How Computers Store Numbers: Binary and Beyond


Introduction
Of course computer understand everything. They’re computers, duh. You type 5, they see 5… right?
Nope. That would be too easy.
Behind the scenes, your fancy computer - the one that runs billion-dollar apps and plays vital 4K Netflix - has no clue what 5
means. All it knows is how to flip tiny electrical switches ON
or OFF
. That’s it. No magic. Just a lot of 1s and 0s pretending to be smart. 🙄
It’s one of those things no one really talks about — like pineapple on pizza or reading terms & conditions. Most people just skip it, pretend it’s boring, and move on with their lives. But here’s the thing: understanding how computers actually store numbers is kind of important — especially if you want to be more than just a copy-paste developer. So yeah, let’s walk through it. It won’t hurt… much. 😏
What does computer understand?
Everything inside a computer boils down to just two values: ON (1) and OFF (0). Nothing else. Computers don’t understand anything beyond that. Everything we’ve been seeing and using all our lives — from photos and videos to websites and apps — is, at the lowest level, just a bunch of 1s and 0s. Sounds a bit fishy, right? But that’s the truth. And this magical world of 1s and 0s is what we call binary numbers.
The Only Language Your Computer Actually Speaks
You and I count like — 0, 1, 2, 3… all the way to 9 and beyond. That’s decimal, or base-10. It has ten digits (0 to 9). Logical, right?
Now imagine trying to count using just two digits — 0 and 1. That’s what computers do. That’s binary, or base-2.
Here’s what it looks like:
Binary | Decimal |
0 0 0 1 | 1 |
0 0 1 0 | 2 |
0 0 1 1 | 3 |
0 1 0 0 | 4 |
1 0 0 0 | 8 |
And yes, your computer count like this. Slowly. But very, very fast. Think of binary like row of switches. Each switch is either ON(1) or OFF(0). Depending on the combination, you get different numbers.
We always read binary numbers from right to left. For example, if the binary number is 0001
, we start from the rightmost digit — that 1
— and then move left. Each position represents a power of 2, starting from 2^0.
What’s a Bit? What’s a Byte?
A bit is the smallest unit of data in a computer. It can be either ON (1) or OFF (0) — nothing in between, no maybe, no "kinda". Just yes or no, like a light switch.
Now put 8 of these bits together, and you get a byte.
👉 1 bit = 1 switch (1 or 0).
👉 8 bits = 1 byte → Can store 256 different values, from 0 to 255.
Think of a byte like a locker with 8 drawers. Each drawer can either be empty (0) or filled (1). Depending on which drawers are filled, you get a different combination — a different number.
How Computers Store Decimals (Floating Point)
You might think computers just write 12.34
as-is and call it a day.
But nope. That would be far too human. Computers need to store everything — including decimals — as binary.
But here’s the catch: binary doesn't have a decimal point. So… how does it work?
Two Common Ways to Store Decimals:
Fixed Point Representation - Imagine drawing a tiny, invisible line in your byte saying “2 digits for whole numbers, 2 for decimals.“ So
12.34
would be stored as1234
, and then the computer just knows to place the decimal point two digits from the end.🧐 But how does the computer know where the decimal goes? it doesn’t.
We (the programmer) decide that. It's an agreement, like “hey, every number has 2 decimal places — deal with it.”The computer only stores:
00000100 11010010
<— (That’s 1234 in binary).Floating Point Representation - This is where it gets juice. Computers use something called
IEEE 754 format
to store the real numbers (i.e. decimals). It’s kind of like writing numbers is scientific notation.We know:
12.34 = 1.234 x 10¹Computers do the same thing - but in binary:
1100.01 = 1.10001 x 2³
The numbers are broken into 3 parts:
Sign bit (positive or negative)
Exponent (how far to shift the decimal)
Mantissa (the actual digits of the number)
Though precision errors can happen, some decimals like 0.1
can’t be perfectly represented in binary. That’s why 0.1 + 0.2 = 0.30000000000000004
you might’ve seen this in JavaScript as well.
This topic is worth a couple of blog posts by itself, but for now we won’t go too deep into it — it can get very complex. Though don’t worry, we’ll get back to it. 😉
Where are these numbers actually stores?
Okay, so we’ve got bits, bytes, decimal, whatever. But where do they go?
RAM
This is where the data lives while the app is running.
RAM
is very fast, temporary, and volatile. The program we’re working with is stored inRAM
. It’s divided into memory chunks, and our data is stored there.int x = 5
It’s stored in the memory like 00000101 at some address 0×334324…
Registers
These are tiny, small units inside the
CPU
that are super fast and limited. They're used during the actual processing of the program. TheCPU
pulls data from RAM, processes it inregisters
, and then writes it back toRAM
.Hard Disk / SSD
This is where saved data goes. They're slower than
RAM
orregisters
, but they make up for it by storing tons of data — your files, apps, photos, everything.Cache
A quick-access memory between
RAM
andCPU
to speed things up. It stores recently used programs or instructions.
To explain the working suppose you’ve written a program:
let marks = 15
15
is turned into binary:00001111
Then it gets stored at some memory location in
RAM
.When
CPU
while processing the program needs to use it (in a calculation), it:Fetches the binary from
RAM
.Loads it into a
register
.Processes it.
Sends back the result.
Why This Matters?
We’ve gone through half a dozen sections, and you might be thinking:
“In a world of AI, autonomous vehicles, and aliens (probably), why should I care about bits and bytes?”
Fair question. But here’s the thing — everything you love and use online:
Your bank balance, your Instagram feed, those Ghibli-style profile pictures, even the photos of your beloved better half — they’re all just numbers under the hood.
Understanding how numbers are stored and manipulated actually helps you in tons of real-world situations:
🧱 System Design (e.g., how much storage will 10 million users need?)
🗃️ Database Planning (e.g., do you really need a 64-bit integer to store age?)
🐞 Debugging Weird Bugs (e.g., floating-point precision nightmares)
🧠 Memory Optimization (especially on low-resource or embedded devices)
So yeah, bits and bytes may sound tiny — but they’re kind of a deal.
Conclusion
This isn’t even the tip of the iceberg — it’s more like poking the iceberg from a safe distance while pretending we’re experts.
But hey, these fundamentals? They do matter. A lot.
Because no matter how many frameworks you learn or how many GitHub stars your repo gets, if you don’t get how the machine underneath works... you’re just fancy copy-pasting.
Mastering this stuff won’t turn you into a wizard overnight, but it will make your software faster, cleaner, and way less embarrassing when someone asks, “But how does that actually work?”
Subscribe to my newsletter
Read articles from Asif Siddique directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
