In C, an int and float each take up 4 bytes, or 32 bits, in memory. The difference between int and float is not the number of bits they take up in memory, but rather in the way the ALU (Arithmetic Logic Unit) treats each number. An int is treated as the integer represented by its bits using two's complement notation. A float, on the other hand, is encoded (typically in IEEE 754 format) to represent a number in exponential form (e.g. 2.9979245x108 is a number in exponential form with base 2.9979245 and exponent 8). The number of significant digits in the decimal representation of a floating point number is always about the same: 6-9 digits for 32-bit float and 15-17 digits for a 64-bit float (or double). For example, the value 4.2949673x109 is what I get as the decimal representation of the closest 32-bit float to the number 232 , and it has 8 significant digits.

It can be a common misconception that a floating point number somehow represents more information than a fixed-point number, which is not true. While a 32-bit float can represent numbers of greater magnitude than a 32-bit int, it cannot represent all of them with as much precision. In total, this answer derives that a 32-bit float can represent around 4,278,190,081 unique numbers. This other answer contains a nice plot showing how these 32-bit floats are distributed on the real line.

While an int may not be able to represent numbers with as large of a magnitude as a float, it represents each number in its valid range (-232 to 232-1) with the same precision. The largest number it can represent is 2,147,483,647 and has 10 significant digits. And in total, it can represent 232=4,294,967,296 unique numbers, which is more than for the 32-bit float!

Answer from Brian on Stack Overflow
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › c-language › type-float
Type float | Microsoft Learn
Single-precision values with float type have 4 bytes, consisting of a sign bit, an 8-bit excess-127 binary exponent, and a 23-bit mantissa. The mantissa represents a number between 1.0 and 2.0.
🌐
Quora
quora.com › How-many-bytes-is-a-float-in-Java
How many bytes is a float in Java? - Quora
Answer: Hi! float data type size is 4 bytes! The float data type can store fractional numbers from 3.4e−038 to 3.4e+038. You should use a floating data type whenever you need a number with a decimal, such as 3.99 or 9.6715. Note that you should end the value with an "f" when using the float da...
Discussions

floating point - Float and Int Both 4 Bytes? How Come? - Stack Overflow
Int is 4 bytes with a range of +- 2^31 Float is 4 bytes with a range of +- 1.2E(+- 38) Float encompasses so many more points on the Real Line and yet is equal to the size of int. Is the Sign-Expon... More on stackoverflow.com
🌐 stackoverflow.com
How is the sizeof(float) 4 bytes?
Also, how does the sizeof(numbers) equal to 12 bytes? I feel so lost with this concept. ... The size of a float or other data types for that matter is dependent upon the system. More on teamtreehouse.com
🌐 teamtreehouse.com
4
July 9, 2014
How many bytes is a float
A float is a data type used in programming to represent floating-point numbers—numbers that have a decimal point. The number of bytes a float occupies depends on the computer architecture and programming language, but the most common representation follows the IEEE 754 standard · Typically, ... More on en.sorumatik.co
🌐 en.sorumatik.co
1
0
July 28, 2025
c# - What is the size in Byte of this kind of float? - Stack Overflow
I want to know what is the size in memory in bytes of this float number for example -0,005606111. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Oracle
docs.oracle.com › cd › E19253-01 › 817-6223 › chp-typeopexpr-2 › index.html
Data Types and Sizes
Floating-point constants may be used to initialize data structures, but floating-point arithmetic is not permitted in D. D provides a 32-bit and 64-bit data model for use in writing programs. The data model used when executing your program is the native data model associated with the active operating system kernel. You can determine the native data model for your system using isainfo -b. The names of the integer types and their sizes in each of the two data models are shown in the following table.
Top answer
1 of 8
63

