What is the difference between CHAR and VARCHAR?

Why Interviewers Ask This

Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for MySQL / SQL development. It reveals whether you understand the building blocks that more complex concepts rely on.

Answer

CHAR(n) is a fixed-length character data type. It always uses exactly n bytes of storage, padding with spaces if the stored value is shorter. Maximum length: 255 characters. VARCHAR(n) is a variable-length character data type. It uses only as much space as needed plus 1-2 bytes for the length prefix (1 byte if ≤255 chars, 2 bytes if ≤65535). Maximum length: 65,535 bytes. When to use each: CHAR — best for fixed-width strings where all values are the same length: country codes (CHAR(2)), phone numbers with consistent formatting (CHAR(10)), MD5 hashes (CHAR(32)), UUIDs (CHAR(36)). CHAR can be slightly faster for retrieval because row offsets are predictable. VARCHAR — best for strings that vary widely in length: names, addresses, email addresses, descriptions. VARCHAR saves storage when values vary. Key point: trailing spaces are removed from VARCHAR on storage and comparison; CHAR pads and compares with trailing spaces. In modern MySQL with row-format compression, the performance difference is minimal.

Pro Tip

Back up your answer with a specific project or situation. Saying 'In my last MySQL / SQL project, I used this when...' immediately makes your answer more credible and memorable.