Databases 2 min read

When to Use CHAR vs VARCHAR in MySQL? Understanding Length, Storage, and Performance

CHAR stores fixed‑length strings padded with spaces, while VARCHAR stores variable‑length strings with a length byte, leading to different maximum sizes—255 characters for CHAR and up to 65,535 bytes for VARCHAR (about 21,589 UTF‑8 characters)—and distinct use cases such as short fixed fields versus space‑saving flexible fields.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
When to Use CHAR vs VARCHAR in MySQL? Understanding Length, Storage, and Performance

Basic Differences

CHAR is fixed‑length; MySQL pads the value on the right with spaces to reach the defined length.

VARCHAR is variable‑length; each value occupies only the bytes needed plus a length byte (one byte if length < 255, otherwise two bytes).

Maximum Lengths

CHAR can be defined up to 255 characters (not bytes).

VARCHAR can be defined up to 65,535 bytes (not characters). With utf8 encoding (3 bytes per character), the practical maximum is about 21,589 characters.

Applicable Scenarios

Use CHAR for short, relatively fixed‑length fields such as postal codes, UUIDs, or columns that change frequently, because it avoids the overhead of length calculation.

Use VARCHAR when you want to save space for variable‑length data.

MySQLdatabase designvarcharStoragechar
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.