In C, an int and float each take up 4 bytes, or 32 bits, in memory. The difference between int and float is not the number of bits they take up in memory, but rather in the way the ALU (Arithmetic Logic Unit) treats each number. An int is treated as the integer represented by its bits using two's complement notation. A float, on the other hand, is encoded (typically in IEEE 754 format) to represent a number in exponential form (e.g. 2.9979245x108 is a number in exponential form with base 2.9979245 and exponent 8). The number of significant digits in the decimal representation of a floating point number is always about the same: 6-9 digits for 32-bit float and 15-17 digits for a 64-bit float (or double). For example, the value 4.2949673x109 is what I get as the decimal representation of the closest 32-bit float to the number 232 , and it has 8 significant digits.

It can be a common misconception that a floating point number somehow represents more information than a fixed-point number, which is not true. While a 32-bit float can represent numbers of greater magnitude than a 32-bit int, it cannot represent all of them with as much precision. In total, this answer derives that a 32-bit float can represent around 4,278,190,081 unique numbers. This other answer contains a nice plot showing how these 32-bit floats are distributed on the real line.

While an int may not be able to represent numbers with as large of a magnitude as a float, it represents each number in its valid range (-232 to 232-1) with the same precision. The largest number it can represent is 2,147,483,647 and has 10 significant digits. And in total, it can represent 232=4,294,967,296 unique numbers, which is more than for the 32-bit float!

2 of 8
32

I just find it highly surprising that something which represents (virtually) the entire real line is of the same size as that of which represents the Integers.

Perhaps this will become less surprising once you realize that there are lots of integers that a 32-bit int can represent exactly, and a 32-bit float can't.

A float can represent fewer distinct numbers than an int, but they're spread over a wider range.

It is also worth noting that the spacing between consecutive floats becomes wider as one moves away from zero, whereas it remains constant for consecutive ints.

Top answer
1 of 4
5
Hi Vlatko, The size of a float or other data types for that matter is dependent upon the system. It has to do with the hardware architecture and the compiler. This float, 10498.429, would also be 4 bytes in memory. If a given computer system had a float size of 4 bytes then all floats are 4 bytes. You should not be thinking of these floating point numbers as characters in an array and counting how many characters there are. So when you do float numbers[] = {11.11, 22.22, 33.33}; The computer will set aside 12 bytes of memory because it knows each float is 4 bytes and it has to make room for 3 of them. The array could have been float numbers[] = {0.5, 9.3, 32897.4, 98.568}; and the computer will still reserve 12 bytes of memory. So when you do sizeof(numbers) that evaluates to 12 because you're asking for the total size in memory that is occupied by that array. I think one of the main points that you should get from this video is that you don't really need to know the size of a float. You want to do your calculations in a way that is independent of the system it's running on. For instance, the teacher calculated the array length with sizeof (numbers) / sizeof (float) and that comes out to 3 (12 / 4 = 3) Well, you could get that answer by doing this sizeof(numbers) / 4 The problem with this is that we have assumed a float size of 4. If we now run this program on a system where the float size is something else then we're going to get the wrong length. I hope this clears it up for you.
2 of 4
2
Here's a little extra information for the more curious: The way memory works is 0's and 1's. And the way computers count is by using a bunch of 0's and 1's all in a row (binary). The reason it's 0's and 1's has to do with storing electrical charge. If you want any more than two lonely numbers—0 and 1—you have to start setting them next to one another. A byte is 8 of these 0's and 1's set next to one another. Here's an example of a byte: 00101100. A byte has 256 possible combinations (2 to the power of 8). This is part of why you'll see RGB colors valued up to 256. If you have four bytes, you have over 4 billion possible combinations. Computers actually do something cool and tricky with floats in C (or in Objective-C, all the same), but ignoring that, someone back in the history of computing decided it would make sense for a float to be 4 bytes (or 32-bits). All "sizeof" is asking for in C is the number of bytes for that primitive float type. It doesn't matter what number you assign to that float, it's going to be 4 bytes regardless. So now if you have some array of floats, and you ask it what it's "sizeof" is, the C language is only going to understand you as asking what the size of a general float is. It doesn't actually understand that you have an array; it thinks you're just asking about a float. So if you want to keep track of how large your array is (for example, if you ever do anything in OpenGL), you'll need to save an integer that refers to the size of the float array. For instance, it might look like this: ```` C float myarray[] = malloc( sizeof(float) * 300 ); // suppose I have 300 elements in my array. int myarraysize = sizeof(float) * 300; // or you could use sizet instead of int. ````
🌐
Sorumatik
en.sorumatik.co › education
How many bytes is a float - Sorumatik
July 28, 2025 - A float is a data type used in programming to represent floating-point numbers—numbers that have a decimal point. The number of bytes a float occupies depends on the computer architecture and programming language, but the most common representation follows the IEEE 754 standard · Typically, ...
Find elsewhere
Top answer
1 of 5
2

