What is the logic behind dividing an octave into 22 notes?
To use Indian musical terminology, there are 7 swara, 12 swara-prakaar, and 22 shruti in an octave.
The seven swara in Indian music are the equivalents of the Western do re mi fa so la ti. In Indian music, they are called sa re ga ma pa dha ni.
Of the above, sa and pa are given special status as fixed notes in an octave and have only one variant each; re, ga, dha, and ni have natural and flat variants; and ma has natural and sharp variants. This gives us a total of 12 swara variants, or "swara-prakaar." So, when we use the word "notes" in an Indian context, we are usually referring to the 12 swara-prakaar.
For an elementary or intermediate-level understanding of Indian classical music, swara and swara-prakaar are all you need to know about. However, going back all the way to the Vedas (Chandogya Upanishad, 6-8th century BCE), many ancient Indian texts on music talk about an octave being divided into 22 shrutis.
What are these shrutis?
Understanding shrutis involves delving deeper into the physics and mathematics behind musical notes and their frequencies relative to the tonic.
To begin very simply, if you choose a particular frequency for the tonic (Sa), then the other 11 notes in the octave exist not at precise frequencies relative to the tonic, but in small bands of frequencies relative to the tonic. And the upper and lower bounds of each note's frequency band are taken as two distinct shrutis for that note because there is an audible difference in pitch between the two.
However, perhaps in an effort to stabilize the octave and keep the discrepancies from adding up, the frequencies of the the fifth note (Pa) and the octave (Sa') are set at fixed ratios to the tonic, at 1 : 1.5 : 2. The other 10 notes are allowed to exist in their respective frequency bands bound by the lower and higher shrutis for each note. This is what results in 22 shrutis in an octave.
How do we know that the notes exist in frequency bands rather than fixed frequencies relative to the tonic? The easiest way to know and perceive this is by playing the notes on a string. You can hear the different notes at different locations on the string, but each note can be played quite tunefully (consonantly) not just at a single, precise location, but within a small region of the string.
The presence of small bands of frequencies for each note can also be mathematically explained.
Throughout history, people have tried to understand and explain the physics and the mathematics behind musical notes in many different ways. There are different formulae that can be used to arrive at all the 12 notes in an octave from a single starting note.
For instance, if you have a length of string, it will produce a certain pitch when plucked. But plucking two-thirds of that string will produce a pitch that is exactly a fifth higher. So, if the whole string produces the tonic (Sa), two-thirds of it will produce the fifth note (Pa); i.e., you can derive the perfect fifth from the tonic. Now, if you use the perfect fifth as your new tonic, you can derive the perfect fifth of the perfect fifth, which is the major second of the next octave Re'(2'). And if you continue this way, you can discover all the 12 notes in an octave before arriving back at the starting note Sa(1). This is called the "circle of fifths," and the sequence of notes discovered in the circle of fifths is:
Sa(1) -> Pa(5) -> Re(2) -> Dha(6) -> Ga(3) -> Ni(7) -> Ma(#4) -> re(♭2) -> dha(♭6) -> ga(♭3) -> ni(♭7) -> ma(4) -> Sa(1)
A similar way of deriving all the notes is using the circle of fourths. The principle behind the circle of fourths is that if you have a length of string that produces a certain pitch when plucked, plucking three-fourths of that string will produce a pitch that is exactly a fourth higher. So, if the whole string produces the tonic (Sa), three-fourths of it will produce the fourth note (ma). The sequence of notes discovered using the circle of fourths is the exact reverse of that discovered using the circle of fifths:
Sa(1) -> ma(4) -> ni(♭7) -> ga(♭3) -> dha(♭6) -> re(♭2) -> Ma(#4) -> Ni(7) -> Ga(3) -> Dha(6) -> Re(2) -> Pa(5) -> Sa(1)
Similarly, if you pluck four-fifths of a string, it will produce the major third (Ga). However, there is no "circle of thirds," and only three notes in an octave can be discovered using this method: Sa(1) -> Ga(3) -> dha(♭6). But if you already know ma(4), you can additionally discover ma(4) -> Dha(6) -> re(♭2); if you already know Pa(5), you can additionally discover Pa(5) -> Ni (7) -> ga(♭3), and so on.
Having marked locations where each note can be played along a string, we can derive the relative frequency of each note to the tonic using the formula "f = 1/L" (where L is the relative length of the string required to produce that note). In this way, the location of musical notes along a string and their frequencies relative to the tonic can be discovered using a variety of methods.
The interesting thing to note here, though, is that the frequencies of the notes arrived at using the different relationships all differ, if only slightly, from each other. Here is a chart I made to show the frequencies arrived at using the circle of fourths vs. the circle of fifths.
This seems to be what gave rise to the idea that musical notes in an octave exist within a small band of frequencies rather than exact frequencies relative to the tonic, which then gave rise to the concept of having an upper and lower shruti for each note. However, to keep the octave stable, the frequencies of Sa(1), Pa(5), and Sa'(8) were fixed.
Musical systems around the world use different relative frequencies for different notes depending on their priorities and requirements. The equally tempered scale used in Western music, for instance, is a compromise necessitated by the use of keyboard instruments. By contrast, just intonation uses the simplest frequency ratios to the tonic possible in an effort to find the most consonant intervals.
The shruti frequencies chosen for the lower and upper bounds of each note in Indian music are based on Sa(1)-Pa(5), Sa(1)-ma(4), and Sa(1)-Ga(3) relationships between the notes as these are considered to be the most pleasing intervals. The chart below shows what relationships are used to arrive at the higher and lower shrutis for each note.
Different ragas use different shrutis for different notes, but within a raga, there is internal consistency and a logic to which set of shrutis is used (fascinating but complex subject that is a different discussion altogether).
The mathematical rationale behind having 22 shrutis was lost for many hundreds of years and is only now beginning to be rediscovered, but an innate understanding of the use of shrutis has remained alive and well in Indian classical music though the ages, handed down from one generation of musicians to another through the guru-sishya (oral) tradition of learning music.
Dr. Vidyadhar Oke's website www.22shruti.com has a great deal of useful information on this topic.
So while I really appreciate @Sadhana's answer, I'd also like to point out this article from Xenharmonikon, Tuning, Tonality, and 22-Tone Temperament written by Paul Erlich which approaches the shruti in a more analytic way, connecting modern JI music theory with (IIRC) the Natya Shastra (which I read in translation several years ago out of curiosity sparked by the paper). Beginning around page 17 of the linked PDF, he notes that the sruti is defined implicitly by the equivalences:
- 4 sruti = 9/8
- 3 sruti = 10/9
- 2 sruti = 16/15
from these, the rest of the scale degrees in the Natya Shastra are then defined, producing smaller sets of scale tones based on 22 srutis in an ocatve. Now, Erlich's main interest in the paper is not in the rendering of Indian classical music, but rather in the theoretical properties of 22 TET, especially in relationship to music from outside the western canon, but it really opened my eyes to the possibilities inherent in Just Intonation as well as seeing it's practical use in relationship to a music that I already liked rather a lot.