customs and immigration – Can I enter Spain few days before my student visa expires?

Your visa is still valid for entry until the date of expiry.

If your visa is a short-term one for studies under 90 days for example, then it would be hard to justify your entry since you will have to leave Spain before the visa expires.

Assuming your intended stay (i.e. time of studies left) is over 6 months though, you would have obtained a category D visa (see the letter on your visa) and you will need to apply for a residence permit at the local ComisarĂ­a. You should do this as soon as possible before your visa actually expires.

From what I heard, the appointment slots are scarce due to Covid, but you can make an appointment online beforehand if you know your arrival date and has a place to live ready.

The residence permit will be your status document in Spain (and for entering/exiting the Schengen area).

Note that without a valid visa or residence permit you will not be allowed to exit Spanish territories to e.g. visit other Schengen countries, even if your presence in Spain is tolerated when your application is under processing.