The column type for a password in MySQL is VARCHAR(255). You store the encoded output of a slow password hash (bcrypt, argon2id, or scrypt), never the password and never a fast MD5 or SHA-256. A bcrypt hash is always 60 characters and an Argon2id hash runs about 95 to 100, and VARCHAR(255) holds both. This page covers the column, the bcrypt and Argon2id specifics, and the lookup-then-verify flow.
Short answer: use password_hash VARCHAR(255) NOT NULL (store it as ascii or latin1, since the encoded hash is pure ASCII), compute the hash in your application with a real password library, never with MySQL's MD5() or SHA2(), and never write WHERE password = .... You look up the user row by their email or username, pull the stored hash out, and verify the candidate password against it in app code. This is the opposite of the integrity-hash story in storing a SHA-256 hash in MySQL: SHA-256 is for fingerprinting, not credentials.
Why VARCHAR(255) and not something shorter
The instinct is to size the column to exactly fit the hash you use today. bcrypt output is exactly 60 characters, so CHAR(60) looks tidy. The problem is that you are not really storing a bcrypt hash. You are storing whatever your password library hands back, and that format changes the day you raise the cost factor, switch algorithms, or move to a new library version.
The encoded string is self-describing. A bcrypt hash looks like $2y$12$R9h/cIPz0gi.URNNX3kh2OPST9/PgBkqquzi.Ss7KIUgO2t0jWMUW: the $2y$ is the algorithm identifier, 12 is the cost, and the rest is the salt and digest packed together. argon2id looks like $argon2id$v=19$m=65536,t=4,p=1$...$..., encoding the memory, time, and parallelism parameters inline. Because the parameters travel with the hash, you can verify an old password against an old hash even after you have moved everyone new onto stronger settings. That is the whole point, and it only works if the column is wide enough to hold the longest format you might ever migrate to.
Here are the encoded lengths in practice:
| Algorithm | Typical encoded length | Notes |
|---|---|---|
bcrypt ($2y$) | 60 chars (fixed) | Length never varies, even as cost rises |
| argon2i / argon2id | ~95–100 chars | Grows with larger m/t/p parameters, salt or digest length |
scrypt (libsodium $7$) | ~101 chars (fixed buffer) | libsodium's crypto_pwhash_scryptsalsa208sha256_STRBYTES is 102 bytes incl. terminator |
PHP PASSWORD_DEFAULT | 60 today (bcrypt) | Could change in a future PHP release |
VARCHAR(255) covers all of these with comfortable headroom, and 255 is not an arbitrary number: it is the largest length a VARCHAR can have while still using a single-byte length prefix (up to 255 bytes), so you pay one byte of overhead plus the actual hash bytes and nothing more. VARCHAR is variable-length, so a 60-character bcrypt hash still only occupies 61 bytes on disk in this column. You get the migration headroom for free.
This is also the recommendation you will find everywhere that has thought about it. PHP's manual tells you to use VARCHAR(255) for the result of password_hash(). Laravel's default users migration ships a password column as string, which maps to VARCHAR(255), and a Rails string column lands in the same place. Django stores its password field as a 128-character field but the principle is the same: width that outlives the current algorithm. WordPress is a concrete case study in why: it kept its user_pass column at VARCHAR(255), and that one decision let it switch its hashing from phpass to bcrypt decades later with no schema change. MariaDB is identical to MySQL here in every respect: same types, same sizes, same advice.
What NOT to use
A few column types look reasonable and are wrong for specific reasons.
CHAR(60) sizes the column to bcrypt exactly. It works, today, for bcrypt only. The moment you decide argon2id is the better default (it is, for new systems), every new hash is ~96 characters and no longer fits. Now you need an ALTER TABLE ... MODIFY on your users table, which on a large table is a locking, blocking, multi-minute operation you have to schedule. CHAR also pads to the full width, so even if every value were 60 chars you save nothing over VARCHAR in practice, and you lose the headroom.

