The short data type is a 16-bit signed integer type in Java. It is designed to store whole numbers that are larger than the range of byte but smaller than the range of int.
In everyday Java applications, int is usually preferred for normal integer calculations. However, understanding short is important because it helps you understand numeric ranges, memory representation, type promotion, casting, and Java's primitive type system.
What Is the short Data Type?
The short data type stores signed whole numbers using 16 bits. Its range is from -32,768 to 32,767.
short age = 25; short temperature = -100; short marks = 25000;
A short is useful when the expected values are known to remain within its range and compact numeric storage is desirable.
Key Point: Java's short is a signed 16-bit integer with a range of -32,768 to 32,767.
Why Does Java Have short?
Different applications have different data requirements. A value such as a small measurement, compact numeric record, or protocol field may not need the full range of an int.
Using a smaller type can be useful when large amounts of data must be stored compactly. However, choosing short simply because it uses fewer bits is not automatically better. Java arithmetic promotes short values to int, so ordinary calculations often work more naturally with int.
Syntax of short
short variableName = value;
For example:
short temperature = 30; short score = 950; short year = 2026;
Range of short
A short uses 16 bits and is signed. Its range can be represented mathematically as -215 to 215 - 1.
| Property | Value |
|---|---|
| Data Type | short |
| Category | Integer |
| Size | 16 bits |
| Minimum Value | -32,768 |
| Maximum Value | 32,767 |
| Default Value for a Field | 0 |
| Signed | Yes |
Valid short Values
Any whole number between -32,768 and 32,767 can be stored in a short variable.
short minimum = -32768; short zero = 0; short maximum = 32767;
These assignments are valid because all three values fall within the supported range.
Invalid short Values
A value outside the short range cannot be assigned directly to a short variable.
short number = 40000;
The compiler rejects this because 40000 is greater than the maximum value supported by short.
Beginner Tip: Before choosing short, make sure the complete expected range of your data fits between -32,768 and 32,767.
short and Integer Literals
Integer literals such as 1000 are normally treated as int. Java can nevertheless assign a compile-time constant integer literal to a short when the value fits within the short range.
short number = 1000;
This works because the compiler can determine that 1000 is within the valid short range.
But a variable of type int cannot be assigned automatically to short.
int value = 1000; short number = value;
The conversion must be made explicit:
int value = 1000; short number = (short) value;
short Type Conversion
A short can be automatically converted to larger numeric types such as int, long, float, or double when the conversion is supported by Java's numeric promotion rules.
short value = 500; int number = value; long largeNumber = value; float decimalNumber = value; double preciseNumber = value;
No explicit cast is required because these destination types can represent the complete range of short.
short and Arithmetic Operations
One of the most important rules to remember is that arithmetic involving short values is generally performed using int.
short a = 100; short b = 200; int result = a + b;
The expression a + b produces an int result. Therefore, this code does not compile:
short a = 100; short b = 200; short result = a + b;
To explicitly store the result as a short, a cast is required.
short a = 100; short b = 200; short result = (short) (a + b);
Remember: Like byte, a short is generally promoted to int during arithmetic operations.
short Overflow
A short can represent values only up to 32,767. When a calculation produces a value beyond that range and the result is converted back to short, the value can wrap around.
short number = 32767; number++; System.out.println(number);
The result becomes -32768. This happens because the value has moved beyond the maximum representable short value.
Overflow is especially important when working with counters, calculations, binary formats, or external data whose limits are not fully controlled.
short vs byte
| Feature | byte | short |
|---|---|---|
| Size | 8 bits | 16 bits |
| Minimum | -128 | -32,768 |
| Maximum | 127 | 32,767 |
| Category | Integer | Integer |
| Arithmetic Promotion | int | int |
When Should You Use short?
Use short when the data has a known range that fits within its limits and a compact representation is useful. It can be appropriate for specialized data structures, binary formats, and APIs that explicitly operate with 16-bit values.
For ordinary variables such as age, quantity, score, or loop counters, int is generally the better choice because Java's integer operations naturally work with int.
Common Beginner Mistakes
- Assuming short can store any number smaller than a long.
- Forgetting that the maximum short value is 32,767.
- Expecting short + short to produce a short.
- Assigning an int variable to a short without casting.
- Using short everywhere just because it uses less storage than int.
- Ignoring overflow when calculations can exceed the supported range.
Best Practices
- Use short when the value range is genuinely limited and compact storage matters.
- Prefer int for ordinary integer calculations and counters.
- Use explicit casting when intentionally converting a larger integer type to short.
- Check possible overflow when values approach the boundaries of the short range.
Interview Insights
Question: What is the size and range of short in Java?
Answer: short is a signed 16-bit integer type with a range from -32,768 to 32,767.
Question: Why does short + short produce int?
Answer: Java applies binary numeric promotion during arithmetic, causing short operands to be promoted to int.
Question: Is short signed in Java?
Answer: Yes. Java's short is a signed 16-bit integer type.
short Data Type: Quick Revision
| Property | Details |
|---|---|
| Type | short |
| Category | Integer |
| Size | 16 bits |
| Minimum | -32,768 |
| Maximum | 32,767 |
| Default Field Value | 0 |
| Signed | Yes |
| Arithmetic Result | Usually promoted to int |
| Example | short marks = 25000; |
The short data type occupies a useful middle position between byte and int. While it is not a common choice for everyday calculations, it becomes valuable when a program needs a signed 16-bit value or works with data formats where the size of the numeric representation matters.
