The circle of fifths
Arrange the twelve keys so each step clockwise is a perfect fifth up, and a pattern appears: every step clockwise adds one sharp to the key signature, and every step anticlockwise adds one flat.
Why the bottom key has two names
Start at C, at the top, with an empty signature. Walk clockwise and the sharps pile up one at a time: G has one, D has two, and by B you are at five. Walk the other way and the flats do the same: F has one, Bb two, and Db five. The two walks meet at the bottom of the circle, six steps from C in either direction, and that meeting point is one sound with two perfectly correct spellings: F# major, written with six sharps, or Gb major, written with six flats.
Neither spelling escapes an awkward note. A major scale must use each letter name exactly once, so F# major needs its seventh degree written as E# (the note a piano player would call F), and Gb major needs its fourth written as Cb (the note a piano player would call B). Which spelling you pick is habit and context: guitarists and sharp-side instruments tend to say F#, flat-side instruments and many pianists say Gb. This site writes F# by default, and the key wheel on the scale and chord pages has a small toggle if you would rather see Gb.
The two signatures, side by side
The same major scale, once in each spelling - six sharps on the left, six flats on the right, the awkward note sitting in plain sight in both.