CHAR and VARCHAR are both ASCII character data types and almost same but they are different at the stage of storing and retrieving the data from the database.

1. CHAR Datatype:
It is a datatype in SQL which is used to store character string of fixed length specified. If the length of string is less than set or fixed length then it is padded with extra blank spaces so that its length became equal to the set length. Storage size of CHAR datatype is of n bytes(set length). We should use this datatype when we expect the data values in a column are of same length.

2. VARCHAR Datatype:
It is a datatype in SQL which is used to store character string of variable length but maximum of set length specified. If the length of string is less than set or fixed length then it will store as it is without padded with extra blank spaces. Storage size of VARCHAR datatype is equal to the actual length of the entered string in bytes. We should use this datatype when we expect the data values in a column are of variable length.

Difference between CHAR and VARCHAR dataypes

CHAR Data Type
VARCHAR Data Type
Its full name is CHARACTER
Its full name is VARIABLE CHARACTER
It stores values in fixed lengths and are padded with space characters to match the specified length
VARCHAR stores values in variable length along with 1-byte or 2-byte length prefix and are not padded with any characters
It can hold a maximum of 255 characters.
It can hold a maximum of 65,535 characters.
It uses static memory allocation.It uses dynamic memory allocation.
SR.NO.CHARVARCHAR
1.CHAR datatype is used to store character string of fixed lengthVARCHAR datatype is used to store character string of variable length
2.In CHAR, If the length of string is less than set or fixed length then it is padded with extra memory space.In VARCHAR, If the length of string is less than set or fixed length then it will store as it is without padded with extra memory spaces.
3.CHAR stands for “Character”VARCHAR stands for “Variable Character”
4.Storage size of CHAR datatypes is equal to n bytes i.e. set lengthStorage size of VARCHAR datatype is equal to the actual length of the entered string in bytes.
5.We should use CHAR datatype when we expect the data values in a column are of same length.We should use VARCHAR datatype when we expect the data values in a column are of variable length.
6.CHAR take 1 byte for each characterVARCHAR take 1 byte for each character and some extra bytes for holding length information
9.Better performance than VARCHARPerformance is not good as compared to CHAR