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
🌐
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.
People also ask

Why does Python have a limit on float size?
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.
🌐
whattoknow.blog
whattoknow.blog › python-float-size-limits
Python Float Size: The Shocking Limits You Need to Know! - ...
What is the approximate range of Python float size?
The approximate range of a python float size is from -1.8 x 10^308 to 1.8 x 10^308. Numbers outside of this range will be represented as positive or negative infinity.
🌐
whattoknow.blog
whattoknow.blog › python-float-size-limits
Python Float Size: The Shocking Limits You Need to Know! - ...
How does the limited python float size affect the precision of calculations?
Due to the finite python float size, not all real numbers can be represented exactly. This can lead to rounding errors in calculations, especially when dealing with very large or very small numbers, or when performing many iterative calculations. It's important to be aware of these limitations, especially in scientific or financial applications where precision is critical.
🌐
whattoknow.blog
whattoknow.blog › python-float-size-limits
Python Float Size: The Shocking Limits You Need to Know! - ...
🌐
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 ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-float-type-and-its-methods
Float type and its methods in python - GeeksforGeeks
July 11, 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) Python provides several built-in methods for float objects.
🌐
IncludeHelp
includehelp.com › python › how-to-check-the-size-of-a-float.aspx
Python - How to check the size of a float?
All the 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. However, a much easier approach to find the information about the float size is to use numpy.finfo() which is powerful enough to tell us about the properties of float or any other data type including the number of bits in the exponents, the number of bits in the mantissa, etc.
🌐
Python Tutorial
pythontutorial.net › home › advanced python › python float
An Essential Guide to Python float Type By Examples
September 10, 2022 - CPython implements float using C double type. The C double type usually implements IEEE 754 double-precision binary float, which is also called binary64. Python float uses 8 bytes (or 64 bits) to represent real numbers.
🌐
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.
Find elsewhere
🌐
Whattoknow
whattoknow.blog › python-float-size-limits
Python Float Size: The Shocking Limits You Need to Know! - whattoknow.blog
Specifically, the python float size, typically 64-bit (double precision), defines the maximum range and precision of numerical values. Understanding this size is vital when working with libraries such as NumPy, where large datasets can expose the limitations of float representation.
🌐
W3Resource
w3resource.com › python-interview › what-is-the-maximum-and-minimum-value-for-an-int-float-and-string-data-type-in-python.php
Exploring data type limits in Python
August 12, 2023 - Python's float data type has 15-17 decimal digits of precision. ... In Python, a string's length is limited by the system's memory. Since strings are immutable, the maximum size of a string is determined by the total memory available and the ...
🌐
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
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)
🌐
NumPy
numpy.org › doc › stable › user › basics.types.html
Data types — NumPy v2.4 Manual
For information about precision in calculations, see Floating-Point Arithmetic. Python’s floating-point numbers are usually 64-bit floating-point numbers, nearly equivalent to numpy.float64. In some unusual situations it may be useful to use floating-point numbers with more precision.
🌐
Real Python
realpython.com › ref › builtin-types › float
float | Python’s Built-in Data Types – Real Python
You'll explore integer, floating-point numbers, and complex numbers and see how perform calculations using Python's arithmetic operators, math functions, and number methods.
Top answer
1 of 1
5

I'll talk just about ints for now, and look at floats at the end.

In Python, unlike C and many other languages, int is not just a datatype storing a number. It is a full object, with extra information about the object (more detail here).

This extra information takes up lots of space, which is why the objects can seem unusually large. Specifically, it takes up 3 lots of 8 bytes (3*8=24 bytes). These are a reference count, a type and a size.

Python stores integers using a specific number of bytes depending on how large they are. Specifically:

0 <= n < 2**0:
    requires 24 bytes
2**0 <= n < 2**30:
    requires 28 bytes
2**30 <= n < 2**60:
    requires 32 bytes

In general, for every increase of 30 powers of 2 (for want of better terminology!), 4 extra bytes are required.

This pattern also follows for the negative numbers, just going the opposite direction.

These specific values are the values on my computer, but will vary depending on the environment you're running Python on. However, the general patterns are likely to be the same.

I believe (as explained a little here) that the reason zero alone uses less space is that the only int which can be represented using just 24 bytes is zero, so there is no need to additionally store the actual value, reducing the size. It's possible I've misunderstood this specific case so please correct me below if so!

However, floats are stored differently. Their values are simply stored using 64 bits (i.e. a double), which means there are 8 bytes representing the value. Since this never varies, there is no need to store the size as we do with integers, meaning there are only two 8 byte values to store alongside the specific float value. This means the total size is two lots of 8 bytes for the object data and one lot of 8 bytes for the actual value, or 24 bytes in total.

It is this property of not needing to store the value's size that frees up 8 bytes, which means 1.5 requires less space than 1.

🌐
Pytut
pytut.com › float
Python float (Floating Point Number) Data Type
11 people have already viewed this offer · domain transfers per month
🌐
Pytables
pytables.org › usersguide › datatypes.html
Supported data types in PyTables — PyTables 3.10.2 documentation
There are eight kinds of types supported by PyTables: bool: Boolean (true/false) types. Supported precisions: 8 (default) bits. int: Signed integer types. Supported precisions: 8, 16, 32 (default) and 64 bits. uint: Unsigned integer types. Supported precisions: 8, 16, 32 (default) and 64 bits. ...
🌐
Python documentation
docs.python.org › 3 › tutorial › floatingpoint.html
15. Floating-Point Arithmetic: Issues and Limitations — Python 3.14.3 documentation
On most machines today, floats are approximated using a binary fraction with the numerator using the first 53 bits starting with the most significant bit and with the denominator as a power of two.
🌐
Heurekadevs
heurekadevs.com › homepage › home › development › on the implementation of float and list types in python: part i
On The Implementation of Float and List Types in Python: Part I | Heurekadevs
January 26, 2022 - However, there should not be much loss of generality when we think of arbitrarily large lists and random floats. I describe these structures as they are implemented in CPython (specifically CPython 3.10.0). Let us start by saying that all data types in Python are objects.
🌐
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 - Working with floats is not much different from working with integers. You can do the usual addition, subtraction, multiplication, and division. x = 1.45 y = 4.51 # Add x and y z = x + y # Subtract x and y z = x - y # Multiply x and y z = x * y # Divide x and y z = x / yCode language: Python (python)