Why are there 12 notes, and why do D sharp and E flat share one key?
Twelve equal divisions make the octave close cleanly on near-pure fifths; enharmonic names like D#/Eb are one sound spelled per context.
Western music chose 12 because it is the smallest slicing of the octave where the most important harmony, the perfect fifth, comes out almost perfectly in tune in every key.
D sharp and E flat are the same piano key with two names. Which name you use depends on context, like the words "flour" and "flower" sounding alike but meaning differently.
Stack pure fifths and you almost, but not quite, land back on your starting note after 12 steps. Equal temperament splits that tiny error evenly across all 12 semitones, making every key equally usable at the cost of perfectly pure intervals: the great compromise behind the modern keyboard.
Only 7 letters exist because the staff and key system grew from 7-note scales; the 5 in-between notes borrow neighbors’ names with sharps and flats. That also explains the missing black keys: B-C and E-F are already a semitone apart inside the major pattern.
Spelling matters for grammar: in the key of B major the note is D sharp (its 3rd), while in E flat minor the same sound is E flat’s tonic-flat spelling. Right pitch, context-dependent name.
The mathematics: a pure fifth is ratio 3:2, and (3/2)^12 is close to 2^7 but overshoots by about 1.4 percent, the Pythagorean comma. Twelve-tone equal temperament defines the semitone as the twelfth root of 2, putting the fifth at 700 cents versus the pure 702: imperceptible to most ears, and the circle of fifths closes.
Other divisions exist and are used: 19, 24 (quarter tones) and 31 equal divisions, plus just-intonation systems; 12 won historically for keyboard practicality and the quality of its fifths and fourths.
Enharmonic spelling carries real information in notation: intervals are named by letters (C to D# is an augmented 2nd; C to Eb a minor 3rd), and correct spelling shows the note’s function and resolution direction even though the sound is identical in equal temperament.