If each segment has a unique flight number, then you get mileage for each segment, as you did in your case. If each segment (DEN-SFO and SFO-IAD) had the same flight number, though, you would have only gotten mileage for the distance between the beginning and end cities - in other words, the mileage from DEN to IAD.
Mike