Development

snake_case Explained: Where and Why It's Used

By AZ Utils Editorial · · 9 min read

snake_case Explained: Where and Why It's Used

If you have written Python, designed a database, or defined a constant, you have used snake_case — the naming style that joins lowercase words with underscores, like user_name or max_retry_count. It is one of the most common conventions in programming, and understanding where and why it is used will make your code read as natural to others in its ecosystem. This guide explains snake_case fully: what it is, where it is conventional, its variants, and how to use it well.

It is written for developers and students learning naming conventions, and anyone curious about why so many identifiers are written with underscores.

What Is snake_case?

snake_case is a naming convention in which a multi-word identifier is written in all lowercase letters with words separated by underscores, with no spaces or capital letters. Examples include first_name, total_amount, calculate_average and is_active. The underscores stand in for the spaces you would use in ordinary writing, keeping the words clearly separated and readable while remaining a single valid identifier that a programming language will accept.

The name is descriptive: the low underscores connecting the words make the identifier look as though it is sliding along the ground, like a snake. It is the natural counterpart to the "camel" of camelCase, and the two represent the two dominant approaches to joining words in code — one using case to mark boundaries, the other using a separator character. snake_case's all-lowercase form gives it a calm, uniform appearance that many find especially easy to read, since there are no capital letters to process, only the clear underscore breaks between words.

In short: snake_case writes multi-word identifiers in lowercase with underscores between words, like user_name. It is the conventional style for variables and functions in Python, for database column names, and — in its uppercase form, SCREAMING_SNAKE_CASE — for constants.

Where snake_case Is Used

snake_case is the dominant convention in several important areas of programming, and recognising them helps you write code that fits its environment. The most prominent is Python, whose widely followed style guide specifies snake_case for variable names, function names and method names. In idiomatic Python, you write def calculate_total(): and user_email = "...", and using camelCase instead would immediately mark the code as un-Pythonic. Because Python is so widely taught and used, snake_case is many programmers' first encounter with a separator-based naming style.

Beyond Python, snake_case is the conventional choice for database column and table names in many systems, where lowercase-with-underscores avoids case-sensitivity pitfalls and reads clearly in queries — columns like created_at and order_id are ubiquitous. It also appears in configuration files, in the naming of files and assets in some ecosystems, and in languages such as Ruby and Rust for their respective identifier conventions. The common thread is that snake_case is favoured where lowercase clarity and explicit word separation are valued, and where the surrounding ecosystem has standardised on it. Following the local convention — snake_case in these contexts — is what makes your code look native rather than foreign.

SCREAMING_SNAKE_CASE for Constants

snake_case has an important uppercase variant, usually called SCREAMING_SNAKE_CASE (or simply UPPER_SNAKE_CASE), in which the words are written in all capitals and joined by underscores, like MAX_CONNECTIONS, DEFAULT_TIMEOUT or API_BASE_URL. This form is the near-universal convention for constants — values that are fixed and should not change while the program runs — across a great many languages, including Python, JavaScript, Java, C and others. When you see an identifier in all-caps with underscores, you can reliably read it as "this is a constant," which is exactly the kind of instant signal that good naming conventions provide.

The reason this variant is so widely shared, even in languages that otherwise use camelCase or PascalCase, is that the all-caps form stands out visually as something special and unchanging. In a JavaScript file full of camelCase variables, a MAX_RETRIES constant draws the eye and announces its role. This cross-language consistency makes SCREAMING_SNAKE_CASE one of the most universally recognised naming conventions in programming, and using it for your constants is a small, widely understood signal that improves readability regardless of the language's other conventions.

Try Our Free Case Converter

Converting names to or from snake_case by hand — adding underscores, lowercasing everything — is tedious, especially for many identifiers. Our Case Converter converts text to snake_case and back to other styles instantly.

  • ✅ Convert to snake_case, SCREAMING_SNAKE_CASE, camelCase, kebab-case and more
  • ✅ Reformat identifiers quickly when refactoring or migrating
  • ✅ Runs in your browser — your text stays private

👉 Convert to snake_case now →

The Readability Case for snake_case

There is a long-running, friendly debate in programming about whether separator-based styles like snake_case are easier to read than case-based styles like camelCase, and it is worth understanding because it explains why snake_case has such devoted adherents. The argument in snake_case's favour is that explicit separators mirror how we read natural language: words in ordinary text are separated by spaces, and an underscore is the closest an identifier can get to that familiar visual break. user_account_balance arguably parses more easily at a glance than userAccountBalance, because the eye does not have to detect the subtle case changes that mark word boundaries in camelCase — the gaps are explicit rather than implied.

This readability argument is part of why snake_case was chosen for Python, a language that prizes readability as a core value, and why it is favoured in contexts like database schemas where clarity at a glance matters. The counter-argument is that camelCase is more compact and that experienced developers read it just as fluently, which is also true. The honest conclusion is that both are perfectly readable to people accustomed to them, and the choice is ultimately governed by ecosystem convention rather than any decisive readability advantage. But understanding the readability rationale helps explain why snake_case feels so natural in the communities that adopted it, and why those communities defend it — it is not arbitrary preference but a considered choice about how identifiers should look.

Why Following the Convention Matters

As with all naming styles, snake_case is about communication and consistency rather than correctness — your code will run whatever style you choose. But choosing the style your ecosystem expects has real benefits. Code that follows the local convention reads as natural and competent to others working in that language, while code that ignores it looks out of place and slows readers down as they adjust to the unexpected style. A Python codebase written in camelCase, or a database with mixed casing in its column names, creates constant low-level friction for everyone who works with it, even though nothing is technically broken.

