LearnThatStack Ace your next interview
MySQL · question
Question 4 of 42

What is the difference between CHAR and VARCHAR?

beginner
← All MySQL questions
Re-explain

CHAR(n) is a fixed-length string and VARCHAR(n) is a variable-length string. In both, n counts characters, not bytes.

  • CHAR pads values with spaces to the full length when stored, and MySQL strips trailing spaces on read. The length can be 0 to 255. It is a little faster for fixed-size values such as country codes, but wastes space on shorter ones.
  • VARCHAR stores only the characters used, plus a length prefix, so it is more storage efficient.

You can declare a VARCHAR length up to 65,535, but the real limit is lower. All columns share a 65,535-byte row size limit, and the character set decides how many bytes each character takes. The prefix is 1 byte when values need at most 255 bytes, and 2 bytes otherwise. With the default utf8mb4, a character can take up to 4 bytes, so a VARCHAR(255) value can need 1,020 bytes and a 2-byte prefix.

-- CHAR(10) always holds 10 characters, padded with spaces
name CHAR(10)

-- VARCHAR(255) stores only the characters used, plus a length prefix
name VARCHAR(255)
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the MySQL cheatsheet.

← Back to all MySQL questions
Pro · $10/mo

37 of 42 MySQL answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime