In the United States, cities and counties are the creations of state or territorial law, so you'll find a lot of different variations. Using California as an example, the counties are the first-level political subdivision, dividing every bit of land in the state into 58 pieces, some smaller and some bigger. Exclusively within each county, a city can be incorporated by the will of the people living there, either as a general law city or a charter city. The former uses some default rules prescribed by the state (usually suitable for small towns, which California law still calls a "city") and the latter being a mini constitution that allows creative municipal administration (eg "strong mayor" systems).
Incorporating a city removes the power and responsibility from the county to manage that territory and its affairs, giving that to the city government. It is a specific rule in California that no city can span two counties: hence adjacent cities like Sacramento and West Sacramento, that are in different counties.
Compare this system to Louisiana, which uses county-like parishes. Or to New York City, which is one big city made from five counties, each being the same territory as the five constituent boroughs of the city. Oh, and California has one "consolidated city and county" in the form of San Francisco, where the city expanded to include all land in the county, so the difference was meaningless and they merged the two.
So while counties are consistent in covering all the land in a state, cities don't necessarily follow consistent rules or reasons. More often, they follow population patterns (sometimes gerrymandered to include prison populations, for example) or to grab natural resources (eg Sacramento River waterfront).
Edit: I should mention that the smallest "towns" in California basically exist in name only, being Census Designated Places (CDPs) of the county. They have only their normal county representative, although CDPs tend to also have a county-level committee made of locals to advocate for their town, in front of the county Board of Supervisors.