I have a return flight to India from Madrid, with a two-day layover in Amsterdam. I have got a single-entry visa. So when I leave Madrid, they will do the immigration checks and they might stamp on the passport that this tourist has departed from Schengen. However I need to get out of the airport in Amsterdam to travel. Can I do that with a single-entry visa?
If you have a flight from Madrid to Amsterdam, there's no way you will get an exit stamp. This means you will still be in Schengen when arriving to Amsterdam, and can go out as you please. You will only leave Schengen when boarding for India.
Exit checks will be done in Amsterdam. Your Madrid-Amsterdam flight will be a domestic flight and you will not pass through immigration. You don't need a transit visa for that flight.