Consistency within a project matters even more than matching the broader ecosystem. The worst outcome is a codebase that mixes snake_case, camelCase and other styles arbitrarily, forcing readers to absorb a different convention every few lines and making the code feel disorganised and unprofessional. Picking the conventional style for your language — snake_case where it is the norm — and applying it uniformly is a small discipline that pays off in readability and maintainability. It signals that the code was written with care and respect for the conventions its readers expect, which is a quiet but real marker of quality.

snake_case and Databases

The use of snake_case in databases deserves a closer look, because it is one of the convention's most consistent and practically important homes. Database systems often treat unquoted identifiers in a case-insensitive or case-folding way, which means that a column named userName might be stored or matched as username depending on the system, creating subtle confusion. Using all-lowercase snake_case sidesteps this entirely: user_name contains no capitals to be folded, so it behaves predictably everywhere. The underscores keep the multi-word names readable in queries, where you frequently scan column lists, and they avoid the need for quoting that mixed-case names sometimes require.

This is why snake_case is so deeply entrenched in SQL schemas and why columns like created_at, updated_at, order_id and is_active are almost universal. The convention extends naturally to table names too. For developers, an interesting wrinkle arises when a snake_case database meets a camelCase application language like JavaScript: the data layer often maps between the two, converting user_name in the database to userName in the code, precisely because each side has its own strong convention. Tools and ORMs frequently handle this translation automatically, which is itself a testament to how firmly each ecosystem holds to its own naming style. Understanding that databases conventionally speak snake_case helps you design schemas that feel idiomatic and avoid the case-sensitivity headaches that mixed-case identifiers can cause.

Real-World Examples

A few snippets show snake_case in its natural habitats. In Python, you would write def get_user_profile(user_id): and inside it full_name = first_name + " " + last_name — all snake_case, as the language's style guide directs. In a SQL database you would query SELECT order_id, created_at FROM customer_orders, with table and column names in snake_case for clarity and consistency. For constants, across many languages, you would declare something like MAX_UPLOAD_SIZE = 10485760 in SCREAMING_SNAKE_CASE to mark it as a fixed value. Each of these reads as idiomatic precisely because it follows the convention its context expects, and a developer familiar with the ecosystem absorbs the meaning without a second thought.

Common Mistakes

  1. Using camelCase in snake_case ecosystems like Python, which makes the code look un-idiomatic.
  2. Mixing snake_case and other styles inconsistently within a project.
  3. Forgetting SCREAMING_SNAKE_CASE for constants, missing a widely understood signal.
  4. Using capitals or spaces in snake_case — it is strictly lowercase words joined by underscores.
  5. Inconsistent database casing, which causes confusion and sometimes case-sensitivity bugs.

Best Practices

  • Use snake_case where it is the convention — Python variables and functions, database names, and similar contexts.
  • Use SCREAMING_SNAKE_CASE for constants across languages.
  • Keep it strictly lowercase with single underscores between words.
  • Be consistent across your whole project.
  • Use a case converter to reformat names quickly when migrating or refactoring.

Frequently Asked Questions

What is snake_case?

snake_case is a naming convention that writes multi-word identifiers in all lowercase with underscores between words, such as user_name or total_amount. The underscores keep the words readable while forming a single valid identifier.

Where is snake_case used?

It is the conventional style for variables and functions in Python, for database table and column names, and in configuration files, among other contexts. Its uppercase form is used for constants across many languages.

What is SCREAMING_SNAKE_CASE?

It is snake_case written in all capital letters, like MAX_CONNECTIONS, and it is the near-universal convention for constants — fixed values — across many programming languages.

Why does Python use snake_case?

Python's official style guide recommends snake_case for variable, function and method names, valuing its lowercase clarity and readability. Following it makes Python code idiomatic; using camelCase instead looks un-Pythonic.

Is snake_case better than camelCase?

Neither is universally better; each is conventional in different ecosystems. snake_case dominates Python and databases, while camelCase dominates JavaScript and Java variables. Use whichever your language and project conventionally expect.

Can snake_case have capital letters?

Standard snake_case is all lowercase. The all-capital variant, SCREAMING_SNAKE_CASE, is a separate convention reserved for constants. Mixing capitals into ordinary snake_case is non-standard.

Conclusion

snake_case — lowercase words joined by underscores — is one of programming's most familiar conventions, the standard for variables and functions in Python, for database column names, and, in its all-caps SCREAMING_SNAKE_CASE form, for constants across nearly every language. Its appeal is clean, lowercase readability with explicit word separation, and its value comes from following it consistently where it is expected. Write snake_case in the ecosystems that favour it, reserve the screaming variant for constants, keep it strictly lowercase, and stay consistent across your project. When you need to convert identifiers to or from snake_case, a case converter makes it instant — and your code will read as natural to everyone who works in its language.

👉 Convert to snake_case with our free tool →

AZ Utils Editorial

AZ Utils Editorial

Finance & web-tools writer

AZ Utilis writes practical, plain-English guides on calculators, finance and everyday web tools, drawing on years of experience helping beginners and small businesses get the numbers right.

Development

How to Format JSON (Beautify & Minify)

How to format JSON — beautify it for readability or minify it for production — in tools, editors, the command line and code, with the why behind each.

AZ Utils Editorial · · 10 min read