Compare Two Semver Versions — Which Is Newer?

Compare two semantic versions to determine which is newer. Learn the comparison algorithm for major, minor, patch, and pre-release components.

Version Comparison

Detailed Explanation

Comparing Two Semver Versions

Version comparison answers a simple question: given two versions, which one is newer? The SemVer specification defines a precise algorithm for this.

The Comparison Algorithm

Versions are compared component by component, left to right:

  1. Compare MAJOR — higher MAJOR wins
  2. If MAJOR is equal, compare MINOR — higher MINOR wins
  3. If MINOR is equal, compare PATCH — higher PATCH wins
  4. If PATCH is equal, compare pre-release identifiers (see below)
  5. Build metadata is always ignored

Examples

Version A Version B Result Deciding Factor
2.0.0 1.9.9 A > B MAJOR: 2 > 1
1.3.0 1.2.9 A > B MINOR: 3 > 2
1.2.4 1.2.3 A > B PATCH: 4 > 3
1.2.3 1.2.3 A = B All equal
1.2.3 1.2.3-alpha A > B Release > pre-release
1.2.3-beta 1.2.3-alpha A > B "beta" > "alpha" lexically
1.2.3+build.1 1.2.3+build.2 A = B Build metadata ignored

Pre-release Comparison

When both versions have pre-release identifiers and the same MAJOR.MINOR.PATCH:

  1. Split pre-release by dots into tokens
  2. Compare tokens left to right
  3. Numeric tokens are compared as integers (2 < 11)
  4. String tokens are compared lexically ("alpha" < "beta")
  5. Numeric tokens have lower precedence than string tokens
  6. Fewer tokens means lower precedence (if prefix matches)

Practical Comparison

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

Using the Compare Tab

Enter two versions in the Compare tab to instantly see:

  • Which version is newer
  • The component-by-component breakdown
  • The difference in major, minor, and patch numbers

Sorting Multiple Versions

When you have a list of versions, comparison is applied pairwise to produce a sorted order. The result follows the same rules — major takes priority, then minor, then patch, then pre-release.

Use Case

Determining whether an available update is newer than your currently installed version, building version-aware deployment pipelines, or sorting release lists in changelogs and dashboards.

Try It — Semver Calculator

Open full tool