The determination of an ecosystem isn't a clear line as the border of countries, but usually a gradual change of the environment characteristics (such as temperature, humidity, altitude and latitude) that is also accompanied by a change in the communities of living organisms that live there.
A clear end of an ecosystem is for example a shore, where a terrestrial ecosystem ends and an aquatic one begins; while a more gradual change of ecosystems can happen when the altitude increases, and probably the humidity and temperature decrease at the same time, causing different organisms to be more adapted to those conditions.