This may at first sound strange, but the number of semitones is determined by the name of the interval but not the other way around. In non-equal-temperament, there may be no enharmonics, D# may (or may not) be identical to Eb (they will be close though.)
In equal temperament, (or by counting piano keys), each semitone is considered to have the same ratio. Often, in some post-Romantic music theory, notes and intervals are identified by semitone count. However, in most Common Practice Period music (and most earlier and lots of modern music), each key is represented by 7 letters (A,B,C,D,E,F,G) and intervals main name are determined by counting this way. So A to C and C to E are both called a third; as the two intervals have different semitone counts, A-C is termed a minor third and C-E is termed a major third.
As music was (and mostly still is) written, naming intervals by note name (rather than semitone difference) carries more information. For example, in the key of C, the interval D-F is a minor third and D-F# is a major third; this naming indicates that for the purposes of the piece being considered, the composer (and performers) should think of F# as a modified F rather than an independent object. (Of course, this is a convention, in the key of D, F# would be the "normal" note and F the modified note.)
One point is that in general (everything is always "in general" or "usually") sharpened notes tend to be followed by a higher pitched note and flattened notes tend to be followed by lower tones. Note that in the same piece, things like dm-G-C and D-G-C chords (ii-V-I and II-V-I or V/V-V-I in Roman Numerals) may both be used to end phrases. Root movements are the same, the only difference is that the D chord appears in two forms. One could even have a d-diminished chord consisting of the notes D,F, and Ab . All these are basically a type of D chord, a G chord, then a C chord even though the intervals may be different.
Another historical relic is that in non-equal-temperament (for example "just tuning"), the ratio of D to C is 9/8 and of E to D is 10/9; this causes the just third C to E to have the ratio 5/4. Equal size whole tones give the C to E ratio as either 81/64 or 100/81. (Thus one has the choice of which intervals should be out-of-tune.)
Music is named because composers write as though intervals may have different sized, but the compromise of equal-temperament means that one is always off (but by the same amount no matter what key.)