In most cases, you'll go through customs and immigration after your flight first arrives in a new country, but there are exceptions. For example, some countries have mutual agreements intended to help speed travelers through the process, so you may go through customs and immigration before you board.
Can you leave airport during international layover?
Leaving the airport during an international layover is possible but can be more complicated. Depending on the layover country, layover flight rules may require you to secure a visa before being allowed to venture out of the airport.