This section explains distance calculations in SportTracks
Why does the distance in the device and SportTracks differ?
Short explanation: There are many ways to calculate GPS length, and a number of ways to compensate for GPS problems.
A GPS device can find the accuracy for each position and may try to compensate. Programs like ST reports the distance from the GPS position that device reports only.
The device have access to more information than it exports, for instance number of satellites, accuracy and in some situations activity types. Some devices like Garmin will use that information to estimate the distance it finds most likely. Therefore the distance can decrease if you turn around the way you came. The device believes that it has made a mistake. This compensation makes a difference mostly for slow activities, like running where the GPS accuracy error is large compared to the speed.
Some devices like some firmware versions of Garmin Edge 705 uses the speed/cadence sensor if available to calculate distance instead of using GPS.
Device distance does normally not include elevation, only using 2D calculations, as GPS elevation is very unreliable.
Include elevation (when it is correct) or not is not major difference. For instance a 10% hill (100m height difference in 1 km) will contribute 0.4% only to the distance.
Post processing programs like ST have different algorithms to calculate distance. The biggest difference is if elevation is included or not, but there are other differences too: The earth is not perfectly round, so the distance between two points is not always the same. These distance differences are small, most differences from one program to another is likely for other reasons like pause handling.
Some algorithms have filters as well to ignore bad points and to "smooth" the distance between the points.
The formula ST uses.
SportTracks always uses the GPS points to calculate the distance, never the distance the device reports. You can get ST report the distance for the complete activity by using manual calculations.
SportTracks uses this approach consistently for all devices, also those that report the detailed distance and to allow you to adjust the activity on the map. You can see and adjust incorrect points.
If the GPS track is very incorrect (for instance GPS on for an indoor activity), delete it. See here
Then, what is best?
There is no best algorithm. Device distance calculation may be better than programs like ST directly (for reasons explained above) but with ST you can see the points on the map and correct the data, so ST can be better.
If you zoom in to the map you will see that the GPS points differ from your actual route occasionally.
Since GPS accuracy is about 5m, it is not strange that the path is off, it is more amazing that the calculation is as accurate as it is, normally between 0,1% and 1%. A calibrated bike computer is better, but a foot pod can have larger error and treadmills often have an error like 5%. Controversy about GPS devices is often because the difference can be seen.