Version numbers look simple — just three numbers separated by dots. But they carry meaning. Semantic versioning (SemVer) is a convention that makes version numbers useful: each part of the number tells you something specific about what changed between releases.

If you publish libraries, manage dependencies, or just wonder why your package.json has all those carets and tildes, this guide explains how SemVer works and why it matters.

The Format

A semantic version has three parts:

MAJOR.MINOR.PATCH
  • MAJOR: Incremented when you make incompatible API changes (breaking changes)
  • MINOR: Incremented when you add functionality in a backward-compatible manner
  • PATCH: Incremented when you make backward-compatible bug fixes
1.0.0 → 1.0.1  (bug fix)
1.0.1 → 1.1.0  (new feature, backward compatible)
1.1.0 → 2.0.0  (breaking change)

Each increment resets the numbers to the right:

1.4.7 → 1.4.8  (patch)
1.4.8 → 1.5.0  (minor — patch resets)
1.5.0 → 2.0.0  (major — minor and patch reset)

What Counts as a Breaking Change?

This is the most important question in SemVer, and the one most frequently debated. Here are clear examples:

Breaking Changes (Bump MAJOR)

  • Removing a public function or method
  • Changing the signature of a public function (different parameters, different return type)
  • Renaming a public class, module, or exported symbol
  • Changing default behavior that consumers rely on
  • Dropping support for a runtime version (e.g., dropping Node.js 16 support)
  • Changing the structure of a configuration file in an incompatible way

Non-Breaking Changes (Bump MINOR)

  • Adding a new public function, method, or endpoint
  • Adding optional parameters with default values
  • Adding new configuration options
  • Deprecating functionality (but not removing it yet)
  • Adding new enum values (in most languages)

Bug Fixes (Bump PATCH)

  • Fixing incorrect behavior to match the documented specification
  • Security patches that do not change the API
  • Performance improvements with no API changes
  • Fixing typos in error messages
  • Correcting documentation

Edge Cases

Some changes are genuinely ambiguous:

  • Fixing a bug that people depend on: If your bug fix changes behavior that consumers rely on, it is effectively a breaking change, even though the old behavior was incorrect. Use your judgment — if the fix affects many users, consider a MAJOR bump.
  • Widening type constraints: Accepting more input types is generally non-breaking for callers but could be breaking for implementers of interfaces.
  • Transitive dependency updates: If your library updates a dependency in a way that changes its behavior, the impact flows through to your consumers.

Pre-Release Versions

SemVer supports pre-release identifiers appended with a hyphen:

2.0.0-alpha.1
2.0.0-beta.1
2.0.0-beta.2
2.0.0-rc.1
2.0.0

Pre-release versions indicate that the release is unstable and might not satisfy the compatibility requirements of the normal version. They have lower precedence than the normal version:

1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-beta < 1.0.0-rc.1 < 1.0.0

Common pre-release tags:

Tag Meaning
alpha Early testing, API may change significantly
beta Feature complete, may have bugs
rc (release candidate) Considered ready for release, final testing

Build Metadata

Build metadata is appended with a + sign and is ignored for version precedence:

1.0.0+build.123
1.0.0+20260908

Two versions that differ only in build metadata are considered equal.

Version Ranges in Package Managers

Package managers use version ranges to specify which versions of a dependency are acceptable.

npm / Yarn / pnpm

Syntax Meaning Example Matches
1.2.3 Exact version 1.2.3 Only 1.2.3
^1.2.3 Compatible with ^1.2.3 >=1.2.3 and <2.0.0
~1.2.3 Approximately equal ~1.2.3 >=1.2.3 and <1.3.0
>=1.2.3 Greater than or equal >=1.2.3 1.2.3, 1.3.0, 2.0.0, etc.
1.x Any minor/patch 1.x >=1.0.0 and <2.0.0
* Any version * Everything

The caret (^) is npm’s default and the most commonly used range. It allows patches and minor updates but not major updates. The reasoning: minor versions add features and patches fix bugs, both without breaking your code.

The tilde (~) is more conservative. It only allows patch updates within the same minor version.

Cargo (Rust)

Cargo uses similar semantics but with different defaults:

