All major keys can be summarized in the following diagram known as the Cycle of Fifths (or the Cycle of Fourths).
If you start at the top of the cycle, C, and go in a clockwise direction, each new key and each new sharp is a fifth higher than the previous key or sharp. The key of F# contains six sharps. After F#, the next logical key would be C# (containing seven sharps). However, this is not practical, and rather than using the key of C#, you would use the enharmonic name for this key, i.e., Db (which contains five flats).
If you start at the top of the cycle, C, and go in a counter clockwise direction, each new key and each new flat is a fourth higher than the previous key or flat. The key of Gb contains six flats. After Gb, the next logical key would be Cb (containing seven flats). However, this is not practical, and rather than using the key of Cb, you would use the enharmonic name for this key, i.e., B (which contains five sharps).