1)

Does sizeof(variable) simply get the variable type and return sizeof(type), which in this case would explain the result ?

Except for variable-length arrays, sizeof doesn't evaluate its operand. So yes, all it cares is the type. So sizeof(someFloatNumb) is 4 which is equivalent to sizeof(float). This explains printf("%i\n", sizeof(someFloatNumb));.

2)

[..] But I can still store a 8 bytes real value in a float, and my compiler says nothing about it. Does/Can gcc grow the capacity of a type ? (managing multiple variables behind the curtains to allow us that sort of things)

No. Capacity doesn't grow. You simply misunderstood how floats are represented/stored. sizeof(float) being 4 doesn't mean it can't store more than 2^32 (assuming 1 byte == 8 bits). See Floating point representation. What the maximum value of a float can represent is defined by the constant FLT_MAX (see <float.h>). sizeof(someFloatNumb) simply yields how many bytes the object (someFloatNumb) takes up in memory which isn't necessarily equal to the range of values it can represent. This explains why printf("%f\n", someFloatNumb); prints the value as expected (and there's no automatic "capacity growth").

3)

printf("%i\n", sizeof(281474976710656));

This is slightly more involved. As said before in (1), sizeof only cares about the type here. But the type of 281474976710656 is not necessarily int. The C standard defines the type of integer constants according to the smallest type that can represent the value. See https://stackoverflow.com/a/42115024/1275169 for an explanation.

On my system 281474976710656 can't be represented in an int and it's stored in a long int which is likely to be case on your system as well. So what you see is essentially equivalent to sizeof(long).

There's no portable way to determine the type of integer constants. But since you are using gcc, you could use a little trick with typeof:

typeof(281474976710656) x;
printf("%s", x); /* deliberately using '%s' to generate warning from gcc. */

generates:

warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘long int’ [-Wformat=] printf("%s", x);


P.S: sizeof results a size_t for which the correct format specifier is %zu. So that's what you should be using in your 1st and 3rd printf statements.

2 of 5
2

This doesn't store "8 bytes" of data, that value gets converted to an integer by the compiler, then converted to a float for assignment:

float someFloatNumb = 0xFFFFFFFFFFFF; // 6 bytes of data

Since float can represent large values, this isn't a big deal, but you will lose a lot of precision if you're only using 32-bit floats. Notice there's a slight but important difference here:

float value = 281474976710656.000000;
int value   = 281474976710655;

This is because float becomes an approximation when it runs out of precision.

Capacities don't "grow" for standard C types. You'll have to use a "bignum" library for that.

Top answer
1 of 7
22

Excerpt from the C99 standard, normative annex F (The C++-standard does not explicitly mention this annex, though it includes all affected functions without change per reference. Also, the types have to match for compatibility.):

IEC 60559 floating-point arithmetic

F.1 Introduction

1 This annex specifies C language support for the IEC 60559 floating-point standard. The IEC 60559 floating-point standard is specifically Binary floating-point arithmetic for microprocessor systems, second edition (IEC 60559:1989), previously designated IEC 559:1989 and as IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE 754−1985). IEEE Standard for Radix-Independent Floating-Point Arithmetic (ANSI/IEEE 854−1987) generalizes the binary standard to remove dependencies on radix and word length. IEC 60559 generally refers to the floating-point standard, as in IEC 60559 operation, IEC 60559 format, etc. An implementation that defines __STDC_IEC_559__ shall conform to the specifications in this annex.356) Where a binding between the C language and IEC 60559 is indicated, the IEC 60559-specified behavior is adopted by reference, unless stated otherwise. Since negative and positive infinity are representable in IEC 60559 formats, all real numbers lie within the range of representable values.

