The short answer
Semantic Versioning (SemVer) numbers releases MAJOR.MINOR.PATCH, and each number is a promise about your public API:
- MAJOR goes up when you make a change that breaks existing callers (
1.4.2 → 2.0.0). - MINOR goes up when you add functionality that does not break them, or deprecate something (
1.4.2 → 1.5.0). - PATCH goes up when you only fix bugs without breaking them (
1.4.2 → 1.4.3).
Bumping a number resets the ones to its right to zero. A hyphen adds a pre-release (2.0.0-rc.1), a plus sign adds build metadata (2.0.0+20261128), and 0.y.z means initial development, where anything may change.
The rules, in plain words
The specification has eleven numbered rules. Here is what each one asks of you.
| # | Rule | What it means in practice |
|---|---|---|
| 1 | Declare a public API | Write down what callers may rely on: documented functions, CLI flags, HTTP endpoints, config keys. SemVer only makes promises about that surface. |
| 2 | Use X.Y.Z | Three non-negative integers, no leading zeros (1.02.0 is invalid). Each one only ever increases. |
| 3 | Released versions are immutable | Never re-publish different code under a version number that has shipped. Any change, however small, is a new version. |
| 4 | 0.y.z is initial development | Anything may change at any time; the API is not yet stable. |
| 5 | 1.0.0 defines the public API | From here on, the numbers carry the compatibility promise. |
| 6 | PATCH: backward-compatible bug fixes | An internal change that fixes incorrect behaviour, and nothing else. |
| 7 | MINOR: backward-compatible features | New public functionality, or something marked deprecated. It may also cover substantial internal improvements, and may include fixes. PATCH resets to 0. |
| 8 | MAJOR: backward-incompatible changes | Anything that can break a caller. It may include features and fixes too. MINOR and PATCH reset to 0. |
| 9 | Pre-release versions | A hyphen and dot-separated identifiers: 1.0.0-alpha.1. They sort before the release they lead up to and may not be stable. |
| 10 | Build metadata | A plus sign and dot-separated identifiers: 1.0.0+exp.sha.5114f85. Ignored when comparing versions. |
| 11 | Precedence | How versions sort; see which version is newer below. |
Which number do I bump?
Ask one question about the release: could any caller relying on the documented API have to change their code or config? If yes, it is MAJOR. If no, and the release adds or deprecates something, it is MINOR. If it only fixes behaviour that was wrong, it is PATCH. The biggest change in the release decides.
| Change | Bump |
|---|---|
| Remove a public function, endpoint, flag or config key | MAJOR |
| Rename a parameter, field or command | MAJOR |
| Make an optional parameter required | MAJOR |
| Change a default so existing calls behave differently | MAJOR |
| Drop support for a runtime or platform version you supported | MAJOR (most projects treat it as breaking) |
| Add a function, endpoint, optional parameter or response field | MINOR |
| Mark something deprecated, keeping it working | MINOR |
| Substantial internal improvement with no API change | MINOR or PATCH (the spec allows MINOR) |
| Fix a bug so behaviour matches the documentation | PATCH |
| Security fix that keeps the API the same | PATCH |
| Update a dependency without changing your API | PATCH if it was to fix a bug, MINOR if it brings new functionality |
| Docs, tests, CI or refactors nobody can observe | No release needed; if you cut one, PATCH |
One edge case catches everyone: fixing a bug that callers have come to depend on. If the “wrong” behaviour was widely relied on, the fix breaks them, and a MAJOR bump is the honest choice.
Version 0.y.z and when to ship 1.0.0
Under 0.y.z the specification makes no promise: anything may change. The FAQ suggests starting development at 0.1.0and incrementing the minor version for each subsequent release. Many tools still read some meaning into zero versions; npm’s caret range, for example, treats 0.2.3 → 0.3.0 as a breaking step (see ranges).
The FAQ’s test for leaving zero is blunt. Ship 1.0.0 when:
- your software is being used in production;
- you have a stable API that users have come to depend on; or
- you are already worrying a lot about backward compatibility.
Staying on 0.x for years does not protect your users; it only removes the signal that would tell them when an upgrade is safe.
Pre-release and build metadata
A pre-release follows the patch number after a hyphen. Its identifiers are separated by dots, use only ASCII letters, digits and hyphens ([0-9A-Za-z-]), must not be empty, and numeric ones must not have leading zeros. Common shapes:
2.0.0-alpha
2.0.0-alpha.1
2.0.0-beta.3
2.0.0-rc.1
1.0.0-0.3.7
1.0.0-x.7.z.92alpha, beta and rc are convention, not part of the specification; any identifiers are valid. Pick a scheme and keep it, because the sort order depends on the identifiers you choose.
Build metadata follows a plus sign, with the same character rules: 1.0.0+20130313144700, 1.0.0-beta+exp.sha.5114f85. Two versions that differ only in build metadata have the same precedence, so do not use it to tell releases apart.
Which version is newer?
- Compare MAJOR, then MINOR, then PATCH, as numbers (so
1.10.0is newer than1.9.0). - If those are equal, a version with a pre-release is older than the one without:
1.0.0-rc.1 < 1.0.0. - Between two pre-releases, compare identifiers left to right: numeric identifiers as numbers, others in ASCII order, and a numeric identifier is always older than a non-numeric one.
- If every identifier so far is equal, the version with more identifiers is newer.
- Ignore build metadata.
The specification’s own example, oldest to newest:
1.0.0-alpha
< 1.0.0-alpha.1
< 1.0.0-alpha.beta
< 1.0.0-beta
< 1.0.0-beta.2
< 1.0.0-beta.11
< 1.0.0-rc.1
< 1.0.0Note beta.2 < beta.11: numeric identifiers compare as numbers. That only works because the dot keeps them separate. Write rc.1, not rc1, or rc10 will sort before rc2.
Validating a version string
The specification publishes a regular expression that matches exactly the valid SemVer strings, with capture groups for major, minor, patch, pre-release and build metadata. Copy it for a CI check on your tags or a form field:
^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$It rejects a leading v. v1.2.3 is not itself a semantic version, but the FAQ calls the prefix a common way to mark a version number, and it is the usual shape of a git tag. Strip the v before validating, and be consistent about it in tags.
Version ranges: caret, tilde and friends
SemVer itself defines no range syntax; package managers do, and they do not all agree. In npm (node-semver):
| Range | Means | Accepts |
|---|---|---|
^1.2.3 | >=1.2.3 <2.0.0 | New minors and patches; npm’s default when you install a package |
^0.2.3 | >=0.2.3 <0.3.0 | Patches only, because under 0.x the minor is treated as breaking |
^0.0.3 | >=0.0.3 <0.0.4 | That version only |
~1.2.3 | >=1.2.3 <1.3.0 | Patches only |
1.2.x | >=1.2.0 <1.3.0 | Any patch of 1.2 |
1.2.3 | Exactly 1.2.3 | Nothing else |
By default, npm ranges do not match pre-releases unless the range itself names a pre-release on the same MAJOR.MINOR.PATCH, so ^1.2.3 will not pull in 1.3.0-beta.1.
Elsewhere, the same characters can mean something else:
- Cargo (Rust): a bare
"1.2.3"inCargo.tomlis a caret requirement, the same as^1.2.3. - Composer (PHP):
^matches npm, but~1.2means>=1.2 <2.0, while~1.2.3means>=1.2.3 <1.3.0. The last number you write is the one allowed to move. - Python: versions follow PEP 440, not SemVer. Its compatible-release operator
~=1.4.5means>=1.4.5, ==1.4.*. - Go modules: versions need the
vprefix (v1.2.3), and from v2 on the major version becomes part of the module path (example.com/mod/v2).
Check your package manager’s documentation for the full syntax; the sources below link each one.
Deprecations and breaking changes
The FAQ asks for at least one minor release that deprecates a feature before the major release that removes it. In practice:
- 1.5.0: mark the old API deprecated, keep it working, ship the replacement, and say in the changelog what to use instead and in which major version it goes away.
- 1.6.0, 1.7.0…: carry on; warnings at runtime or in the compiler help callers find the old calls.
- 2.0.0: remove it, and lead the release notes with a short migration guide.
If you ship a breaking change in a minor or patch release by mistake, the FAQ is clear: do not change or re-publish the released version. Release a new version that restores compatibility, and tell users which version broke. The breaking change can come back in the next major.
SemVer, Conventional Commits and the changelog
A version number tells a machine whether an upgrade is safe; the changelog tells a person why. The two line up neatly with the change types in our changelog format guide: anything under Removed, or a Changed entry that breaks callers, means MAJOR; Added or Deprecated means MINOR; Fixed or Security alone means PATCH.
With Conventional Commits the mapping comes from commit messages: fix: is a patch, feat: a minor, and a ! after the type or a BREAKING CHANGE: footer a major. Tools such as release-please and semantic-release read those messages to pick the next version and draft the notes. Someone still has to decide what counts as breaking; a commit prefix is only as accurate as the person who typed it.
When SemVer is the wrong fit
SemVer is built for software that other software depends on: libraries, SDKs, CLIs, APIs. It fits less well where there is no compatibility contract to describe:
- Calendar versioning (CalVer) puts the date in the number, as Ubuntu does with
YY.0M(24.04). It suits products released on a schedule, where “how old is this?” matters more than “will it break?”. - Hosted SaaS often has no version users install. Many such teams version the API separately (a date or
v2in the URL) and keep a dated product changelog. - Applicationspeople run rather than build on can use SemVer, but MAJOR then usually means “a big change in how it works”, which is marketing, not the specification.
Whatever you pick, say so in the changelog preamble so readers know how to read the numbers.
Common mistakes
- Re-tagging a release. Moving
v1.4.0to a new commit breaks every lockfile and cache that already has it. Ship1.4.1. - Bumping MAJOR for marketing. A redesign with no breaking change is a MINOR. Spending major versions on launches teaches users to ignore them.
- Hiding breaking changes in a MINORto avoid “version inflation”. Big major numbers are fine; broken builds after
npm updateare not. - No declared public API. If you never said what is public, every change is arguably breaking. Document the surface, and mark internals as internal.
- Leading zeros and four parts.
1.02.0and1.2.3.4are not valid SemVer and will confuse tools that parse it. rc1instead ofrc.1. Without the dot,rc10sorts beforerc2.
Release checklist
- List what changed since the last tag, and which of it touches the public API.
- Pick the bump from the biggest change: breaking → MAJOR, feature or deprecation → MINOR, fixes only → PATCH.
- Reset the numbers to the right of the one you bumped to 0.
- For a MAJOR, check each removal was deprecated in an earlier minor, and write the migration notes.
- Update the version in your manifest (
package.json,Cargo.toml,pyproject.toml…). - Move the Unreleased section of the changelog under the new version and today’s date.
- Tag the commit with the same version (with or without
v, as your project always does) and publish. - Never move or reuse that tag; anything else is the next version.
Questions
What does SemVer stand for?
Semantic Versioning: version numbers whose parts carry meaning (semantics) about compatibility. The current specification is 2.0.0, written by Tom Preston-Werner and published at semver.org.
Is v1.2.3 a valid semantic version?
Strictly, no; the version is 1.2.3. The v is a widely used prefix for tags, and some ecosystems, like Go modules, require it.
Does a new feature ever need a MAJOR bump?
Only if adding it breaks something that exists, for example by changing a default or a return type. Additions alone are MINOR.
Should a security fix be a PATCH?
If it keeps the API the same, yes. If closing the hole means removing or changing public behaviour, it is breaking, and the honest bump is MAJOR; many projects also backport the fix to older supported lines as patch releases there.
Is there a limit on how big the numbers get?
No. 1.0.0 → 42.0.0 is valid. The FAQ only asks for good judgment on the length of the whole string.
How do I version a REST API with SemVer?
Most HTTP APIs expose only the major version to clients (/v2/ or a header) and ship additive changes without a new number. Read versioning strategy documentation for REST APIs for how teams write that policy down.
Sources
- Semantic Versioning 2.0.0 (specification, FAQ and regular expression)
- node-semver: ranges and npm: About semantic versioning
- The Cargo Book: Specifying dependencies
- Composer: Versions and constraints
- PEP 440: Version identification and dependency specification
- Go: Module version numbering
- Conventional Commits 1.0.0
- Calendar Versioning