Distance is calculated from your 2nd waypoint along the flight path to each subsequent waypoint ending with your penultimate (2nd-to-last) waypoint. This is the race distance for 1 lap and is multiplied by the number of laps on the race to determine the actual race distance.
Each race can have any number of laps and the race distance will be calculated for all laps. All flight plans include a starting and ending waypoint, typically an airfield at either end. Flight plans created specifically for racing often have the starting and ending waypoints in flight cruise, but regardless the first and last waypoints are not considered a part of the race course. Only User type waypoints are counted for sector times. Airports can be included on racing flight plans, but sector times will not be counted when the Airport is passed/reached. If you want to record times at interim airports, create User type waypoints on the runways/parking/gates you want to record sector times for.
Only laps with no missed waypoints will be counted as official and only races with the required number of completed laps will be included in the leaderboards. So if a race has 3 laps and you miss a waypoint on your 3rd lap, your lap times will not be considered in the official race results and your race time will not show on the Leaderboard.
You can always see your own completed laps whether you missed any waypoints or not by logging into simflightplan.com. Incomplete races will not be included in race results but any valid laps (laps without missed waypoints) will be considered for best laps. So you may see your lap listed in the top 3 race laps at the top of the Laps page even though you didn’t complete all laps for the race and therefore doesn’t appear on the Leaderboard. You can of course, try any race as many times as you want, and all completed laps (with or without missed waypoints) will be recorded and displayed for you. If you crash or simply want to stop, just close Cockpit Map and any previously completed laps will be saved, but the incomplete lap will be discarded.