There is no dividing line. Cities are bigger than towns, but many places can be called both. In some countries 'city' is an official title. For example, here in Britain, traditionally it's a city if it has a cathedral, but for the Queen's Jubilee some eight or ten towns have just been promoted to city. This doesn't change how we think of them: we can still call them town or city.
In Britain, "city" is used for a place with a city charter from the monarch, and sometimes, unofficially, for a place with a (Protestant) cathedral, although I think this latter use is now unusual (is there anyone from Rochester or Southwell who would care to respond?). It would be unusual to call anywhere else a city, whatever its size. Reading (population 348,000) is not a city.
Very occasionally, the word "town" reflects having a charter, and there are a handful of large villages which, never having had a charter, are not towns. Near where I used to live, there were Axbridge (population 2,000), which is a town, Cheddar (population 5,800), which is a village, and Wells (population 10,500), which is a city.
That's a royal charter detailing such things as arrangements for local government, the freedom of the residents and holding a regular market. There are actually many of them, so I wouldn't say "occasionally". I live in a town which is part of a city. The charter was granted a little over 700 years ago (1300, by Edward I)