Here is the situation. I'm Belgian but this is about my American boyfriend. He entered Schengen on July 16, 2018 - flew into Amsterdam airport where his passport got stamped, then took a train to Belgium, where he stayed. On October 5, he obtained a student visa for Spain (type D), valid until May 31st, 2019.
He hasn't left Schengen since he arrived on July 16 and mostly stayed in Belgium (a couple of days in Germany and Czech Republic in August, a week in Spain late September) and then in Spain starting early October until late December. He came to Belgium for the Christmas holidays and only returned to Spain for one day after that. He is currently in Belgium.
Can he legally stay in Belgium until May 31st with his Spanish visa? I found information on this only being possible for 90 days, but is this actually accurate? I don't understand how this would comply with the free travel between Schengen countries and the absence of border checks.
On June 1st, does he have another 90 days in Schengen? I read everywhere that days spent under a visa are not taken into account, but what exactly does this mean? Are they to be considered like days not spent in the Schengen zone? Or are they not counted at all? Implying in the latter case that on June 1st he would only have 9 days left to spend in Schengen? (because he spent 81 days in Schengen between arriving on July 16 and getting his Spanish visa on October 5)