EMZETT.
Login

short

In short: An integer data type with a smaller value range than the standard integer type (usually 16 bits) — a middle ground between the very small byte and a full integer.

In more detail: In practice, short is used significantly less often than byte or a normal integer, because most systems calculate internally with larger word sizes anyway, and the memory advantage over a normal integer is often negligible. It matters especially for very memory-sensitive applications with huge amounts of data, such as in arrays with millions of elements.

In Depth

The integer data types form a size hierarchy, usually with double the bit width per step:

byte:  8 bits  -> -128 to 127
short: 16 bits -> -32,768 to 32,767
int:   32 bits -> about -2.1 to +2.1 billion
long:  64 bits -> about -9.2 to +9.2 quintillion

short thus covers a value range that’s enough for many real-world numbers (an age, a quantity in the three- to low-five-digit range), but is no longer enough for somewhat larger numbers (e.g. the population of medium-sized cities). In practice, most developers simply reach for the normal integer type anyway, even when short’s value range would technically be enough — the small memory difference is almost never worth the extra care short requires (e.g. explicit type conversions for arithmetic operations, because many languages automatically widen intermediate results to int).

Today, short is found mainly in two niches: for interoperability with older data formats/protocols that historically fixedly prescribe the type (e.g. some binary file formats or network protocols), and for extremely memory-critical applications with huge amounts of data (e.g. image processing, scientific simulations with millions of data points), where the difference between 2 and 4 bytes per value actually becomes noticeable at the appropriate scale.

See also: byte, long