DC Rainmaker answered this on a podcast some time ago. GPS is terrible at working out elevation. To work it out you have to put a point on a map and then get the elevation from that map, problem is GPS that we use isn't accurate to the inch so you could get a read of elevatio from a point a few metres away. Imagine you are riding on a road with a sharp drop to your left and your GPS marks there - the elevation will be well wrong.
Strava interprets the GPS data from Garmin and passes it through its own algorithms. Also the maps they use might not exactly be the same, so you also get discrepancies here.
If you have a Garmin with an altimeter it will use that data source rather than trying to work out your elevation itself. I've found the altimeters from Garmin to be pretty accurate, give or take +/- 10%.
An interesting point re Strava. I plotted a 75 mile route on their route planner and the stated elevation gain was 2250 (from memory). I did the ride with 2 mates all using different Garmins (a 200 and a 25). My ride was recorded on a 520 with altimeter. Their elevation after uploading to a Strava was 1600 and 1750. Mine was 2150. A big difference but closer to what Strava said it would be. Interestingly the Garmin 200 stated a similar elevation before the rode was uploaded to Strava.
It's not that Garmins or altimeters are rubbish, it's the different ways Garmin / Strava interpret your data PLUS a GPS is pretty accurate on the horizontal but not the vertical.
As long as you are using the same device every ride at least your data will be consistent.
(I listened to the podcast about 6 months ago so hope I have explained his answer clearly).