Short answer: fill A and B to compare, type a range to test A, and put one version per line to sort. The notes explain the edge that applies — a caret on a 0.x version, a prerelease, or build metadata.
Precedence, in one paragraph
Compare major, then minor, then patch as integers. A prerelease version is lower than its release, and prereleases compare identifier by identifier with numeric identifiers ordered numerically. Build metadata after + never affects ordering.
The two ranges people misread
^— allows changes that do not modify the left-most non-zero digit.^1.2.3is>=1.2.3 <2.0.0;^0.2.3is>=0.2.3 <0.3.0.~— allows patch-level changes when a minor is specified.~1.2.3is>=1.2.3 <1.3.0.
Auditing what a range actually resolves to? Read the lockfile with theJSON formatter, and compare two resolved versions side by side in the text diff.