What is the difference between tinyint, smallint, mediumint, bigint and int in MySQL?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
In MySQL, choosing the appropriate integer data type is crucial for database optimization, storage efficiency, and ensuring that the values fit the intended range. MySQL provides several integer data types that serve different storage needs:
- TINYINT
- SMALLINT
- MEDIUMINT
- INT
- BIGINT
Each of these data types differs in terms of storage requirements and range of values they can store. Let's explore them in detail.
Data Types Overview
TINYINT
- Storage Size: 1 byte
- Unsigned Range: 0 to 255
- Signed Range: -128 to 127
TINYINT is the smallest integer type and is often used when you need to store very small numbers. This is useful for things like storing boolean values (0 and 1) or small categorical data.
Example of usage:
SMALLINT
- Storage Size: 2 bytes
- Unsigned Range: 0 to 65,535
- Signed Range: -32,768 to 32,767
SMALLINT is suitable for slightly larger numbers than those handled by TINYINT, such as ages, counts, and other small numerical data.
Example of usage:
MEDIUMINT
- Storage Size: 3 bytes
- Unsigned Range: 0 to 16,777,215
- Signed Range: -8,388,608 to 8,388,607
MEDIUMINT offers a larger range than SMALLINT and is less commonly used, but can be handy for storing medium-sized numbers, like a moderate database ID system.
Example of usage:
INT
- Storage Size: 4 bytes
- Unsigned Range: 0 to 4,294,967,295
- Signed Range: -2,147,483,648 to 2,147,483,647
INT is one of the most commonly used integer types and handles most standard numerical data. This suits typical use cases like user IDs, prices, or any moderate numerical data.
Example of usage:
BIGINT
- Storage Size: 8 bytes
- Unsigned Range: 0 to 18,446,744,073,709,551,615
- Signed Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
BIGINT is used for very large numbers that exceed the capacity of INT. It's appropriate for cases like large financial transactions, astronomical computations, or storing timestamps well into the future.
Example of usage:
Key Differences and Summary Table
The primary differences between these data types lie in their storage size and range of values:
| Data Type | Storage Size | Signed Range | Unsigned Range |
| TINYINT | 1 byte | -128 to 127 | 0 to 255 |
| SMALLINT | 2 bytes | -32,768 to 32,767 | 0 to 65,535 |
| MEDIUMINT | 3 bytes | -8,388,608 to 8,388,607 | 0 to 16,777,215 |
| INT | 4 bytes | -2,147,483,648 to 2,147,483,647 | 0 to 4,294,967,295 |
| BIGINT | 8 bytes | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 0 to 18,446,744,073,709,551,615 |
Additional Considerations
Choosing the Right Type
Choosing the correct integer type can significantly affect the size and performance of the database. Smaller integer types save space but limit the range of data, whereas larger integer types consume more storage.
Signed vs. Unsigned
Unsigned types can only store non-negative numbers, effectively doubling the maximum positive range compared to their signed counterparts. Use unsigned integers when you know the values will be non-negative, like IDs or countable quantities.
Storage Efficiency
Optimizing the storage size can lead to significant improvements, particularly in large tables. The choice affects how the data is stored, indexed, and retrieved.
Practical Scenarios
- Use
TINYINTfor small flags, boolean fields, or very small numbers. - Use
SMALLINTfor small-scale numerical data like small counts or ranges. - Use
MEDIUMINTwhen you anticipate larger numbers thanSMALLINT, but want to conserve space. - Use
INTfor the majority of cases as it's a balanced choice for many applications. - Use
BIGINTfor extremely large values, such as timestamps or financial transactions.
Selecting the right integer type not only saves storage space and reduces memory overhead but also impacts query performance and ensures data integrity through appropriate constraints.
Related reading
- what is the difference between transaction id and sequence id of a distributedlog record?
- What is the difference between Unidirectional and Bidirectional JPA and Hibernate associations?
- What is the difference between UNION and UNION ALL?
- What is the difference between utf8mb4 and utf8 charsets in MySQL?
- what is the disadvantages of database sequencing with machine name + table alias + sequence?
- What is the easiest way to ignore a JPA field during persistence?
- what is the effect of distributed_group_by_no_merge
- What is the error Every derived table must have its own alias in MySQL?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.