Here is a formula to calculate the value range for primitive data types - byte to long.

Value Range = (-2^n-1) to (2^n-1)-1 where n is the size in bits.

So this is how it works.

Variable Type Size(in bits) Value byte 8 (-2^7) - 2^7-1 (-128 to 127) short 16 (-2^15) - 2^15-1(-32768 to 32767) int 32 (-2^31) - 2^31-1 long 64 (-2^63) - 2^63-1