How is it decided when certain intervals are flat or sharp...
For instance, a flat five could be a sharp 4, or flat 6 could be a sharp 5 etc...
It goes together with notation (letters) and the original way that majors and perfects were determined. Everything goes out from there on the naming side. As a quick review:
1. The names of intervals are based on the major scale, and the distance from the Tonic. This is easiest seen in C major, and the white keys on the piano give you an actual map:
CD - M2 (major 2)
CE - M3
CF - P4 (perfect 4)
CG - P5
CA - M6
CB - M7
Whether it is 2, 3, 4, 5, 6, 7 (2nd, 3rd, 4th etc.) comes from the number of notes involved. C to D = 2 notes. C to E (C,D,E) involves 3 notes, etc.
2 a) If the top note is one semitone lower (flatted) for a major interval, it becomes minor. So if CE = M3, then CEb = m3 (minor 3). etc. If the top note of a perfect interval is one semitone lower, it becomes diminished. So if CG = P5, then CGb = b5. There's your "flat 5".
2 b) If the top note of a major interval is two semitones lower, (or if the top note of a minor interval is one semitone lower - same thing), you get a diminished interval. If CA = M6, then CAb = m6, and CAbb (same as CG on piano) is dim6. You don't usually lower a Perfect interval by two semitones.
2 c) If the top note of a major interval is one semitone higher ("sharped") then it is an augmented interval. Thus if CA = M6, then CA# = aug6.
To work in this manner with an interval starting on any other note, you imagine the major scale starting on that note. There are also other ways to get there.
All this has to do with how things are named letter-wise, when the music is written. If you play CEb on the piano, and then play CD# on the piano, you will hear the same sound and press down the same keys. That actual distance between the the piano keys will be exactly the same.
So your sharp 4 ........ that's an augmented 4, or a P4 that has been "sharped" or made bigger by one semitone. If P4 is CF, then "sharp 4" is CF#.
Your flat 5 .... that's a diminished 5, or a P5 that has been lowered by a semitone. If P5 is CG, then "flat 5" is CGb. If you play CF# and then CGb you get the same sound and play the same piano keys. This gives you the famous "tritone.
Your "flat 6" is what you get when you "flat" an M6 ..... CA becomes CAb (also an m6).
Your "sharp 5" is what you get when you "sharp" a P5 .... CG becomes CG# (also an aug5).
Again, if you play CAb and then CG#, you hear the same sound, and press the same piano keys.
The reason for using different choices such as CAb vs. CG#, or CD# vs. CEb has to do with "grammar rules" in music.