What Doug said
The first use of 7ths was on the Dominant (or 5th) scale degree (hence the name Dominant 7th)
G7 (GBDF) is the Dominant 7th of C major and when you see it laid out in that context (over 2 octaves), then the 7th isn't flat but natural (i.e., belongs to the scale).
C D E F
G A
B C
D E
F G A B C
Counting G as 1, B = 3 D = 5 and F= 7
in that context
But if you think of G7 built on scale degree 1 of the G major scale
G A
B C
D E
F# G instead of scale degree 5 of the C major scale, then in that context the 7th note is F# - to make the 7th F we have to "flat" the F# - so the chord
formula is 1 3 5 b7.
Now all chords are referred to in relation to the FIRST degree of the scale for convenience and consistency.