So, include <math.h> (or in C++ maybe <cmath>), and test for __STDC_IEC_559__.

If the macro is defined, not only are the types better specified (float being 32bits and double being 64bits among others), but also the behavior of builtin operators and standard-functions is more specified.
Lack of the macro does not give any guarantees.

For x86 and x86_64 (amd64), you can rely on the types float and double being IEC-60559-conformant, though functions using them and operations on them might not be.

2 of 7
14

Does not say anything about the size.

3.9.1.8

There are three floating point types: float, double, and long double. The type double provides at least as much precision as float, and the type long double provides at least as much precision as double. The set of values of the type float is a subset of the set of values of the type double; the set of values of the type double is a subset of the set of values of the type long double. The value representation of floating-point types is implementation-defined. Integral and floating types are collectively called arithmetic types. Specializations of the standard template std::numeric_limits (18.3) shall specify the maximum and minimum values of each arithmetic type for an implementation.

🌐
Quora
quora.com › What-are-the-sizes-of-char-int-float-double-and-bool
What are the sizes of char, int, float, double, and bool? - Quora
Answer (1 of 2): The sizes of these data types differs due to different compilers, But here are the most common known sizes of these data types: 1. char: 1 byte 2. int: 4 bytes 3. float: 4 bytes 4. double: 8 bytes 5. bool: 1 byte
🌐
Reddit
reddit.com › r/learnpython › confusion about the size of floats in python
r/learnpython on Reddit: Confusion about the size of floats in python
June 8, 2015 -

