I was just looking at scales and trying to memorise how many sharps and flats each key has.

In short: count the sharps. multiply by 7. divide by 12. add the remainder in semi-tones to C. that’s the key. For flats, subtract the remainder from C.

The usual way to do this is to use the “circle of fifths” diagram:

In that, you count clockwise from C to find keys with sharps in them, and anti-clockwise for flats.

For example:

This key has 3 sharps, so you count three keys to the right of C, and that makes it A major.

If you want the minor key, then do the same, but then subtract 3 semi-tones from it, and you get F#m.

Now, what if you’ve a crap memory like me? There’s no bloody way I could remember a complex diagram like that.

Simple – let’s look at another variant of the diagram:

In this diagram, in order to figure out the key, you follow the lines; anti-clockwise for sharps, and clockwise for flats. For a key with 3 sharps, you start on C, then follow the lines 3 times, through G and D to A.

Yes, it’s another diagram, but look at the lines – they’re perfectly regular, which means that a formula can be built from it.

The formula is simply this: sharps * 7 % 12. Then add the result in semi-tones to C and you get the answer.

Examples:

C | C# D♭ |
D | D# E♭ |
E | F | F# G♭ |
G | G# A♭ |
A | A# B♭ |
B | C |

0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |

- 1 sharp: 1*7=7. 7%12=7. 7 is G
- 2 sharps: 2*7=14. 14%12=2. 2 is D
- 3 sharps: 3*7=21. 21%12=9. 9 is A

For flats, subtract the result from 12 to get the answer:

- 1 flat: 1*7=7. 7%12=7. 12-7=5. 5 is F
- 2 flats: 2*7=14. 14%12=2. 12-2=10. 10 is B♭
- 3 flats: 3*7=21. 21%12=9. 12-9=3. 3 is E♭