Course contentsShow
← Computer Science
Lesson 140 of 2,8724. Introduction to ProgrammingFree lesson

Integer Data Types

Exploring whole number types: their range, memory size, and when to use them.

Integer Data Types

You'll learn what integer data types are, how much memory they use, and when to choose each one in your programs.

What Are Integer Data Types?

In programming, an integer data type stores whole numbers without decimal points—numbers like -5, 0, 42, or 1000. Unlike mathematical integers (which can be infinitely large), computer integers have limited ranges because they occupy a fixed amount of memory.

Think of integer types like different-sized boxes: a small box holds fewer items but takes up less space, while a large box holds more but uses more storage.

Common Integer Types and Their Ranges

Different programming languages offer various integer types, typically including:

  • byte or int8: Uses 8 bits (1 byte) of memory, stores values from -128 to 127
  • short or int16: Uses 16 bits (2 bytes), stores approximately -32,000 to 32,000
  • int or int32: Uses 32 bits (4 bytes), stores approximately -2 billion to 2 billion
  • long or int64: Uses 64 bits (8 bytes), stores approximately -9 quintillion to 9 quintillion

Some languages also provide unsigned versions (only non-negative numbers), which double the positive range.

When to Use Each Type

Choose your integer type based on:

  1. Value range needed: Use byte for small counters (0–100), but long for timestamps or large calculations
  2. Memory efficiency: In arrays storing millions of numbers, using short instead of long saves significant space
  3. Performance: Some processors handle certain sizes faster

Key Takeaway: Integer types are whole-number containers with different memory sizes and value ranges—pick the smallest type that safely fits your expected values to balance range with memory efficiency.