The #S_N2# (substitution, nucleophilic, bimolecular) mechanism is generally favored when the substrate which it attacks has minimal steric hinderance, i.e. reactivity increases #cancel3^o<2^o<1^o< Me #. Note that #Me# represents a methyl carbon and tertiary substrates (carbon atoms specifically) will not react via an #S_N2# mechanism due to steric hinderance. Also note that steric hinderance affects nucleophilicity more than basicity, where (simply put) a nucleophile attacks a substrate and forms a bond to it, whereas a base abstracts a proton from the substrate. Note that all bases are nuelcophiles and vice versa, it is whether they bond to the substrate or abstract a proton from it that governs whether it acts as a base or nucleophile.
Another very important factor is the type of nucleophile: strong or weak. #S_N2# mechanisms are favored when a strong nucleophile/base is involved. For example, #NaOCH_3#.
Next, #S_N2# mechanisms favor a polar aprotic solvent, such as DMSO. Polar aprotic solvents have strong dipole moments to enhance solubility and have no protic protons (as in alcohols or amines, for example) which will form hydrogen bonds with anions. Generally, #S_N2# mechanisms can occur in a polar protic solvent, it just typically leads to a much slower reaction rate, sometimes by a factor of #1000# or more.