I originally received my Schengen Visa for my upcoming 11 days trip to Italy, however I have 6 hours layover in Madrid and was planning to checkout madrid during that time. I just realized that they only granted me single entry and now I am worried that if I visit Madrid during my transit, Italian immigration can resufe my entry when i get there.
As a general principle, the entire Schengen area is considered one country for immigration purposes. This means in particular that a flight between two Schengen countries (in your case, Spain and Italy) is considered a domestic flight and there is no immigration control before or after the flight.
Hence, in your case you will enter the Schengen area and pass immigration when you arrive in Madrid, regardless of whether you exit the airport or not. There will be no immigration control in Italy at all.