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.
🌐
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:
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
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
Big difference between float 32 and float 64 operations in IIR?
It depends on how extreme the filter is, the filter structure, and what frequencies you're looking at. Very low frequencies (DC filters) can have trouble with 32 bit floating point. It can also depend on the order of operations how the filter is actually implemented in assembly, as rounding errors can accumulate and cause overflow or underflow issues. More on reddit.com
🌐 r/DSP
14
8
February 28, 2016
🌐
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.
🌐
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.
🌐
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
🌐
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.
Find elsewhere
🌐
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) ...
🌐
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.
🌐
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....
🌐
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.
🌐
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...
🌐
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 ...
🌐
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 ...
🌐
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....
🌐
Whattoknow
whattoknow.blog › python-float-size-limits
Python Float Size: The Shocking Limits You Need to Know! - whattoknow.blog
Within Python, this standard directly impacts the representation and behavior of the float datatype, giving rise to crucial limitations. Specifically, the python float size, typically 64-bit (double precision), defines the maximum range and precision of numerical values.
🌐
Execute Program
executeprogram.com › courses › python-for-programmers › lessons › size-and-precision-of-numbers
Python for Programmers: Size and Precision of Numbers
However, Python doesn't always raise an OverflowError with very large floats. For example, we can use scientific notation to write a number that's too big to fit in a float. In that case we get infinity, not an exception. ... The other important consideration with floats is that they aren't guaranteed to be precise. ... The size and precision limitations on floats aren't specific to Python.
🌐
Sololearn
sololearn.com › en › Discuss › 2671032 › maximum-binary-size-of-float-in-python
Maximum "binary" size of float in python
January 20, 2021 - Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
GeeksforGeeks
geeksforgeeks.org › python › float-in-python
float() in Python - GeeksforGeeks
September 18, 2025 - Example: This code raises an OverflowError because 10**309 exceeds Python’s floating-point range.
🌐
Programiz
programiz.com › python-programming › methods › built-in › float
Python float()
Online Python Online JavaScript Online SQL Online Java Online HTML Online C Online C++ Online C# Online PHP Online Swift Online Kotlin Online TypeScript Online Go Online Rust Online Scala Online Dart Online R Online Ruby ... The float() method returns a floating point number from a number or a string.