Eruvin, Chapter Five, Mishnah 8. At the end of the previous Mishnah we established the rule that if a person measures two thousand amos from his eruv, and within that two thousand amah boundary there is an entire city or town, and the measurement ends beyond that town - the town is not counted in the measurement and does not use up any of the two thousand amos. For example: a person standing one thousand amos to the east of a town, whose two thousand amah boundary to the west includes the town - the town is not figured into the calculation, and therefore after the one thousand amos up to the town he still has another thousand amos beyond it.
This rule, however, applies specifically when the two thousand amos end after the city. If they end in the middle of the city, the person may walk only up to that point, even within the city. The only exception, as Tosafos writes, is someone who actually slept in the city - he may walk throughout the entire area of the city, but not beyond it.
The case in our Mishnah - two neighboring towns:
Mishnah 8 discusses two cities, a large one and a small one, that are located within two thousand amos of each other: when the small city measures two thousand amos from the edge of its boundary, its measurement ends in the middle of the large city; whereas the large city, since its measurement includes the entire small city, its two thousand amos extend beyond the small city. This is exactly the case that was discussed in the previous Mishnah.
The words of the Mishnah:
"Anshei ir gedolah mehalchin es kol ir ketanah" - the residents of the large city may walk the entire length of the small city, for since their two thousand amos end beyond the small city, the small city takes up no space at all in the calculation of the two thousand amos, and they may walk even beyond it.
"V'ein anshei ir ketanah mehalchin es kol ir gedolah" - the residents of the small city, whose two thousand amos end in the middle of the large city, may not walk through all of it, for the reasons explained in the previous Mishnah.
The Gemara's completion of the Mishnah's wording:
The Gemara clarifies that words are missing in this Mishnah, and it should be read as follows: "In what case does this apply? To one who measures the two thousand amos of the Shabbos boundary from his own city and reaches another city. But one who places his eruv in another city - the residents of a large city may walk the entire small city, and the residents of a small city may walk the entire large city". That is, the distinction between the large city and the small city was stated regarding one who measures the Shabbos boundary from his own city and reached another city; but one who places his eruv in another city - that city becomes his new city.
And the Mishnah continues: How so? One who was in a large city and placed his eruv in a small city, or was in a small city and placed his eruv in a large city - he may walk the entire city and two thousand amos outside of it.
A dissenting opinion:
There is, however, one who disagrees and holds that one who places his eruv in another city does not thereby gain that the entire city be considered his city, such that he need not include it in the calculation of the two thousand amos. In his view, he has only two thousand amos from the place where the eruv is located within the city. We do not say that the two thousand amos begin from the edge of the city, but rather from the location of the eruv.
In summary: In this Mishnah we learned the law of two towns that are near one another: the residents of the large city may walk the entire small city and even beyond it, since it takes up no space in the calculation of their boundary, whereas the residents of the small city may not walk the entire large city, since their boundary ends in the middle of it. The Gemara completed the picture: all of this refers to one who measures the Shabbos boundary from his own city; but one who places his eruv in another city - that city becomes his city, and he may walk all of it and two thousand amos outside of it. In contrast, a dissenting opinion holds that he has only two thousand amos from the place where the eruv was placed.