snake_case writes words in lowercase and joins them with underscores: my_variable_name. The converter reads camelCase, PascalCase and kebab-case as well as plain text: myVariableName becomes my_variable_name, HTTPServer becomes http_server and user-first-name becomes user_first_name. Underscores at the start or end of a name are kept, so _privateValue becomes _private_value.
Brand names, leading digits, Python's underscores and accented letters are the four places where the word split needs a human check.
How the converter splits text into snake_case words
Eight things happen when text becomes snake_case:
- Spaces, hyphens and dots become underscores. Each of them marks a word boundary, so user-first-name becomes user_first_name and version 2.5 becomes version_2_5.
- A capital after a lowercase letter starts a new word. That is how camelCase marks its words: myVariableName becomes my_variable_name. A capital after a digit starts a new word too.
- A run of capitals stays one word. HTTPServer becomes http_server, not h_t_t_p_server: only the last capital of the run, the one a lowercase letter follows, opens the next word.
- Every letter becomes lowercase. The underscore already marks each word, so capitals carry nothing: MAX_RETRY_COUNT becomes max_retry_count. For a constant in capitals, see below.
- Digits stay attached to their word. md5Hash becomes md5_hash. A digit starts a word of its own only after a space or a symbol.
- Apostrophes are dropped without splitting the word. Don't becomes dont, not don_t, because a Python name is built only from letters, digits and the underscore (Python reference).
- Other symbols are removed. Between two words they leave one underscore, so C++ & C# becomes c_c and user__name becomes user_name.
- Leading and trailing underscores are kept. In Python they carry a meaning, so _privateValue becomes _private_value and __init__ stays __init__.
getHTTPResponseCode becomes get_http_response_code
Don't Stop: Café 2.5 becomes dont_stop_café_2_5
_privateValue becomes _private_value
These rules read letters, not meaning, so a few kinds of text come out in a form worth reading before you use it.
Where the word split needs a human check
Four kinds of text need a second look: brand names with a capital inside, names that start with a digit or a symbol, underscores that carry a meaning, and accented letters.
Brand names with an inner capital, like iPhone and OAuth
A capital inside a word reads as a word boundary, so iPhone 15 Pro becomes i_phone_15_pro and OAuth2Client becomes o_auth2_client. The JavaScript libraries lodash and change-case split iPhone the same way. Rust's API guidelines go further: in snake_case, “a ‘word’ should never consist of a single letter unless it is the last ‘word’” (Rust API Guidelines). If the name is a brand, join it by hand: iphone_15_pro.
Names that start with a digit or a symbol
2nd place becomes 2nd_place, which works as a quoted database column but not as a variable: a Python name “cannot start with a digit” (Python reference), and neither can a C name (cppreference). Put a letter in front: second_place. Symbols that carry the meaning are lost too: C++ & C# becomes c_c, so spell such names out first – cpp, csharp.
Leading underscores, like _private and __init__
The converter keeps underscores at the start and end of the input, because Python gives them a meaning. PEP 8 describes _single_leading_underscore as a weak “internal use” indicator and __double_leading_and_trailing_underscore__as “magic” objects or attributes (PEP 8). So _privateValue becomes _private_value and __init__ stays __init__. Check them before you keep them: in C, names that begin with an underscore followed by a capital letter or by another underscore are reserved (cppreference).
Accented letters
Accented letters are kept: Café Résumé becomes café_résumé. That is a valid name in Python, whose identifiers accept non-ASCII letters (Python reference), and in PostgreSQL, which allows “letters with diacritical marks and non-Latin letters” (PostgreSQL). Environment variables are stricter: the names the standard shell utilities use consist “solely of uppercase letters, digits, and the <underscore>” (POSIX), so replace accented letters by hand there.
Where snake_case is used
snake_case is the format for names that a programming language or a database reads, where a hyphen would be taken for a minus sign. The Rust compiler's documentation gives the shape: all characters “in lowercase, with words separated with a single underscore” ( rustc).
Python functions, variables and modules
PEP 8 asks for function names in “lowercase, with words separated by underscores as necessary to improve readability”, and variable names follow the same rule (PEP 8): getUserName becomes get_user_name. mixedCase is allowed “only in contexts where that's already the prevailing style”. Module names are short and lowercase, and “Underscores can be used in the module name if it improves readability”, so DataLoader becomes data_loader; in package names “the use of underscores is discouraged” (PEP 8).
Rust, Ruby and Elixir
Rust uses snake_case for “value-level” constructs – modules, functions, methods and local variables (Rust API Guidelines), and its compiler warns by default when one of them is not in snake case (rustc): parseConfig becomes parse_config. Ruby's documentation says “The convention is to use underscores to separate words in a multiword method name” (Ruby docs), and the community Ruby Style Guide extends it to symbols and variables (Ruby Style Guide). Elixir is the strictest: developers “must use snake_case when defining variables, function names, module attributes” (Elixir).
Database tables and columns
In PostgreSQL, “unquoted names are always folded to lower case”, while quoting a name makes it case-sensitive (PostgreSQL). A column named firstName has to be written in double quotes in every query; firstName becomes first_name, which needs no quotes at all. MySQL adds another reason: table names are “not case-sensitive in Windows, but are case-sensitive in most varieties of Unix” (MySQL), and lowercase with underscores reads the same on both.
Constants and environment variables
Constants use the same underscores in capital letters, a format Rust's guidelines call SCREAMING_SNAKE_CASE (Rust API Guidelines). PEP 8 writes constants “in all capital letters with underscores separating words” (PEP 8), Google's JavaScript style guide calls it CONSTANT_CASE (Google), and PHP declares class constants “in all upper case with underscore separators” (PSR-1). Environment variables have the same shape (POSIX).
This converter returns lowercase, so a constant takes two steps: maxRetryCount becomes max_retry_count, then the uppercase mode turns max_retry_count into MAX_RETRY_COUNT. In the same way databaseUrl ends up as DATABASE_URL.
Where snake_case is not the convention
Some languages that accept underscores still choose capitals. Go's convention is “MixedCaps or mixedCaps rather than underscores to write multiword names” ( Effective Go). PHP method names “MUST be declared in camelCase” (PSR-1). For JSON, Google's own style guide says “Property names must be lower camel-cased” ( Google JSON Style Guide), though that is Google's rule rather than a standard. snake_case belongs where the language or the database already uses it.
How snake_case differs from kebab-case and camelCase
kebab-case splits the words the same way but joins them with hyphens, for names a browser, a shell or a file system reads: the kebab-case Converter turns user_first_name into user-first-name. The two meet in Python packaging: a package name may contain hyphens, and PyPI compares names after every run of dots, hyphens and underscores is “replaced with a single - character” (PEP 503), but the module you import is my_package. camelCase drops the separator and marks each word with a capital, the usual choice for JavaScript and JSON: the camelCase converter turns first_name into firstName. Choose snake_case when the name lives inside Python, Rust, Ruby or SQL.
Questions about snake_case
What is snake case?
Snake case is a way of writing a name without spaces: the words are lowercase and joined with underscores, as in my_variable_name. The Rust compiler's documentation describes it as all characters "in lowercase, with words separated with a single underscore."
What is SCREAMING_SNAKE_CASE?
It is snake case in capital letters, as in MAX_RETRY_COUNT, and it is the usual format for constants. Python's PEP 8 writes constants "in all capital letters with underscores separating words," Rust's API guidelines call the format SCREAMING_SNAKE_CASE, and Google's JavaScript style guide calls it CONSTANT_CASE. It is also known as upper snake case. This converter returns lowercase: convert to snake_case first, then to uppercase, and max_retry_count becomes MAX_RETRY_COUNT.
snake_case or camelCase: which should I use?
Use the one the language already uses. Python and Rust name functions and variables in snake_case, Go uses "MixedCaps or mixedCaps rather than underscores," and Google's JSON style guide asks for camelCase property names. In code that already mixes them, follow the existing style: PEP 8 allows mixedCase where it is "already the prevailing style."
How do I turn snake_case back into words?
Replace the underscores with spaces, then convert to title case: first name becomes First Name. With the underscores left in, each word still gets its capital but the underscores stay, so the result is First_Name.
Does snake_case keep numbers?
Yes. A digit stays attached to its word, so md5Hash becomes md5_hash, and a number after a space becomes a word of its own: version 2.5 becomes version_2_5. A Python or C name cannot start with a digit, though, so a result such as 2nd_place needs a letter in front before it works as a variable name.