For good results, a screw should ideally pass 2/3rd of its length deep into the stud. This also depends on the strength required and the thickness of the stud.