Hi, not sure if this belongs here or in the main python sub, but decided to try here first. Anyways, I'm working on a project where I have a large text file which essentially contains a roughly 22,000x6,000 matrix of decimal values. This file is >2GB in size, however it's all encoded as text so the size of the data should become considerably smaller once I read them in and represent them as floats (they are mostly a single-digit integer part with 14 digit fractional part, along with the decimal point itself, each character of which UTF-8 can represent as a single byte since it's in the ascii range so each value should use 16 bytes if my calculations are correct). I figure that python represents floats as 8-byte double precision values, as the documentation says CPython will use a C double for your platform to represent them. My googling seems to support this assumption. That would mean that my original matrix in the file should be about 16220006000 ~= 2 GB (not including the whitespace separators), and the matrix in memory as floats should be 8220006000 ~= 1 GB, which while not small, should fit comfortably in memory on my laptop. However, this is not the case and I'm getting an out of memory error as a result.

As a result, I did some investigation and did >>> x = 3.14 >>> sys.getsizeof(x) 24 What the hell, how can this be??? What could CPython possibly be doing with 24 bytes? All I can figure is that there's an 8-byte pointer to a 16-byte double (huge!) and getsizeof() is counting both? Note that this is 64-bit CPython running on linux. I tried again on a 32-bit CPython running on windows and the answer I got was 16 bytes, so I figure this means a 4-byte pointer to an 8-byte double? Somewhat frustrated with this result, I tried again, this time using numpy.float16 because these are relatively small values and I don't need all that space anyways. For the linux 64-bit CPython I got 24 bytes again, and on the Windows 32-bit CPython I got 12 bytes. No idea at all what's happening here because if my previous guesses were correct I should have 8 and 4 byte pointers to 2-byte float16s, giving 10 and 6 bytes, respectively. Clearly I'm missing something here. Can anyone explain what's happening to me, and why so much memory is being used to store these values?

Also, I'm aware that my use case is memory intensive and I'm working on refactoring so that I don't need to have everything in memory at once. However, I'm still extremely curious about this behavior as it seems strange to me. Thanks!

Top answer
1 of 3
5
In python, everything is an object. That means that getsizeof doesn't just include the raw numerical data, or even a pointer to the raw numerical data, it includes the size of the entire object, including the numerical data, methods, etc. It is what is called an "opaque data type", which means that the exact internal representation is not visible to the user. I am not sure what you mean when you say you are using a "matrix". Python has no built-in multidimensional data structures. Do you mean you are using a numpy matrix or array? If so, the floats in a numpy array are not the same as python floats. In the case of a numpy array, they are true IEEE floats. The array as a whole is an object, but it stores the float data as raw floats in consecutive (or rather strided) regions of memory. So the overhead will only be present once, for the entire array, rather than once for each element of the array (as is the case for Python lists). This means that looking at what happens with an individual python float is not generalizable to a numpy float array. Anyway, the proper data structure for what you are doing is a Pandas DataFrame. You can store this as an HDF5 file so that you don't have to read the whole thing into memory at once. You can also use Dask or Blaze to do true, transparent out-of-core processing.
2 of 3
3
In CPython, every object begins with a reference count (of type ssize_t, i.e. a machine word) and a pointer to the type object for that object, which is necessary to be able to do any operations (e.g. invoke a method) on the object. That's two machine words right there off the bat, before you even start to talk about the data contained in the object. After that header comes a variable amount of data; in the case of a float object, it's just a C double value directly, so another eight bytes. For a 32 bit CPython, that's 4 + 4 + 8 = 16 bytes, for a 64 bit CPython, that's 8 + 8 + 8 = 24 bytes. Note that CPython can also be configured for debug builds, which adds two more pointers to that common header shared by all objects, which are used to form a doubly linked list of all objects on the heap, which can be used to track down reference counting bugs. Modules like Numpy can store raw values without these object headers, but that representation is completely hidden from you. Anything that you can actually access has to be an object. So while the values inside that Numpy array may only occupy 2 bytes each, the moment that you access any such value, it's converted (boxed) into a Python object that has the same header as any other object in Python. It's impossible not to see the contribution of that header using sys.getsizeof(), because you can't not pass a Python object to that function. Moreover, these structures are subject to alignment requirements. At the very least, each member of the structure must have its natural alignment (e.g. a member that's 4 bytes must be aligned to the nearest 4 byte boundary, a member that's 8 bytes must be aligned to the nearest 8 byte boundary, and so on.) That also means that the overall size of the structure must be padded to accommodate the member with the highest alignment, so for example if a struct contains an 8 byte pointer, then the size of the struct must be a multiple of 8; extra padding will be inserted at the end to make that happen. If that wasn't the case, then you couldn't pack structures back to back and still satisfy the alignment requirements of each individual member. Since the Python object header contains two machine words, that means its size must be a multiple of the native word size. In your example of a numpy.float16 object, on a 64 bit system, the layout would be 8 + 8 + 2 + 6 bytes padding = 24. And on a 32 bit system, 4 + 4 + 2 + 2 bytes padding = 12 bytes. But again, this only applies when you actually access these values as Python objects, but the whole point of Numpy is to avoid doing that. When you declare an ndarray in Numpy, all the values are packed without Python object headers, and are accessed by C in their raw form. If you multiply a Numpy array by a scalar for instance, that's all done in C without any boxing or unboxing. But if you write e.g. my_numpy_float12_array[42] then Numpy has to extract that value from its compact 2 byte representation and box in a Python object, resulting in a 24 byte Python object on a 64 bit system. It's impossible to access that 2 byte value directly, because you can only access Python objects. But as long as you use Numpy properly, that's not a problem, because you're rarely accessing individual elements like that. Again, the whole point of Numpy is to avoid doing as much as possible in Python and do everything in C, i.e. you should never manually loop over values, you should use whatever vector construct represents the operation you're trying to perform.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Why float numbers occupies more bytes than int? - Programming - Arduino Forum
December 18, 2021 - hi.... roughly, i have a sketch ... currentTemp(); ... float pastTemp = temps[pastHour]; ... according documentation floats takes 4 bytes and ints take 2 bytes.........
🌐
Actian
docs.actian.com › openroad › 6.0 › LangRef › Floating_Point_Data_Types.htm
Floating Point Data Types
Floating point numbers are stored in four or eight bytes. Internally, eight byte numbers are rounded to 15 decimal digits.
🌐
SoftHandTech
softhandtech.com › how-many-bytes-is-a-float
Understanding Floats: How Many Bytes is a Float? - SoftHandTech
April 6, 2025 - The primary difference between a float and a double lies in the amount of memory each occupies and the level of precision they offer. A float typically occupies 4 bytes of memory and provides a precision of about 7 decimal digits, while a double occupies 8 bytes and can represent numbers with ...
🌐
Quora
quora.com › Is-float-always-4-bytes
Is float always 4 bytes? - Quora
Answer (1 of 3): No. A IEEE single (often called a float), has 32 bits of data. A given system might have padding bits in an IEEE single, but I know of none that actually do, but it’s allowed. On the other hand, many systems with “single precision” floating point numbers that are not ...
🌐
W3Schools
w3schools.com › c › c_data_types.php
W3Schools.com
// Create variables int myNum = 5; // Integer (whole number) float myFloatNum = 5.99; // Floating point number char myLetter = 'D'; // Character // Print variables printf("%d\n", myNum); printf("%f\n", myFloatNum); printf("%c\n", myLetter); Try it Yourself » · The data type specifies the size and type of information the variable will store.
🌐
Reddit
reddit.com › r/learnprogramming › how does a float support bigger numbers than int?
r/learnprogramming on Reddit: How does a float support bigger numbers than int?
March 4, 2022 -

Hi!

I've got a question about C, which has popped up in my mind while following CS50's week 2 and looking up for extra info online.

Apparently, float and int take up the same amount of bytes, 4. However, according to this page, has its limit on 2,147,483,647, while float supports numbers as high as 3.4E+38.

I tried the following code on Programiz's compiler:

#include <stdio.h>

int main() {
    // Write C code here
    int i = 2000000000000000;
    printf("Int value: %i \n", i);
    
    float j = 2000000000000000.0;
    printf("Float value: %f", j);
    
    return 0;
}

Which returned:

Int value: 1233977344 
Float value: 1999999973982208.000000

While the integer overflows, as expected, the float returns a relatively precise value (not completely precise, but close to my input).

How is this possible, considering both take up 4 bytes of memory?

Thank you!

EDIT: Thank you all for your answers! :)

