In my experience, the formal definition of a city vs a town would depend on the how that country's government defines a "city" by population. So, in a smaller country, something could be referred to a city that perhaps would be a town in a bigger country. In my country, Statistics New Zealand defines a city from the Local Government Act, which today classes a place of dwelling as a city if it has a minimum population of 50,000, is predominantly urban in character, is a distinct entity, and is a major centre of activity within the region.
In common use, we can still refer to a city as "a town" if we are speaking casually. Eg "Not in my town!" "I need to get out of town" "He's out of town". Town in casual speech is the distinction between town and country, urban and rural. However, if you truly lived on a farm in the middle of nowhere, to refer to "town" would be whatever has a few shops and a cluster of houses!
On the other hand, if you actually live in a city, there are still blurred lines of usage! You could still say "Shall we go into the city?" meaning, although I live within the city boundary, I want to go right into the heart of it, otherwise known as "downtown" or "inner city" or "city centre". You can also swap the word town and city easily, saying "I live on the other side of town" or "I live on the other side of the city". Using the word "town" is more casual in this context.