There is a sense in which all music has underlying mathematics. There is also, however, a widespread perception that this mathematics is associated only with symphonic music, not with free-flowing, improvisational music such as jazz. It is our premise here that jazz has its own mathematics, which is just as fascinating as the mathematics of a Bach fugue. This underlies such musical fundamentals as the way in which note durations are expressed, the number of bars in a passage, and the actual notes, chords, and key signatures used. The differences between jazz and rock in these respects are also interesting; and jazz musicians have even been known to play sly mathematical games.