Formula to Calculate the Range of an Integer Data Types in SQL Server

In this blog, I described how to calculate the maximum range of integer data types in SQL Server. The int data type is the primary integer data type in SQL Server. Int represents an integer value that can be stored in 4 bytes. INT is the short form of integer.

Formula   

2^(n-1) is the formula to find the maximum of an INT data type.

In the preceding formula N (Size in bits) is the size of data type. The ^ operator calculates the power of the value.

Now determine the value of N in Bit:

Select (max_length * 8) as 'Bit(s)' from sys.types Where name = 'Int'

Output

32 bits

Determine the maximum range of int

The formula is:

2^(n-1) here N=32

Select Power(cast(2 as varchar),(32) -1) as 'int max range'  from sys.types Where name = 'Int'

 

The range of an int data type is -2,147,483,648 to 2,147,483,647.