Top answer
1 of 6
12
The trick is that an integer just counts up from zero, but a float uses some of its size to say "how big is this number." Let's say we have 10 "digits" to represent a number. For an integer, we'd say "0000000000" means 0, "0000000001" means 1, and "9999999999" means 9,999,999,999. And that's as high as you can go. For a float, we've still got 10 digits, but let's say we use the first 8 to define numbers, and we use the last 2 to say "how far to move the decimal point." So "1234567890" might mean "take the number 1.2345678 and move the decimal 90 spaces to the right, a.k.a 1.2345678 x 10^90". See how the decimal point moves around? That's what they mean by a "floating point." That's pretty much exactly what floating point numbers do in real life, except they use binary instead of base 10. A 32 bit floating point number uses 1 bit to say "positive or negative," then 8 bits to say "how big is the exponent aka how many decimal points are we sliding the number", and then the last 23 bits are the "mantissa," which is the number that we're going to move the decimal point around. The good thing about floats is that they can express really huge or really tiny numbers in a compact amount of space, but the downside is that they have less precision than an integer, and the math gets weird around the edges. You can easily represent "about 1.23 quadrillion" as a float, but you can't represent precisely 1,230,000,000,000,007.
2 of 6
8
Floating point numbers are like the computer equivalent of scientific notation. The mass of the earth is 5.972e+27 grams. "5.972e+27" only takes up 9 characters, while 5972000000000000000000000000 takes up 28 characters. If you want to learn how it really works, here's a good concise intro: https://floating-point-gui.de/formats/fp/
🌐
Actian
docs.actian.com › vectorhadoop › 5.1 › SQLLang › 2._SQL_Data_Types.htm
2. SQL Data Types
... Nullable columns require one additional byte to store a null indicator. Note: If your hardware supports the IEEE standard for floating point numbers, the FLOAT type is accurate to 14 decimal precision (-dddddddddddd.dd to +dddddddddddd.dd) and ranges from -10**308 to +10**308.