Properties of a Python float can be requested via sys.float_info. It returns information such as max/min value, max/min exp value, etc. These properties can potentially be used to calculate the byte size of a float. I never encountered anything else than 64 bit, though, on many different architectures.

The items of a NumPy array might have different size, but you can check their size in bytes by a.itemsize, where a is a NumPy array.

Answer from Sven Marnach on Stack Overflow
🌐
EyeHunts
tutorial.eyehunts.com › home › python float size
Python float size - Tutorial - By EyeHunts
July 6, 2023 - In Python, the float type represents floating-point numbers and follows the IEEE 754 standard for floating-point arithmetic. The size of a float in Python is typically 64 bits or 8 bytes.
Discussions

Confusion about the size of floats in python
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. More on reddit.com
🌐 r/learnpython
5
3
June 8, 2015
getting size of primitive data types in python - Stack Overflow
If you just want to know the size of a single float, the easiest way is to simply instantiate some arbitrary float. For example: ... This returns 24 bytes in your case (and probably for most other people as well). In the case of CPython (the most common Python implementation), every float object ... More on stackoverflow.com
🌐 stackoverflow.com
AttributeError: 'float' object has no attribute 'time'
cal_time = 0.0 # the time to dequeue all the elements Why would the number 0.0 have an attribute "time"? More on reddit.com
🌐 r/learnpython
7
2
February 25, 2020
Python numpy arange for float, error
A quick google for "numpy arange maximum size" tells me that array is probably too big to fit in memory. Print out the size of the array you've asked for:(t_scale*4 - (t_mid + t_scale))/5e-12, I'm curious to know what it is. I'm also very curious to know why you want a step size so incredibly small and why you generate the array twice. Since it looks like you're just iterating on the array, this is a perfect place to use a generator. In Python 3, range() returns a generator; which will take up the same very small amount of memory no matter how many things you'll get when you iterate over it. More on reddit.com
🌐 r/learnpython
2
2
June 15, 2016
🌐
Python Tutorial
pythontutorial.net › home › advanced python › python float
An Essential Guide to Python float Type By Examples
September 10, 2022 - Unlike the integer type, the float type uses a fixed number of bytes. ... For the sake of simplicity, significant digits are all digits except leading and trailing zeros. For example, 0.25 has two significant digits, 0.125 has three significant digits, and 12.25 has four significant digits.
🌐
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.
🌐
IncludeHelp
includehelp.com › python › how-to-check-the-size-of-a-float.aspx
Python - How to check the size of a float?
# Import numpy import numpy as np # Getting information about float for f in (np.float32, np.float64): finfo = np.finfo(f) # Display result print("Information about float variants:\n", finfo) In this example, we have used the following Python basic topics that you should learn:
🌐
GeeksforGeeks
geeksforgeeks.org › python-float-type-and-its-methods
Float type and its methods in python - GeeksforGeeks
February 21, 2025 - a = 10.5 # Float declaration b = -3.14 # Negative float c = 2.0 # Even if it looks like an integer, it's a float d = 1.23e4 # Scientific notation (1.23 × 10⁴ = 12300.0) e = 5e-3 # Scientific notation (5 × 10⁻³ = 0.005) print(a,b,c,d,e) ...
Top answer
1 of 5
15

Running

sys.getsizeof(float)

does not return the size of any individual float, it returns the size of the float class. That class contains a lot more data than just any single float, so the returned size will also be much bigger.

If you just want to know the size of a single float, the easiest way is to simply instantiate some arbitrary float. For example:

sys.getsizeof(float())

Note that

float()

simply returns 0.0, so this is actually equivalent to:

sys.getsizeof(0.0)

This returns 24 bytes in your case (and probably for most other people as well). In the case of CPython (the most common Python implementation), every float object will contain a reference counter and a pointer to the type (a pointer to the float class), which will each be 8 bytes for 64bit CPython or 4 bytes each for 32bit CPython. The remaining bytes (24 - 8 - 8 = 8 in your case which is very likely to be 64bit CPython) will be the bytes used for the actual float value itself.

This is not guaranteed to work out the same way for other Python implementations though. The language reference says:

These represent machine-level double precision floating point numbers. You are at the mercy of the underlying machine architecture (and C or Java implementation) for the accepted range and handling of overflow. Python does not support single-precision floating point numbers; the savings in processor and memory usage that are usually the reason for using these are dwarfed by the overhead of using objects in Python, so there is no reason to complicate the language with two kinds of floating point numbers.

and I'm not aware of any runtime methods to accurately tell you the number of bytes used. However, note that the quote above from the language reference does say that Python only supports double precision floats, so in most cases (depending on how critical it is for you to always be 100% right) it should be comparable to double precision in C.

