Elevation gain is calculated by summing up all gains in an activity, where a gain is defined as the difference between a low point and a high point. We detect peaks to determine high points and a gain must exceed a threshold in order to be counted. The elevation data used for calculating gain is smoothed before elevation gain is calculated in order to reduce noise. If you are riding or running in a very flat area, and none of the individual climbs on your activity exceed that threshold, it is possible that Strava will list a total elevation gain of 0ft, even if the elevation profile is not totally flat. This is an unfortunate side effect of the thresholds necessary to reduce noise on the majority of Strava activities.
We ignore elevation data from devices without a barometric altimeter (such as the Garmin Edge 200, most Garmin Forerunner models, the iPhone, and Android devices) and instead determine elevation by comparing your data to a set of elevation databases. The smoothing applied to data that has been looked up is slightly higher than that applied to data from barometric altimeters.
For more information on elevation on Strava, see the article on Elevation Correction for your Activity.