Free tutorials in Hindi & English Daily computer, mobile and IT guides Beginner friendly learning
Blog · MySQL / SQL · 04 Jul 2026 · Hindi + English

Difference Between CHAR and VARCHAR in MySQL

CHAR reserves fixed space and pads with spaces; VARCHAR uses only what the value needs plus a length byte. Storage proof table and when each one wins.

The fixed box vs stretch bag analogy

CHAR(10) is a fixed box of exactly 10 slots — put "Aman" (4 letters) inside and MySQL fills the remaining 6 slots with spaces; the box always takes 10 characters of space, always. VARCHAR(10) is a stretch bag with a limit of 10 — "Aman" takes just 4 characters plus 1 small byte that records the length. Short value = small bag; the limit only says how far the bag can stretch.
CHAR(10)    storing 'Aman'  ->  'Aman      '   (padded, 10 chars always)
VARCHAR(10) storing 'Aman'  ->  'Aman' + 1 length byte  (5 bytes total)

Storage proof

CREATE TABLE demo (
    a CHAR(10),
    b VARCHAR(10)
);
INSERT INTO demo VALUES ('Aman', 'Aman');

SELECT LENGTH(a), LENGTH(b) FROM demo;
+-----------+-----------+ | LENGTH(a) | LENGTH(b) | | 10 | 4 | <- CHAR padded to 10, VARCHAR stayed 4 +-----------+-----------+

(Note: MySQL strips the trailing spaces of CHAR when reading, so SELECT a shows 'Aman' — but the storage is still 10. LENGTH exposes the truth.)

Value storedCHAR(10) usesVARCHAR(10) uses
'A'10 chars1 + 1 = 2 bytes
'Aman'10 chars4 + 1 = 5 bytes
'AmanKumar!'10 chars10 + 1 = 11 bytes

Interesting: for values that always fill the full width, CHAR is actually smaller (no length byte) and slightly faster (fixed positions, no length reading). That is exactly when CHAR wins.

Comparison table

PointCHAR(n)VARCHAR(n)
StorageFixed n, space-paddedActual length + 1-2 length bytes
Max n25565,535 (row-size limits apply)
Best forValues of one fixed lengthValues of varying length
SpeedSlightly faster (fixed offsets)Normal
Wasted space on short valuesYes (padding)No

Real column decisions (school database)

CREATE TABLE students (
    roll_no    INT PRIMARY KEY,
    name       VARCHAR(50),     -- names vary: 'Om' to 'Ramakrishnan'
    gender     CHAR(1),         -- always exactly 1: 'M'/'F'/'O'
    pincode    CHAR(6),         -- Indian PIN: always exactly 6
    mobile     CHAR(10),        -- always exactly 10 digits
    address    VARCHAR(200),    -- wildly varying length
    aadhar     CHAR(12)         -- always exactly 12
);

The pattern is obvious once seen: always-same-length codes → CHAR; naturally-varying text → VARCHAR. A VARCHAR(1) for gender would waste a length byte on every row for nothing; a CHAR(200) for address would pad thousands of spaces.

Interview trap: "What happens to trailing spaces?" CHAR strips them on retrieval; VARCHAR keeps them as typed. So 'ab ' saved in CHAR comes back as 'ab', in VARCHAR as 'ab ' — a subtle difference that has broken many login comparisons in real applications.

Fixed डिब्बा vs stretch थैली analogy

CHAR(10) exactly 10 खानों का fixed डिब्बा है — "Aman" (4 letters) रखो तो बचे 6 खाने MySQL spaces से भर देता है; डिब्बा हमेशा 10 characters की जगह लेता है, हमेशा. VARCHAR(10) 10 की limit वाली stretch थैली है — "Aman" सिर्फ 4 characters + 1 छोटा byte लेता है जो length लिखता है. छोटी value = छोटी थैली; limit बस यह बताती है थैली कितनी खिंच सकती है.
CHAR(10)    में 'Aman'  ->  'Aman      '   (padded, हमेशा 10 chars)
VARCHAR(10) में 'Aman'  ->  'Aman' + 1 length byte  (कुल 5 bytes)

Storage proof

CREATE TABLE demo (
    a CHAR(10),
    b VARCHAR(10)
);
INSERT INTO demo VALUES ('Aman', 'Aman');

SELECT LENGTH(a), LENGTH(b) FROM demo;
+-----------+-----------+ | LENGTH(a) | LENGTH(b) | | 10 | 4 | <- CHAR 10 तक padded, VARCHAR 4 ही रहा +-----------+-----------+

(Note: MySQL पढ़ते समय CHAR के trailing spaces हटा देता है, तो SELECT a 'Aman' दिखाता है — पर storage फिर भी 10 है. LENGTH सच दिखाता है.)

Stored valueCHAR(10) लेता हैVARCHAR(10) लेता है
'A'10 chars1 + 1 = 2 bytes
'Aman'10 chars4 + 1 = 5 bytes
'AmanKumar!'10 chars10 + 1 = 11 bytes

Interesting: जो values हमेशा पूरी width भरती हैं, उनके लिए CHAR असल में छोटा है (length byte नहीं) और थोड़ा तेज़ (fixed positions). वहीं CHAR जीतता है.

Comparison table

PointCHAR(n)VARCHAR(n)
StorageFixed n, spaces से paddedअसली length + 1-2 length bytes
Max n25565,535 (row-size limits लागू)
Best forएक fixed length वाली valuesबदलती length वाली values
Speedथोड़ा तेज़ (fixed offsets)Normal
छोटी values पर wasteहां (padding)नहीं

असली column decisions (school database)

CREATE TABLE students (
    roll_no    INT PRIMARY KEY,
    name       VARCHAR(50),     -- names बदलते हैं: 'Om' से 'Ramakrishnan'
    gender     CHAR(1),         -- हमेशा exactly 1: 'M'/'F'/'O'
    pincode    CHAR(6),         -- Indian PIN: हमेशा exactly 6
    mobile     CHAR(10),        -- हमेशा exactly 10 digits
    address    VARCHAR(200),    -- बेतहाशा बदलती length
    aadhar     CHAR(12)         -- हमेशा exactly 12
);

Pattern एक बार दिखा तो साफ है: हमेशा-same-length codes → CHAR; naturally बदलता text → VARCHAR. Gender के लिए VARCHAR(1) हर row पर बेकार का length byte खर्च करता; address के लिए CHAR(200) हज़ारों spaces pad करता.

Interview trap: "Trailing spaces का क्या होता है?" CHAR retrieval पर उन्हें हटा देता है; VARCHAR जैसा type किया वैसा रखता है. तो CHAR में save हुआ 'ab ' वापस 'ab' आता है, VARCHAR में 'ab ' — यह बारीक फर्क असली applications के कई login comparisons तोड़ चुका है.

Frequently Asked Questions

What is the difference between CHAR and VARCHAR?

CHAR(n) always occupies exactly n characters, padding short values with spaces; VARCHAR(n) stores only the actual length plus 1-2 length bytes, with n as just the upper limit.

When should CHAR be used instead of VARCHAR?

For values that are always exactly the same length — gender CHAR(1), PIN code CHAR(6), mobile CHAR(10), Aadhaar CHAR(12) — where CHAR is both smaller and slightly faster.

What happens to trailing spaces in CHAR and VARCHAR?

CHAR strips trailing spaces when values are retrieved, while VARCHAR preserves them exactly as entered — a subtle difference that can break string comparisons.