VARCHAR(60) has the same fatal flaw as CHAR(60): it is sized to one algorithm. The variable-length saving over CHAR(60) is real but irrelevant, because the column is too narrow to hold the next algorithm you will want. Don't tie your schema to bcrypt's exact output length.
TEXT is over-correction in the other direction. The encoded hash is at most ~100-odd bytes, so a TEXT column (built for kilobyte-to-gigabyte blobs) is pure waste, and it has real downsides: TEXT columns cannot have a useful DEFAULT, InnoDB may store long TEXT values off-page in overflow pages, and you cannot index a TEXT column without a prefix length. None of that helps a fixed, short, ASCII credential. VARCHAR(255) is the right shape.
A raw MD5() or SHA2() column. This is the dangerous one, because it is the most common. MD5 and SHA-256 are fast hashes, which is exactly what you do not want for a password: an attacker who steals your table can try billions of guesses per second against a fast hash on a single GPU. They are also unsalted by default, so identical passwords produce identical hashes and a precomputed rainbow table cracks them instantly. Storing SHA2(password, 256) is only marginally better than storing MD5, which is to say not good enough. If you have an existing table doing this, read why MD5 is the wrong choice for passwords and plan a reset-on-next-login migration. SHA-256 has its place, but that place is integrity and fingerprinting, never credentials.
A complete users-table schema
Here is a users table done correctly. The password column is VARCHAR(255); the lookup key is a UNIQUE email; the password column is never part of any index or WHERE clause used to find a user.
CREATE TABLE users (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL,
password_hash VARCHAR(255) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY uq_users_email (email)
) ENGINE=InnoDB;The CHARACTER SET ascii on password_hash matters: every byte a password library emits is a printable ASCII character ($, ., /, [A-Za-z0-9]), so an ascii or latin1 column stores it in one byte each. If your table default is utf8mb4, leaving this column on utf8mb4 reserves up to 4 bytes per character in any index calculation (255 × 4 = 1020 bytes, enough to blow the InnoDB key-length limit when combined with other columns), for zero benefit. You typically do not index password_hash at all, but pinning it to ascii keeps the column honest and avoids surprises. The ascii_bin collation also makes the stored hash compare byte-for-byte, which is correct, though you should never be comparing it in SQL anyway.
The lookup-then-verify flow is the part people get backwards. You do not ask the database "is there a row where the password matches?" That would require sending the candidate password to the database and comparing it server-side, which is impossible once the stored value is a salted hash (the salt differs per row, and a fresh hash of the same password produces a different string every time, so equality never holds). Instead:
-- 1. Find the user by their identifier, pull the stored hash.
SELECT id, password_hash FROM users WHERE email = ?;
-- 2. Verify the candidate password against that hash IN YOUR APPLICATION.
-- There is no step where the password appears in a WHERE clause.If the SELECT returns no row, authentication fails (and you should still run a dummy verify to keep response timing constant, so you do not leak which emails exist). If it returns a row, you hand the candidate password and the stored hash to your password library and let it tell you yes or no.
Hashing in your application
The hash is always computed in the application layer, never in MySQL. MySQL and MariaDB have no bcrypt or Argon2 function, and even if they did you would not want the plaintext password traveling into a query, sitting in the query log, or being hashed by the database. Every mainstream language ships a battle-tested library.
PHP has this built in. PASSWORD_DEFAULT is bcrypt today; PASSWORD_ARGON2ID is available since PHP 7.3 if your build includes libargon2:
// On registration / password change:
$hash = password_hash($plaintext, PASSWORD_DEFAULT); // 60-char bcrypt string
// or, for argon2id:
$hash = password_hash($plaintext, PASSWORD_ARGON2ID); // ~96-char string
// Store $hash in users.password_hash (VARCHAR(255)).
// On login, after SELECTing the row by email:
if (password_verify($plaintext, $row['password_hash'])) {
// authenticated
if (password_needs_rehash($row['password_hash'], PASSWORD_DEFAULT)) {
// re-hash with current params and UPDATE the row
}
}In every library the hash function generates a fresh random salt per call, folds it and the cost parameters into the returned string, and the verify function pulls them back out to re-derive and compare in constant time. You store one string, you verify against one string, and the column never participates in the lookup. There is no separate salt column. The Python and Node versions for each algorithm are in the two sections below.
Store a bcrypt hash in MySQL
A bcrypt hash is a single fixed-length string in the modular crypt format. It is always 60 ASCII characters, broken down like this:
$2y$12$R9h/cIPz0gi.URNNX3kh2OPST9/PgBkqquzi.Ss7KIUgO2t0jWMUW
└┬┘ └┬┘ └────────────────────┬─────────────────────────────┘
│ │ │
│ │ └─ 22-char salt + 31-char hash (53 chars)
│ └─ cost factor (work factor, here 12 → 2^12 rounds)
└─ algorithm version prefix
The prefix $2y$ is 4 characters, the two-digit cost plus its trailing $ is 3, and the salt-plus-digest tail is 53. That is 60, every time, regardless of how long the password was or how high the cost goes. The version prefix is one of $2a$, $2b$, or $2y$ (PHP's password_hash() emits $2y$); they differ only in the identifier, all are 4 characters, and they verify interchangeably. For the history behind each prefix, see what the bcrypt prefixes mean.
| Column | Bytes per row | Fits bcrypt's 60 chars | Survives an algorithm change | Verdict |
|---|---|---|---|---|
VARCHAR(255) | up to 61 (60 + 1-byte length prefix) | Yes | Yes (argon2id, scrypt all fit) | Recommended default |
CHAR(60) | exactly 60 | Yes, exactly | No (argon2id hashes are ~95+ chars) | Exact-fit, only if algorithm is frozen |
VARCHAR(60) | up to 61 | Yes | No | No reason to pick this |
CHAR(60) is not wrong for bcrypt. The older canonical advice was CHAR(60) BINARY (or BINARY(60)) because bcrypt's alphabet is case-sensitive and MySQL's default collations (utf8mb4_0900_ai_ci on 8.0, latin1_swedish_ci historically) compare case-insensitively. That only matters if you compare the hash in SQL, which you should not do. I only reach for CHAR(60) when something genuinely fixes the format (a spec, a compliance constraint, an existing column I am matching).
Hash on signup and verify on login. A cost of 10 to 12 is the normal range: 10 is the common library default, 12 is reasonable on modern server hardware. Pick the highest cost your login latency budget tolerates, and remember that a higher cost is slower to crack.
// PASSWORD_BCRYPT pins bcrypt; PASSWORD_DEFAULT is also bcrypt today.
$hash = password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]);
// $hash is a 60-char string like $2y$12$R9h/cIPz0gi... -> store it as-is.
if (password_verify($password, $hashFromDb)) {
// password matches
}import bcrypt
# gensalt(rounds=12) sets the cost factor.
hashed = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt(rounds=12))
# hashed is 60 bytes; decode to store the str, or store the bytes.
if bcrypt.checkpw(password.encode("utf-8"), hash_from_db.encode("utf-8")):
... # matchconst bcrypt = require("bcrypt");
const hash = await bcrypt.hash(password, 12); // second arg is the cost
const ok = await bcrypt.compare(password, hashFromDb); // on login
The 72-byte limit. bcrypt only looks at the first 72 bytes of the password. Anything past byte 72 is silently ignored, so two passwords that share a 72-byte prefix hash to the same value. Normal passwords never reach it, but long passphrases can. The standard fix is to pre-hash with SHA-256 and bcrypt the digest (Django ships this as BCryptSHA256PasswordHasher); the stored value is still a 60-character bcrypt string. Argon2id has no such cap, which is one reason OWASP nudges new projects toward it.
Store an Argon2id hash in MySQL
Argon2 won the Password Hashing Competition in July 2015. Of its three variants (Argon2d, Argon2i, and the hybrid Argon2id), Argon2id is OWASP's first choice because it resists both side-channel attacks and GPU cracking. A real Argon2id hash from PHP's password_hash():
$argon2id$v=19$m=65536,t=4,p=1$c29tZXNhbHR2YWx1ZQ$RdescudvJCsgt3ub+b+dWRWJTmaaJObG| Segment | Example | Meaning |
|---|---|---|
| Algorithm | argon2id | The variant. Also argon2i or argon2d. |
| Version | v=19 | Argon2 version 0x13 (1.3), the current encoding. |
| Parameters | m=65536,t=4,p=1 | Memory in KiB, time (passes), parallelism. |
| Salt | c29tZXNhbHR2YWx1ZQ | Base64, no padding. |
| Hash | RdescudvJCsgt3ub+b+dWRWJTmaaJObG | The derived key, Base64, no padding. |
Unlike bcrypt, the length varies. It moves with the salt length (16 bytes by default, 22 Base64 characters), the digest length (32 bytes by default, 43 characters), and the width of the parameter substring itself (m=65536 is five digits, m=1048576 is seven). This is where people get burned: tutorials cargo-cult bcrypt's CHAR(60) onto Argon2, which does not fit, and a VARCHAR(96) sized to one observed hash silently truncates the moment you raise the memory cost. A truncated hash never verifies, so every affected user is locked out. Use the same VARCHAR(255) CHARACTER SET ascii COLLATE ascii_bin column as the schema above.

