Data Types Size & Range
The fundamental atoms of programming. Compare 8-bit, 32-bit, and 64-bit types. Visualize memory footprints and overflow limits.
Data Type Visualizer
Select a type to see its memory footprint and range.
int
32-bit signed integer (Standard).
*Each block represents 1 Byte (8 bits). Uses half a 64-bit word.
Full Comparison Reference
| Type Name | Category | Size | Range / Description |
|---|---|---|---|
| boolean | Boolean | 1 bit | true / false |
| char | Character | 2 bytes | 0 to 65,535 (Unicode) |
| byte | Integer | 1 byte | -128 to 127 |
| short | Integer | 2 bytes | -32,768 to 32,767 |
| int | Integer | 4 bytes | -2.1B to 2.1B |
| long | Integer | 8 bytes | -9.22e18 to 9.22e18 |
| float | Float | 4 bytes | ±3.4e38 (7 digits) |
| double | Float | 8 bytes | ±1.7e308 (15 digits) |
| String | Complex | Sequence of characters. Size depends on length. | |
| Array | Complex | Fixed-size collection of same-type elements. | |
| Object | Complex | Collection of key-value pairs or properties. |
Why Data Types Matter
Every variable you create occupies physical space on a silicon chip. Choosing the right data type is the art of balancing Range (how big a number fits) vs Memory (how much RAM it costs).
In modern high-level languages like Python or JavaScript, these details are often hidden from you. But behind the scenes, the machine is still juggling bits and bytes. Understanding this helps you write code that is faster and crash-proof.
Stack vs Heap
Primitive Types (like int, boolean) usually live on the Stack. This is extremely fast memory. The CPU grabs the value directly.
Complex Types (like String, Array) live on the Heap. The variable on the stack is just a "pointer" (address) telling the CPU where to find the actual data in the Heap. This double-lookup makes them slightly slower.
Integer Overflow
What happens if you try to put the number 2,147,483,648 into a standard 32-bit integer?
It crashes OR wraps around to -2,147,483,648!
max = max + 1;
// Result: -2147483648 (Disaster!)
This is why financial software often uses long (64-bit) or special BigDecimal classes.
Storage Unit Cheatsheet
1 Bit (b)
A single switch. 0 or 1. The atom of computing.
1 Byte (B) = 8 Bits
Can store 256 different values (2^8). Enough for one ASCI character (like 'A').
1 Word (32 or 64 bits)
Calculations are fastest when data fits the CPU's "Word Size". On a 64-bit processor, fetching 64 bits (8 bytes) is just as fast as fetching 8 bits.
Floating Point Weirdness
Never use `float` or `double` for money! They sacrifice accuracy for range. They are scientific tools, designed to measure the distance to stars or the size of atoms.
Rule of Thumb: Use int or long (counting cents) for currency, or use Decimal libraries.
Frequently Asked Questions
What is the difference between Primitive and Non-Primitive data types?
Primitive types (int, char, boolean) are the basic building blocks. They store single values directly in memory (Stack). Non-Primitive (or Reference) types (Arrays, Strings, Objects) store a memory address pointing to a complex structure in the Heap.
Why is an Integer 4 bytes?
A standard 32-bit Integer uses 32 bits (4 bytes) of memory. This allows it to store values up to 2^31 - 1 (approx 2.1 billion). This is a balance between range and memory efficiency for most calculations.
What happens if a number gets too big for its type?
This is called "Overflow". In many languages (like Java/C++), the value "wraps around" to the minimum negative value. For example, adding 1 to the maximum Integer turns it into -2,147,483,648. This can cause catastrophic bugs.
What is the difference between float and double?
Precision. A float is 32-bit (single precision) and has about 7 decimal digits of accuracy. A double is 64-bit (double precision) and has 15 digits of accuracy. Always use double for math unless you are extremely memory constrained.
Why does 0.1 + 0.2 not equal 0.3 in programming?
Because computers use binary floating-point math (IEEE 754). Numbers like 0.1 cannot be represented perfectly in binary, just like 1/3 cannot be represented perfectly in decimal (0.333...). This results in tiny rounding errors.
Does a Boolean really need 1 byte?
Theoretically, a boolean is 1 bit (0 or 1). However, CPUs typically address memory in bytes, not bits. So, a single boolean variable often takes up a full byte (8 bits) for faster access. Arrays of booleans can be packed to use 1 bit each.
What is a "Signed" vs "Unsigned" type?
Signed types uses one bit (the Most Significant Bit) to represent the sign (+ or -), so they can store negative numbers. Unsigned types use all bits for the value, so they can store larger positive numbers but no negatives.
What is "Type Casting"?
Type casting is converting a variable from one type to another. "Widening" (int -> double) is usually safe and automatic. "Narrowing" (double -> int) must be done manually because you might lose data (e.g., the decimal part is truncated).
Why do we use "char" for text?
A char stores a single character code (like ASCII or Unicode). Strings are simply arrays of chars. In Java/C#, a char is 2 bytes (16-bit) to support Unicode characters from different languages.
What is "String Immutability"?
In many languages (Java, Python, C#), Strings cannot be changed once created. Modifying a string actually creates a brand new String object in memory. This improves security and thread-safety.
What is the Void type?
Void technically means "no type" or "absence of value". It is used as the return type for functions that perform an action but do not produce a result.
How big is an Object in memory?
It depends on its fields + overhead. An empty object in Java takes about 16 bytes of overhead (header). Then you add the size of all its variables. Plus padding to align it to 8-byte boundaries.
What is "Null"?
Null is a special value for Reference types indicating that the variable does not point to any object in memory. Accessing a property of a null variable causes a "Null Pointer Exception" (the billion-dollar mistake).
Why are 64-bit integers called "Long" or "Long Long"?
Naming history. In standard C, int was 16-bit. long was 32-bit. As computers grew to 32-bit and 64-bit architectures, int became 32-bit standard, so we needed long long for 64-bit. Java simplified this: int is 32, long is 64.
What is the Stack versus the Heap?
The Stack is fast, organized memory for function calls and primitive variables; it cleans itself up automatically. The Heap is a large pool for objects (complex types); it requires Garbage Collection to free up unused memory.