RPM packages have a specific format: `[$epoch:]$name-$version-$release.$arch`
The `$epoch` is an integer that can be easily compared, there are packages that do not use this and it is just omitted. `$name` is simply a string that should not change between versions. `$version` is a version string in a format which can be parsed and compared (usually integers separated by periods). `$release` is a string that normally begins with an integer, but can also contain information about what distribution it was built for.
If all of `$epoch`, `$name`, and `$verion` are the same, then `$release` is compared to determine if it is an update. If the `$version`s are different, they are parsed and the higher one is the update. If the `$epoch` is different, the higher one is the update.
The source code for RPM update comparisons I believe can be found here in the functions `parseEVR` and `rpmdsCompareEVR`.