When someone says that he is going to a city or from a city, obviously, the name of the city should be in the Genitive case:
W poniedziałek jadę do Gdańska.
Moja mama leci do Madrytu.
Pociąg z Poznania do Amsterdamu odjeżdża o 15.15.
So you have the following forms: Gdańska, Madrytu, Poznania, Amsterdamu.
As we know, the genitive singular masculine endings are -a or -u.
With that in mind, look again at the examples given above. Do you see the connection between cities and the Genetive form?
Masz rację: Madryt(u) i Amsterdam(u) to miasta leżące poza granicami Polski, a Gdańsk(a) i Poznani(a) to miasta w Polsce.
You’re right: Madryt(-u) and Amsterdam(-u) are not Polish cities while Gdańsk(-a) and Poznani(-a) are both cities in Poland. In most cases, so when you think about Polish city, and the city has a masculine name, it will take the genitive ending -a:
do Szczecina
z Koszalina
do Wrocławia
z Lublina
and so on…
Foreign cities usually take the form -u :
do Pekinu
z Sztokholmu
do Dublinu
z Waszyngtonu
do Nowego Jorku
z Londynu
and so on…
From this rule there are few exceptions. We say:
do Paryża,
do Berlina,
do Wiednia
Do you know any Polish city in masculine, which takes the form -u of the genitive?
If so, write in the comments.