You can leave the airport during a layover only if you are allowed to enter the country where you are connecting. That means clearing passport control and meeting that country’s normal entry rules, including a visa or travel authorization if your nationality requires one, and then going back through security before your onward flight.
Visa-free transit and airport transit visas usually cover only the airport’s international transit area. Germany’s Federal Foreign Office, for example, says an airport transit visa does not let you leave that area, not even to collect luggage, and that travelers who must leave it, change terminals, re-check bags, or stay more than 24 hours need a regular Schengen visa instead. Leave plenty of time for immigration and security, and ask your airline whether your checked bags go through to your final destination.
Source: German Federal Foreign Office (Embassy Port of Spain), “Airport Transit Visa”
Image: Changi Airport transit area signs by Akinori Takemoto, CC BY-SA 3.0, via Wikimedia Commons.