Mechanism for the formation of a mesylate:
The reaction mechanism shown in figure involves the alcohol oxygen acting like a nucleophilic center and substituting the chloride ion from the sulfonate. After that the base eliminates a proton from the intermediate to provide the sulfonate product. Neither of these steps influences the stereochemistry of the alcohol carbon and thus the stereo- chemistry of chiral alcohols is retained.

Figure: Mechanism for the formation of a mesylate.
The tosylate and mesylate groups are excellent leaving groups and can be viewed as the equivalent of a halide. Hence mesylates and tosylates can go through the SN2 reaction in the same way as alkyl halides.

Figure: Nucleophilic substitution of a tosylate.