What Is Semver? MAJOR.MINOR.PATCH Version Numbers and ^ ~ Ranges
Updated: November 6, 2026 · AracMerkezi
▶ Open Semver Version Comparator
If a software package’s version consists of three numbers such as 2.4.1, it is most likely using semantic versioning (semver). This method lets you judge from the version number how risky an update is. npm, Cargo, Composer and many other package managers are built on this scheme. This guide explains the bump rules, how versions are ordered, and which version the ^ and ~ ranges select, using tested examples.
What the three numbers mean
The version number has the form MAJOR.MINOR.PATCH:
- MAJOR: Increases when backward-incompatible changes are made. Your old code may stop working.
- MINOR: Increases when a backward-compatible new feature is added.
- PATCH: Increases for backward-compatible bug fixes.
When one number increases, the numbers to its right reset to zero: after 1.4.7, a bug fix is 1.4.8, a new-feature release is 1.5.0, and a major release is 2.0.0 (we confirmed this with the inc function of npm’s semver package).
Which change bumps which number?
| Change | Number that increases | After 1.4.7 |
|---|---|---|
| A bug was fixed, the API is the same | PATCH | 1.4.8 |
| A new function was added, old ones still work | MINOR | 1.5.0 |
| A function’s name or return type changed | MAJOR | 2.0.0 |
One question is enough to decide: “If someone using the old version updates, will they have to change their code?” If yes, MAJOR increases.
How are versions compared?
Comparison is done left to right, numerically. The most common mistake is sorting versions like text:
- 1.2.3 < 1.10.0 (because 2 < 10; as text, “10” would come first)
- 2.0.0 > 1.99.99
- 1.0.0 = 1.0.0
Try it: in JavaScript, ['1.9.0','1.10.0','1.2.3'].sort() gives 1.10.0, 1.2.3, 1.9.0 in text order; the correct order is 1.2.3, 1.9.0, 1.10.0. When sorting versions, always use a library that compares numerically.
Pre-release tags
Versions that are not stable are tagged with a hyphen: 1.0.0-alpha, 1.0.0-beta.2, 1.0.0-rc.1. A pre-release is always considered lower than the stable version of the same number. Ordering example:
- 1.0.0-alpha
- 1.0.0-alpha.1
- 1.0.0-beta
- 1.0.0-rc.1
- 1.0.0
Pre-release parts are separated by dots; numbers are compared numerically and alphabetic parts alphabetically, so 1.0.0-beta.2 comes before 1.0.0-beta.11. Build metadata added with a plus sign (1.0.0+build.5) is ignored in ordering: 1.0.0+build.5 and 1.0.0+build.9 have equal precedence.
The ^ and ~ range operators
When writing version ranges in files such as package.json, two shortcuts are used a lot (npm rules):
| Notation | Meaning | Example range |
|---|---|---|
| ^1.2.3 | Keep the major version fixed | 1.2.3 and above, below 2.0.0 |
| ~1.2.3 | Keep the minor version fixed | 1.2.3 and above, below 1.3.0 |
| ^0.2.3 | In 0.x versions, keep the minor fixed | 0.2.3 and above, below 0.3.0 |
| ^0.0.3 | Only that exact version | 0.0.3 and above, below 0.0.4 |
Because versions starting with zero are considered “unstable”, the ^ operator works more narrowly in these cases. Wildcard forms such as 1.x and 1.2.x, and explicit ranges such as >=1.2.0 <2.0.0, can also be used; >=1.2.0 <2.0.0 describes the same set as ^1.2.0.
Example 1: Which version gets installed?
Suppose these versions are published in the registry: 1.2.2, 1.2.3, 1.4.0, 1.9.5, 2.0.0, 2.1.0. If you wrote ^1.2.3, the highest version that stays on major 1 is chosen: 1.9.5. 1.2.2 is too low, and 2.0.0 and 2.1.0 are a new major version; both are left out. With the same list, ~1.2.3 could be at most 1.2.x; since the list has 1.2.3, the result would be 1.2.3. The line "dependencies": {"example-package": "^1.2.3"} in package.json makes this choice at install time; the lock file records the chosen version (1.9.5 here) and later installs get the same version, so even if a new 1.9.6 is published, nothing changes until you run the update command.
Example 2: Patch updates with ~
Versions: 1.2.2, 1.2.3, 1.2.8, 1.3.0, 2.0.0. The ~1.2.3 range covers 1.2.3 up to 1.3.0 (excluding 1.3.0): 1.2.8 is installed. ^1.2.3 would also accept 1.3.0. For packages where you want to be more cautious, ~ is preferred.
Example 3: The 0.x trap
If you wrote ^0.2.3, 0.2.9 matches but 0.3.0 does not; ^0.0.3 leaves out even 0.0.4. So for 0.x packages, ^ is narrower than you might expect. Pre-releases have a separate rule too: the range ^1.2.3 does not select 1.3.0-beta.1, because pre-releases are accepted only for the same version triple when the range itself is written with a pre-release (for example, ^1.2.3-beta.2 accepts 1.2.3-beta.4).
Practical tips
- If you break an API in your own package, increase the major version and write the change note clearly.
- When updating dependencies, take patch and minor versions first, and take major versions only after testing.
- Use a lock file; it ensures the same versions are installed in every environment.
- Using semver even for an application itself makes the change history easy to follow.
- Where you need to compare versions, verify with a tool such as the Semver Version Comparator instead of handling text yourself.
Limits
Semver is a promise, not a guarantee. A package maintainer can accidentally change behavior in a patch. That is why you need to run your tests after automatic updates. Also, not all projects use semver; some use calendar-based versioning (such as 2026.10). Range notation (^, ~) can differ slightly from tool to tool; the examples in this article were verified with version 7.x of npm’s semver package.
Common mistakes
- Sorting versions like text: “1.9.0” is wrongly thought to be greater than “1.10.0”.
- Ranking a pre-release above the stable version: 1.0.0-rc.1 comes before 1.0.0.
- Bumping the major version for every new feature, or changing the API in a patch release.
- Not committing the lock file; different versions get installed on different machines.
- Forgetting that the ^ operator works more narrowly with versions that start with zero.
A short checklist
Before a release, check: Was the change note written? Is there a backward-incompatible change? Does the version number match the type of change? Are the tag and the package version the same? These four questions prevent most version confusion.
Glossary
- Dependency: An external package your project uses.
- Registry: The central place where package versions are published and downloaded.
- Lock file: The file that pins which versions were actually installed.
- Backward compatibility: Old code being able to run with the new version unchanged.
Tools
The Semver Version Comparator shows which of two versions is newer. While editing your package.json, you can validate the structure with the JSON Formatter. For scheduled tasks, also take a look at the guide How to Write a Cron Expression.
Frequently asked questions
What do MAJOR, MINOR and PATCH mean?
MAJOR marks backward-incompatible changes, MINOR marks backward-compatible new features, and PATCH marks backward-compatible bug fixes.
Which is newer, 1.2.3 or 1.10.0?
1.10.0 is newer; versions are compared numerically from left to right, and 10 is greater than 2.
Which versions does ^1.2.3 cover?
Under npm rules it covers 1.2.3 and above, up to but not including 2.0.0; ~1.2.3 covers versions up to 1.3.0.
Tools mentioned in this guide
More guides
- What Are JSON, Base64 and URL Encoding? Encoding vs Encryption vs Hashing – What do JSON, Base64, URL encoding, HTML entities, SHA and JWT do? Encoding vs encryption vs hashing, with examples that were run and verified.
- What Is JSON? Structure, Formatting, Validation and Finding Errors – What is JSON and how do you read and validate it? A nested example, a valid/invalid comparison table, number and date traps and the formatting difference.
- How to Write a Cron Expression: Crontab Scheduling Guide with Examples and Common Traps – What is a cron expression? Examples for every 5 minutes, 03:00 and weekdays at 09:30, plus the */7 trap, the day OR rule and time zone pitfalls.
- What Is XML? The Difference Between XML and JSON, and How to Convert – What is XML, and what are its syntax rules? Differences between XML and JSON, how to choose between them, and examples of converting XML to JSON.
- What Is YAML? Indentation Rules, Differences from JSON, and Common Mistakes – What is YAML, and how does indentation work? Differences between YAML and JSON, common mistakes (tabs, colons, yes/no), and converting YAML to JSON.
This article is for general information only and is not legal, financial or medical advice. We are not an official institution.