sizeof

Is int 2 or 4 Bytes in C?

The size of int in C depends on the platform. The standard sets a 16-bit minimum, and most current systems use 4 bytes. Here's how to check yours.

On this page
  1. Short answer
  2. What the C standard guarantees
  3. Where you will see 2 bytes and 4 bytes
  4. Check your own system
  5. When the size matters
  6. In short

Short answer

It depends on the platform. The C standard does not fix the size of int. It requires int to hold at least the range from -32767 to 32767, which needs at least 16 bits. With 8-bit bytes, that makes 2 bytes the smallest possible size. On most current desktop and server systems, int is 4 bytes.

What the C standard guarantees

The standard sets minimum ranges for the integer types, not exact sizes:

  • int must hold at least -32767 to 32767, which means at least 16 bits. With 8-bit bytes, that is at least 2 bytes.
  • long must be at least 32 bits.
  • long long must be at least 64 bits.

Each compiler may choose any size that meets these minimums. That is why int can differ from one system to another, even for the same source code.

Where you will see 2 bytes and 4 bytes

  • 4 bytes is the usual size on mainstream 32-bit and 64-bit desktop, laptop and server systems, with GCC, Clang and MSVC.
  • 2 bytes shows up on some small embedded targets, such as many 8-bit and 16-bit microcontrollers.

Because the size varies, don’t assume one value in your code. Check the size on the system you actually build for.

Check your own system

This short program prints the values that matter. It uses CHAR_BIT and INT_MAX from <limits.h>:

#include <stdio.h>
#include <limits.h>

int main(void) {
    printf("sizeof(int): %zu bytes\n", sizeof(int));
    printf("CHAR_BIT: %d\n", CHAR_BIT);
    printf("INT_MAX: %d\n", INT_MAX);
    return 0;
}

On a typical 64-bit desktop, sizeof(int) prints 4 and CHAR_BIT prints 8. Your numbers may differ.

When the size matters

Code that needs an exact width should use fixed-width types, such as int32_t from <stdint.h> in C or <cstdint> in C++. Those types exist only on platforms with a matching integer type, which covers mainstream systems.

The primitive data types in C each have a minimum size, but the exact sizes can vary. Fixed-width types are the safe choice when the exact number of bits matters, such as in a file format or a network protocol.

In short

The size of int is not fixed by the standard. It is at least 2 bytes, and it is usually 4 bytes on current desktop and server systems. Check sizeof(int) on your target, and use fixed-width types when the exact width matters.

The complete guide to sizeof

The sizeof Operator in C++
Read the guide

Keep exploring

Guides from other topics

All topics →

Enums in C++ With Examples

Learn enums in C++ with clear examples: syntax, automatic values, enum class, switch statements, underlying types, and common mistakes to avoid.

Enums 5 min read