Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7857285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:59:37+00:00 2026-06-02T20:59:37+00:00

I want to check the size of int data type in python: import sys

  • 0

I want to check the size of int data type in python:

import sys
sys.getsizeof(int)

It comes out to be “436”, which doesn’t make sense to me.
Anyway, I want to know how many bytes (2,4,..?) int will take on my machine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:59:40+00:00Added an answer on June 2, 2026 at 8:59 pm

    The short answer

    You’re getting the size of the class, not of an instance of the class. Call int to get the size of an instance:

    >>> sys.getsizeof(int())
    28
    

    If that size still seems a little bit large, remember that a Python int is very different from an int in (for example) C. In Python, an int is a fully-fledged object. This means there’s extra overhead.

    Every Python object contains at least a refcount and a reference to the object’s type in addition to other storage; on a 64-bit machine, just those two things alone take up 16 bytes! The int internals (as determined by the standard CPython implementation) have also changed over time, so that the amount of additional storage taken depends on your version.

    int objects in CPython 3.11

    Integer objects are internally PyLongObject C types representing blocks of memory. The code that defines this type is spread across multiple files. Here are the relevant parts:

    typedef struct _longobject PyLongObject;
    
    struct _longobject {
        PyObject_VAR_HEAD
        digit ob_digit[1];
    };
    
    #define PyObject_VAR_HEAD      PyVarObject ob_base;
    
    typedef struct {
        PyObject ob_base;
        Py_ssize_t ob_size; /* Number of items in variable part */
    } PyVarObject;
    
    typedef struct _object PyObject;
    
    struct _object {
        _PyObject_HEAD_EXTRA
        union {
           Py_ssize_t ob_refcnt;
    #if SIZEOF_VOID_P > 4
           PY_UINT32_T ob_refcnt_split[2];
    #endif
        };
        PyTypeObject *ob_type;
    };
    
    /* _PyObject_HEAD_EXTRA is nothing on non-debug builds */
    #  define _PyObject_HEAD_EXTRA
    
    typedef uint32_t digit;
    

    If we expand all the macros and replace all the typedef statements, this is the struct we end up with:

    struct PyLongObject {
        Py_ssize_t ob_refcnt;
        PyTypeObject *ob_type;
        Py_ssize_t ob_size; /* Number of items in variable part */
        uint32_t ob_digit[1];
    };
    

    uint32_t means "unsigned 32-bit integer" and uint32_t ob_digit[1]; means an array of 32-bit integers is used to hold the (absolute) value of the integer. The "1" in "ob_digit[1]" means the array should be initialized with space for 1 element.

    So we have the following bytes to store an integer object in Python (on a 64-bit system):

    • 8 bytes (64 bits, Py_ssize_t, signed) for ob_refcnt – the reference count
    • 8 bytes (64 bits, PyTypeObject*) for ob_type – the pointer to the int class itself
    • 8 bytes (64 bits, Py_ssize_t, signed) for ob_size – which stores how many 32-bit integers are used to store the integer

    and finally a variable-length array (with at least 1 element) of

    • 4 bytes (32 bits) to store each part of the integer

    The comment that accompanies this definition summarizes Python 3.11’s representation of integers. Zero is represented not by an object with size (ob_size) zero (the actual size is always at least 1 though). Negative numbers are represented by objects with a negative size attribute! This comment further explains that only 30 bits of each uint32_t are used for storing the value.

    >>> sys.getsizeof(0)
    28
    >>> sys.getsizeof(1)
    28
    >>> sys.getsizeof(2 ** 30 - 1)
    28
    >>> sys.getsizeof(2 ** 30)
    32
    >>> sys.getsizeof(2 ** 60 - 1)
    32
    >>> sys.getsizeof(2 ** 60)
    36
    

    On CPython 3.10 and older, sys.getsizeof(0) incorrectly returns 24 instead of 28, this was a bug that was fixed. Python 2 had a second, separate type of integer which worked a bit differently, but generally similar.

    You will get slightly different results on a 32-bit system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What i want to do is, i want to check the Size for a
I want to check the file size of the file selected by user, at
I want to check the type of an Object. How can I do that?
I don't want check if an item with a value exists in the arraylist,
I want to check whether a string is a file name (name DOT ext)
I want to check the integrity of a backup of a Ubuntu disk, copied
I want to check to see if an XML document contains a 'person' element
I want to check whether a Tag (Case-Sensitive) exists in SQL Server 2005 table
I want to check if a particular page gets redirected or not. However, whenever
I want to check a particular website from various locations. For example, I see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.