Only legal residence in Spain counts. Your residence card (TIE), or the decision granting it, states whether you hold a residencia, which counts, or an estancia such as a student stay, which does not.