[dependencies]
serde = "1.0"        # Same as ^1.0 — allows >=1.0.0, <2.0.0
tokio = "=1.28.0"    # Exact version
rand = ">=0.8, <0.9" # Explicit range

pip (Python)

requests>=2.28,<3.0
django~=4.2        # Compatible release: >=4.2, <5.0
flask==2.3.2        # Exact version

You can experiment with version comparisons and ranges using our SemVer calculator to see exactly which versions a range includes.

The 0.x Problem

Versions below 1.0.0 are treated specially in SemVer. The spec says that anything may change at any time during 0.x development — there are no backward-compatibility guarantees.

In practice, this creates problems:

  • ^0.2.3 in npm means >=0.2.3, <0.3.0 (not <1.0.0), because npm treats the minor version as effectively “major” for 0.x versions
  • Many popular packages stay at 0.x for years, even though they are stable and widely used
  • Consumers have no way to distinguish “early unstable prototype” from “mature but the author never bumped to 1.0”

Recommendation: If your library is used in production by others, release 1.0.0. The 0.x range signals instability, and your users deserve the guarantees that 1.0+ provides.

Lockfiles

Version ranges specify what is acceptable. Lockfiles record what is actually installed. This distinction is critical for reproducible builds.

How Lockfiles Work

  1. You specify ranges in your package manifest (package.json, Cargo.toml, etc.)
  2. The package manager resolves those ranges to specific versions
  3. The resolved versions are recorded in a lockfile (package-lock.json, Cargo.lock, etc.)
  4. Future installs use the lockfile to reproduce the exact same dependency tree

Should You Commit the Lockfile?

Project Type Commit Lockfile? Why
Applications Yes Reproducible deployments
Libraries Depends npm: no. Rust: yes. Lockfiles of libraries are ignored by consumers.
Monorepos Yes Consistency across packages

Common Lockfile Issues

  • Merge conflicts: Lockfile conflicts are common in teams. Most package managers can regenerate the lockfile from the manifest — resolve by deleting the lockfile, keeping the manifest changes, and running install.
  • Drift: If you edit the manifest without running install, the lockfile becomes outdated. CI should fail on lockfile mismatch.
  • Different platforms: Some packages have platform-specific dependencies. Lockfiles generated on macOS may not work on Linux.

Publishing with SemVer

If you maintain a library, here is a practical workflow:

  1. Document your public API: Only what is documented and exported is considered part of the API for SemVer purposes. Internal implementation details can change freely.

  2. Use deprecation warnings before removing: Mark something as deprecated in a minor release. Remove it in the next major release. This gives consumers time to migrate.

  3. Write a changelog: Document what changed in each version. Group changes by type: Added, Changed, Deprecated, Removed, Fixed, Security. Our Changelog Formatter helps you structure entries consistently.

  4. Test against your version promise: If you claim a minor release, run the previous version’s test suite against the new version. If tests fail, you have a breaking change.

  5. Automate version bumps: Tools like semantic-release, changesets, and release-please can determine the version bump from commit messages.

Commit Message Convention

Many automation tools use conventional commits to determine version bumps:

feat: add user search endpoint        → minor bump
fix: correct timezone handling         → patch bump
feat!: change authentication flow      → major bump
BREAKING CHANGE: remove v1 API         → major bump

Common Mistakes

  1. Not bumping major for breaking changes: “It was a small change” is not a valid reason to avoid a major bump. If it breaks consumers, it is major.

  2. Bumping major for internal changes: Refactoring internals without changing the public API should be a patch, not a major release.

  3. Staying at 0.x indefinitely: If your library is used in production, commit to SemVer guarantees by releasing 1.0.0.

  4. Ignoring lockfiles: Not committing lockfiles leads to “works on my machine” problems.

  5. Using exact versions everywhere: Pinning every dependency to exact versions prevents you from getting bug fixes and security patches automatically.

Summary

Semantic versioning turns version numbers into a communication tool. MAJOR means breaking changes, MINOR means new features, and PATCH means bug fixes. Version ranges let package managers update dependencies safely within those guarantees, and lockfiles ensure reproducible builds. Follow SemVer honestly when publishing, and your consumers can update dependencies with confidence instead of fear.