PHP added PASSWORD_ARGON2I in 7.2 and PASSWORD_ARGON2ID in 7.3. If you omit the options, PHP uses PASSWORD_ARGON2_DEFAULT_MEMORY_COST, _TIME_COST and _THREADS, which in current PHP are 65536, 4 and 1, the values written out here:
<?php
$hash = password_hash($password, PASSWORD_ARGON2ID, [
'memory_cost' => 65536, // KiB (64 MiB)
'time_cost' => 4, // passes
'threads' => 1, // parallelism
]);
if (password_verify($candidate, $hash)) {
// authenticated
}Python uses argon2-cffi (PasswordHasher defaults to Argon2id), or passlib if you already have it:
from argon2 import PasswordHasher
from argon2.exceptions import VerifyMismatchError
ph = PasswordHasher(memory_cost=65536, time_cost=4, parallelism=1)
encoded = ph.hash(password) # store this string
try:
ph.verify(encoded, candidate)
except VerifyMismatchError:
pass # wrong password
# passlib equivalent:
from passlib.hash import argon2
stored = argon2.hash(plaintext)
ok = argon2.verify(plaintext, stored)Node uses the argon2 package, which also defaults to Argon2id:
const argon2 = require("argon2");
const encoded = await argon2.hash(password, {
type: argon2.argon2id,
memoryCost: 65536,
timeCost: 4,
parallelism: 1,
});
const ok = await argon2.verify(encoded, candidate);Argon2id parameters and rehash on login
Argon2's advantage is that it is memory-hard: the memory cost forces an attacker to commit real RAM per guess. A single consumer GPU runs tens of billions of plain MD5 guesses per second (the hashcat benchmark numbers for a GTX 1080 Ti put MD5 north of 30 GH/s), and an Argon2id hash tuned to 64 MiB per attempt collapses that rate to a crawl. The OWASP Password Storage Cheat Sheet lists equivalent Argon2id minimums, any one of which is acceptable:
m=47104(46 MiB),t=1,p=1m=19456(19 MiB),t=2,p=1m=12288(12 MiB),t=3,p=1m=9216(9 MiB),t=4,p=1m=7168(7 MiB),t=5,p=1
These are floors, not targets; PHP's defaults sit comfortably above them. Raise m and t until one hash takes roughly 0.5 to 1 second on production hardware, then back off if login throughput suffers. Because the parameters live in the stored string, you raise them without a flag day: on a successful login, rehash if the stored hash is weaker than current policy.
<?php
if (password_verify($candidate, $hash)) {
if (password_needs_rehash($hash, PASSWORD_ARGON2ID, $options)) {
$newHash = password_hash($candidate, PASSWORD_ARGON2ID, $options);
// UPDATE users SET password_hash = ? WHERE id = ?
}
}Python and Node expose the same idea via PasswordHasher.check_needs_rehash() and argon2.needsRehash(). The same mechanism migrates a bcrypt table to Argon2id in place: password_verify() detects bcrypt and Argon2id from the prefix, so you verify against whatever produced the stored hash, then rehash under Argon2id and update the row. The column holds a mix of $2y$ and $argon2id$ strings and converges as users log in. WordPress did exactly this at scale, moving to bcrypt in WordPress 6.8 with no schema change.
If your column is already CHAR(60), widen it first: ALTER TABLE users MODIFY password_hash VARCHAR(255) CHARACTER SET ascii COLLATE ascii_bin NOT NULL;. Existing bcrypt rows keep working. CHAR to VARCHAR is a type change that MySQL 8.0 runs with ALGORITHM=COPY (a table rebuild), so on a large table use a maintenance window or an online schema-change tool; changing a column type in MySQL has the details.
bcrypt vs argon2id vs scrypt
All three are deliberately slow, salted password hashes, and all three encode their parameters inline, so all three live happily in VARCHAR(255).
| Algorithm | Hash length (encoded) | Resists | Pick it when |
|---|---|---|---|
| argon2id | ~95–100 chars, variable | GPU and ASIC cracking (memory-hard) | New projects (OWASP's first choice) |
| bcrypt | 60 chars, fixed | GPU cracking (well-understood, everywhere) | Existing systems, broad library support, 72-byte inputs are fine |
| scrypt | ~101 chars (libsodium) | GPU and ASIC cracking (memory-hard) | You already use it, or a platform mandates it |
For a brand-new system, argon2id is the current OWASP recommendation. bcrypt remains completely defensible: battle-tested, available in every language, and its 72-byte limit rarely bites real passwords. Either way the column is the same, so the algorithm stays a code decision, not a schema one.
What to do next
- For every MySQL data type with exact byte sizes and the
VARCHARlength-prefix rules, see MySQL Data Types and Sizes. - For the bcrypt specifics, jump to storing a bcrypt hash; for the memory-hard alternative, see storing an Argon2id hash.
- For why a fast hash is the wrong tool here, see when MD5 is the wrong choice.
- For the integrity-hash counterpart (SHA-256 for checksums and fingerprints, not passwords), see how to store a SHA-256 hash in MySQL.
FAQ
VARCHAR(255). You store the encoded output of a password-hashing function (bcrypt is 60 chars, argon2id is ~96, libsodium scrypt is ~101), and 255 covers all of them with headroom. It is also the largest VARCHAR length that still uses a single-byte length prefix, so the overhead is one byte plus the actual hash.
Because VARCHAR is variable-length, a 60-char bcrypt hash only occupies about 61 bytes even in a VARCHAR(255) column. You get the migration headroom for free.
VARCHAR(255), not CHAR. CHAR(60) sizes the column to bcrypt's exact output, which locks you to bcrypt: switching to argon2id later (a ~96-char hash) needs an ALTER TABLE on your users table. VARCHAR(255) holds every algorithm's format, so an upgrade is just new rows with longer values, no schema change. CHAR(60) is only reasonable when you are certain the algorithm is frozen.
No. SHA2() and MD5() are fast hashes, which is the opposite of what a password needs. A fast hash lets an attacker who steals the table try billions of guesses per second on a GPU, and these functions are unsalted by default so identical passwords collide. There is also no bcrypt or Argon2 function in MySQL or MariaDB. Hash in your application with bcrypt, argon2id, or scrypt instead, and store the result in VARCHAR(255).
No, and you should not. You never search for a user by their password hash, you find them by email or username (which is the column to index, usually UNIQUE), pull the stored hash from that one row, and verify it in your application. A fresh hash of the same password has a different salt, so an equality lookup would never match anyway.
ascii or latin1. The encoded hash from any password library is pure printable ASCII ($, ., /, and alphanumerics), so a single-byte charset stores it perfectly. Avoid utf8mb4 on this column: it reserves up to four bytes per character in index-budget calculations for no benefit. Declare it as VARCHAR(255) CHARACTER SET ascii COLLATE ascii_bin if your table default is utf8mb4.
No. Encryption is reversible by design: anyone with the key can recover the plaintext, so the key becomes a single point of catastrophic failure and you have no business ever recovering a user's password. Passwords get hashed with a slow, salted function (bcrypt, argon2id, scrypt), which is one-way. Encrypt other secrets (API tokens you must replay, OAuth refresh tokens); hash credentials.
No. The cost is a fixed two-digit field inside the string ($2y$04$... versus $2y$31$...), so every bcrypt hash is 60 characters whatever the cost or password length. Argon2id is different: its m, t and p values are written into the string, so raising the memory cost from m=65536 to m=1048576 makes the stored hash longer.
No. The salt is generated per hash and embedded inside the encoded string (the 22 characters after the cost field in bcrypt, the fourth $-delimited segment in Argon2id). The verify function reads it back out of the stored value, so one VARCHAR(255) column holds the entire record.
Argon2id for new systems. It is OWASP's first choice and it is memory-hard, so it resists GPU and ASIC cracking in a way bcrypt does not, and it has no 72-byte input cap. bcrypt is still acceptable and has a fixed 60-character output. Both are stored as application-computed strings in the same VARCHAR(255) column.
No. MariaDB and MySQL are identical here: VARCHAR(255) holding the encoded hash, computed by your application's password library, stored as ascii or latin1, never indexed for lookups. MariaDB has no native bcrypt or Argon2 function either, so the schema and the PHP, Python and Node code run unchanged.
See also
- Storing a bcrypt hash in PostgreSQL covers the same credential column on the other major open-source database.
- How WordPress stores passwords is the real-world case study for why a wide
VARCHARcolumn outlives any single hashing scheme. - The MySQL data types and sizes reference has the exact byte costs and the
VARCHARlength-prefix rules behind the 255 boundary. - If you do need to widen an existing column, changing a column type in MySQL walks through the locking
ALTER TABLEyou are trying to avoid. - Validating password strength with regex is the check that runs before you ever hash.
- Keep the day-to-day syntax handy with the MySQL cheat sheet.
- To test any of this on a throwaway instance, see running MySQL in Docker.
Sources
Authoritative references this article was fact-checked against.
- PHP Manual: password_hash() (recommended storage VARCHAR(255), PASSWORD_DEFAULT, PASSWORD_BCRYPT, PASSWORD_ARGON2ID, cost, 72-byte limit)php.net
- PHP Manual: password_verify()php.net
- Laravel Documentation: Migrations (string password column)laravel.com
- MySQL 8.0 Reference Manual: String Data Types (CHAR, VARCHAR, TEXT)dev.mysql.com
- RFC 9106: Argon2 Memory-Hard Function for Password Hashingdatatracker.ietf.org
- libsodium: crypto_pwhash_scryptsalsa208sha256.h (STRBYTES = 102, the scrypt encoded-hash buffer size)github.com
- bcrypt: modular crypt format, $2a$/$2b$/$2y$ prefixes, 72-byte input limiten.wikipedia.org
- OWASP Password Storage Cheat Sheet (argon2id first, bcrypt, recommended Argon2id parameters)cheatsheetseries.owasp.org
- MySQL 8.0 Reference Manual: The CHAR and VARCHAR Typesdev.mysql.com
- PHP Manual: Password Constants (PASSWORD_ARGON2_DEFAULT_MEMORY_COST, _TIME_COST, _THREADS)php.net