2 of 5
8
import ctypes
ctypes.sizeof(ctypes.c_double)
Find elsewhere
🌐
Tutorial Teacher
tutorialsteacher.com › python › python-number-type
Python Numbers: int, float, complex (With Examples)
As you can see, a floating point ... referred as inf, Inf, INFINITY, or infinity. For example, a float number 2e400 will be considered as infinity for most systems....
🌐
Python documentation
docs.python.org › 3 › tutorial › floatingpoint.html
15. Floating-Point Arithmetic: Issues and Limitations — Python 3.14.8 documentation
Floating-point numbers are represented in computer hardware as base 2 (binary) fractions. For example, the decimal fraction 0.625 has value 6/10 + 2/100 + 5/1000, and in the same way the binary fra...
🌐
Simplilearn
simplilearn.com › home › resources › software development › python float() function: key concepts [with examples]
Python float() Function: Key Concepts [With Examples]
November 27, 2024 - Learn how the float() function in Python converts a specified value into a floating point number. Syntax: float(value). A key function for numeric conversions.
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Python Land
python.land › home › python data types › python float: working with floating-point numbers
Python Float: Working With Floating-Point Numbers • Tutorial
September 16, 2025 - A floating-point number is a number ... or exponent. For example, the number 1.23 is a floating-point number with one digit before the decimal point and two digits after the decimal point....
🌐
Note.nkmk.me
note.nkmk.me › home › python
Maximum and Minimum float Values in Python | note.nkmk.me
August 11, 2023 - In Python, the float type is a 64-bit double-precision floating-point number, equivalent to double in languages like C. This article explains how to get and check the range (maximum and minimum values ...
🌐
Readthedocs
bitstring.readthedocs.io › en › stable › exotic_floats.html
Exotic Floating Point Formats — bitstring 4.3 documentation
The more bits in the mantissa, the greater the precision (~significant figures) of the values. An example of creation and interpretation of a bfloat: >>> a = Bits(bfloat=4.5e23) # No need to specify length as always 16 bits >>> a Bits('0x66be') >>> a.bfloat 4.486248158726163e+23 # Converted ...
🌐
NumPy
numpy.org › doc › stable › user › basics.types.html
Data types — NumPy v2.5 Manual
In this example, np.isclose accounts ... precision in calculations, see Floating-Point Arithmetic. Python’s floating-point numbers are usually 64-bit floating-point numbers, nearly equivalent to numpy.float64....
🌐
Real Python
realpython.com › ref › builtin-types › float
float | Python’s Built-in Data Types – Real Python
The built-in float data type represents floating-point numbers, which are numbers with a decimal point.
🌐
Whattoknow
whattoknow.blog › python-float-size-limits
Python Float Size: The Shocking Limits You Need to Know! - whattoknow.blog
Python's float type is typically implemented using double-precision floating-point numbers (64-bit) according to the IEEE 754 standard. This standard defines how floating-point numbers are represented in memory and allows for a balance between precision and range. The limited python float size is a consequence of this fixed-size representation.
🌐
Processing
processing.org › examples › integersfloats
Integers Floats / Examples / Processing.org
*/ int a = 0; // Create a variable "a" of the datatype "int" float b = 0.0; // Create a variable "b" of the datatype "float" void setup() { size(640, 360); stroke(255); } void draw() { background(0); a = a + 1; b = b + 0.2; line(a, 0, a, height/2); ...
🌐
Built In
builtin.com › data-science › how-to-use-make-float-in-python
How to Use Float in Python (With Sample Code!) | Built In
Yes, you can convert integers into floats in Python using the float() function. For example, float (5) becomes 5.0.
🌐
Mimo
mimo.org › glossary › python › float
Python Floats: Coding Essentials | Learn Now
Therefore, floating-point arithmetic can lead to precision issues and unexpected behavior. For example, checking for equality or summing up large amounts of data can be dangerous. ... sum = 0.1 + 0.2 print(sum) # Often outputs: 0.30000000000000004 print(sum == 0.3) # Often outputs: False · For high-precision needs, particularly in financial applications, Python's decimal module provides operations for decimal arithmetic.
🌐
APXML
apxml.com › courses › python-for-beginners › chapter-2-python-basics-variables-data-types-operators › python-numeric-types
Python Number Data Types | Integers and Floats
# Examples of floating-point numbers pi_approx = 3.14159 price = 49.99 temperature_fahrenheit = -20.5 account_balance = 0.0 # Using a decimal makes it a float distance_meters = 1.5e3 # Scientific notation for 1.5 * 10^3, which is 1500.0 print(pi_approx) print(distance_meters) Even if the number ...