When two words or word-parts meet, the last sound of the first and the first sound of the second often blend into something new. This blending is सन्धि (sandhi), "joining". विद्या + आलयः becomes विद्यालयः; नमः + ते becomes नमस्ते.
Every language does this in speech: English "do not" becomes "don't". What is special about Sanskrit is that the blending is also written, and written strictly by rule. That is why a line of a shloka looks like one long word. To read it, you must undo the sandhi, a step called सन्धि-विच्छेद (sandhi-vichchheda). Hindi keeps hundreds of Sanskrit sandhi words, so you know many results already: हिमालय, सूर्योदय, इत्यादि, स्वागत, सज्जन.
There are three families: vowel sandhi (स्वर), consonant sandhi (व्यञ्जन) and visarga sandhi (विसर्ग).
Vowel sandhi
1. दीर्घ (dirgha): like vowels make one long vowel
Rule
Example
Result
अ/आ + अ/आ = आ
विद्या + आलयः
विद्यालयः
अ/आ + अ/आ = आ
हिम + आलयः
हिमालयः
इ/ई + इ/ई = ई
कवि + इन्द्रः
कवीन्द्रः
उ/ऊ + उ/ऊ = ऊ
भानु + उदयः
भानूदयः
2. गुण (guna): अ or आ + a different vowel
Rule
Example
Result
अ/आ + इ/ई = ए
देव + इन्द्रः
देवेन्द्रः
अ/आ + उ/ऊ = ओ
सूर्य + उदयः
सूर्योदयः
अ/आ + उ/ऊ = ओ
महा + उत्सवः
महोत्सवः
अ/आ + ऋ = अर्
महा + ऋषिः
महर्षिः
3. वृद्धि (vriddhi): अ or आ + ए, ऐ, ओ, औ
Rule
Example
Result
अ/आ + ए/ऐ = ऐ
सदा + एव
सदैव
अ/आ + ए/ऐ = ऐ
एक + एकम्
एकैकम्
अ/आ + ओ/औ = औ
महा + औषधम्
महौषधम्
4. यण् (yan): इ, उ, ऋ before a different vowel
Rule
Example
Result
इ/ई + other vowel = य्
इति + आदि
इत्यादि
इ/ई + other vowel = य्
यदि + अपि
यद्यपि
उ/ऊ + other vowel = व्
सु + आगतम्
स्वागतम्
ऋ + other vowel = र्
पितृ + आज्ञा
पित्राज्ञा
5. अयादि (ayadi): ए, ऐ, ओ, औ before a vowel
Rule
Example
Result
ए + vowel = अय्
ने + अनम्
नयनम्
ऐ + vowel = आय्
नै + अकः
नायकः
ओ + vowel = अव्
पो + अनः
पवनः
औ + vowel = आव्
पौ + अकः
पावकः
Consonant sandhi: two common cases
A hard consonant softens before a soft sound
Example
Result
What happened
जगत् + ईशः
जगदीशः
त् became द् before a vowel
सत् + जनः
सज्जनः
त् became ज् before ज
वाक् + ईशः
वागीशः
क् became ग् before a vowel
उत् + नतिः
उन्नतिः
त् became न् before न
Visarga sandhi: three common cases
What the visarga (ः) turns into
Example
Result
What happened
नमः + ते
नमस्ते
ः became स् before त
मनः + रथः
मनोरथः
अः became ओ before a soft consonant
सः + अपि
सोऽपि
अः + अ became ओ, and the अ dropped (marked ऽ)
निः + चयः
निश्चयः
ः became श् before च
Undoing sandhi in a shloka
Take the first line of Gita 2.47: कर्मण्येवाधिकारस्ते. It is four words run together. Working backwards: कर्मणि + एव gave कर्मण्येव (yan sandhi: इ before ए became य्); एव + अधिकारः gave एवाधिकारः (dirgha: अ + अ = आ); and अधिकारः + ते gave अधिकारस्ते (visarga became स् before त). So the words are कर्मणि एव अधिकारः ते: "in action alone [is] the right of you".
How to learn sandhi
Start with the five vowel sandhis; they account for most of what you will meet.
For each rule, learn one example you already know from Hindi: विद्यालय, सूर्योदय, सदैव, इत्यादि, नयन.
Practise in both directions: join given pairs, and split given words.
When you read a shloka, mark every ऽ, every long vowel in the middle of a compound and every य् or व् before a vowel: these are the usual signs of a sandhi.
This page gives the main rules in their simplest form. Each rule has exceptions and finer points, which are set out in full in any standard Sanskrit grammar.