What is Semantic Versioning?

In short
Semantic Versioning is a naming scheme for software releases built from three numbers, MAJOR.MINOR.PATCH. Each number changes in a specific way, so a version number tells you whether an update is a bug fix, a new feature, or a breaking change.
The three numbers
A semantic version looks like 2.4.1. The first number is the MAJOR version, the second is the MINOR version, and the third is the PATCH version. Each one has a job.
Increase the PATCH number when you fix bugs and keep everything backward compatible. Increase the MINOR number when you add new features that still work with older code. Increase the MAJOR number when you make changes that break existing users.
When you raise a higher number, the lower numbers reset to zero. So a jump from 2.4.1 to 3.0.0 signals a breaking change, and a jump from 2.4.1 to 2.5.0 signals new features.
Why a public API matters
The scheme only works if you know what counts as your public API. That is the set of functions, commands, or behaviors that other people rely on. It can live in the code itself or in documentation. The specification says this API should be clear and precise, because you cannot tell whether a change breaks users if nobody agreed on what users depend on.
The idea behind the scheme is to solve a problem called dependency hell. This is the mess that appears when many packages depend on each other and one upgrade forces a chain of other upgrades, or breaks something silently. Clear version numbers give the people who use your software a way to state which updates they can accept safely.
How it works in practice
The rules are simple. Once a version is released, its contents must never change. Any fix or change needs a new version number. Each number must increase numerically, so 1.9.0 is followed by 1.10.0, not by 1.9.10 style guesses.
Versions starting with 0 are a special case. The specification says major version zero is for initial development. Anything may change at any time, and the API should not be treated as stable. Version 1.0.0 is the point where the public API is officially defined. After that, the normal rules apply.
A simple example
Imagine a library called Firetruck that depends on another package called Ladder. Firetruck uses a feature that first appeared in Ladder 3.1.0. A safe way to write this dependency is to accept any version from 3.1.0 up to, but not including, 4.0.0.
Now suppose Ladder releases 3.1.1 with a bug fix and 3.2.0 with new features. Both fall inside the accepted range, and because the maintainer followed the rules, Firetruck should keep working. A release of 4.0.0 would fall outside the range, which warns you that it may contain breaking changes.
Ladder 3.1.0 first release with the feature Firetruck needs
Ladder 3.1.1 bug fix, safe to take
Ladder 3.2.0 new features, backward compatible
Ladder 4.0.0 breaking changes, review before upgrading
The rules describe what a version number should mean. They do not replace testing. Even a correct patch can expose a surprise, so it is still wise to run your tests after an upgrade.
Pre-release and build labels
The specification allows extra labels. A pre-release label such as 1.0.0-alpha or 1.0.0-rc.1 marks a version that is not yet stable and may not meet the compatibility promises of its normal version. Pre-release versions sort before the normal version, so 1.0.0-rc.1 comes before 1.0.0.
A build label, added with a plus sign such as 1.0.0+20130313144700, carries extra information like a build date. Tools ignore it when deciding which version is newer.
Common mistakes
A common mistake is treating a breaking change as a minor update. Users then upgrade within a range they trust and their software fails. Another mistake is changing a released version without publishing a new number. The specification says this must never happen.
Teams also often skip defining the public API. Without that definition, nobody can decide whether a change is breaking. Write down what users can rely on before you start counting version numbers.
Alternatives
Some projects use calendar-based versions, such as a year and month, instead of counting breaking changes. These work well for software that changes on a fixed schedule, but they do not tell users whether an update will break their code. If you want readers to understand the meaning of a release from its number alone, semantic versioning is the more direct choice.
FAQ
Do I have to use semantic versioning for every project?
No, it is a convention, not a law. It is most useful for libraries and packages that other projects depend on. Small internal tools may not need it.
What happens if I release a breaking change as a minor version?
Users who trusted the minor version range may get code that stops working after an upgrade. That is why the rules ask you to raise the major number for any incompatible change to the public API.
Is version 0.x.y covered by the same rules?
Not fully. The specification says major version zero is for initial development, where anything may change at any time. The stability promises start with version 1.0.0.
What is the difference between a pre-release and a build label?
A pre-release label, such as -beta, marks a version that is not yet stable and sorts before the normal release. A build label, added with a plus sign, adds extra information and is ignored when comparing versions.
Sources
This page is based on the official documentation below. Read it for full detail.
Semantic versioning — official documentation ↗