Substitution and elimination reactions have always competition. There are certain criteria which are useful to understand which will be more favoured, elimination or substitution.
Primary alkyl halides generally have substitution reaction. Tertiary alkyl halides are favoured by mainly elimination reaction. Secondary alkyl halides can react via substitution or elimination depending on the circumstances.
On the other hand solvent also plays an important role. Water favours substitution reaction whereas alcohol encourages elimination reaction.
Temperature is also a factor. Higher temperature will favour elimination reaction.