ctypes.c_int64 is the ctypes data type for a signed 64-bit integer, the equivalent of C's int64_t. Use it for C functions, structures and binary formats that carry large counts, file sizes, nanosecond timestamps or database identifiers that do not fit in 32 bits.
The most common mistake with 64-bit values is not the type itself but the function declaration: if you leave out restype, ctypes reads the result as a 32-bit int and silently truncates it. This article shows how to avoid that.
ctypes.c_int64 is and how it maps to Cctypes.c_int64 valuesctypes.c_int64ctypes.c_int64 is and how it maps to Cc_int64 is an alias for whichever ctypes integer type is 8 bytes wide. That is c_long on 64-bit Linux and macOS, and c_longlong on Windows and 32-bit systems. Because long has different sizes across platforms, c_int64 is the portable choice when the C side uses int64_t.
| Property | Value |
|---|---|
| C type | int64_t |
| Size | 8 bytes (64 bits) |
| Signedness | signed, two's complement |
| Range | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
| Python side | int (read and write through .value) |
| Alias of | ctypes.c_long on 64-bit Linux and macOS, ctypes.c_longlong on Windows |
| Unsigned sibling | ctypes.c_uint64 |
c_int64 is a ctypes data type, not a separate module, even though the question is often phrased that way. You import it from the ctypes module and create instances of it.
ctypes.c_int64 valuesEvery ctypes simple type wraps a block of C-compatible memory. You read and write the wrapped value through the .value attribute, and ctypes.sizeof() reports the size in bytes.
Expected output:
The value 5,000,000,000 does not fit in 32 bits, but fits easily in 64 bits, whose range is about plus or minus 9.2 quintillion.
Integer ctypes types do not check ranges. When you store a Python integer that is too large, ctypes keeps only the low bits and reinterprets them as a signed value, exactly like a C cast. No exception is raised.
Expected output:
Python integers keep growing, but a c_int64 keeps only the low 64 bits. Hash functions, random number generators and checksums often rely on this wrap-around, so you may deliberately wrap results with c_int64(x).value.
ctypes.c_int64This example calls llabs from the C library. It first shows the truncation bug caused by the default return type, then the fix. The examples load the C library with ctypes.util.find_library() and ctypes.CDLL, which works on Linux and macOS. On Windows, load a DLL by name instead, for example ctypes.CDLL("msvcrt") or your own library.
Expected output:
The correct answer is 2 to the power 40, which is 1,099,511,627,776. With the default restype ctypes keeps only the lower 32 bits, which are all zero here, so it prints 0. Always set both argtypes and restype for every function you call. The exact wrong value can vary by platform, but it is never reliable.
Many APIs report time in nanoseconds or sizes in bytes as 64-bit integers. Structures with c_int64 fields keep these values intact.
Expected output:
Both fields hold values far above 2**31, so a 32-bit type would corrupt them. For pure Python code you do not need c_int64 at all, because Python's int is arbitrary precision. Use it only at the boundary with C.
restype, which truncates 64-bit return values to 32 bits.argtypes, so a large Python integer raises ArgumentError: int too long to convert.c_long for int64_t. It is 32 bits on 64-bit Windows.c_int64.c_uint64 for 0 to 18,446,744,073,709,551,615.It depends on the platform. On 64-bit Linux and macOS it is c_long; on Windows c_long is 32 bits and c_int64 is c_longlong.
The function probably has no restype, so ctypes decodes the result as a 32-bit int. Set func.restype = ctypes.c_int64.
No. Python integers have unlimited size. You need c_int64 only when passing values to C, or to emulate 64-bit wrap-around.
Use ctypes.c_int64(x).value for a signed result or x & 0xFFFFFFFFFFFFFFFF for an unsigned one.
ctypes.c_int64 is the signed 64-bit integer of ctypes, matching C's int64_t with a range of about plus or minus 9.2 quintillion. It is portable where c_long is not, wraps silently on overflow, and requires an explicit restype on C functions, because the default return type truncates to 32 bits.