Let no person go out of his place on the seventh day (Exodus 16:29)
The Shabbos boundary is called the “techum Shabbos” (“techum” for short) and it extends 2,000 cubits around a city in every direction. (A cubit is about a foot and a half.) The Talmud in Eruvin (51a) derives the size of a techum from the 2,000-cubit boundaries around the Levite cities in Numbers 35:5 by means of gezeira shava (identical wording between the two topics).
Actually, there’s a difference of opinion as to whether the 2,000-cubit limit is the original Biblical limit. It’s possible that the Torah permits one to walk up to three parsangs outside the city limits on Shabbos and that the 2,000-cubit limit is a Rabbinic enactment. (A parsang is about 3 and a half miles.)
The techum starts at the last structure in the city and the size of the city makes no difference. (A city is either enclosed or the buildings are within 70 cubits of one another.) If you live in New York City, you can walk freely from Battery Park to Harlem.
One can extend his personal techum in one direction by means of a type of eruv. (An eruv isn’t only the string around one’s town; there are different kinds for different purposes, established in different ways. Carrying in a shared domain is governed by the rules of eruvei chatzeiros. When Shabbos falls after Yom Tov, we prepare for Shabbos based on an eruv tavshilin. Here, we speak of eruvei techumin.) When one makes an eruv techumin in one direction, he loses the equivalent distance from the amount he is permitted to walk in the opposite direction. For example, if he makes his eruv 1,500 cubits to the east, he may now walk 3,500 cubits out of city limits to the east but only 500 cubits to the west. In other words, an eruv can shift one’s techum, but not enlarge it.
The reason for this mitzvah is to remind us that it was God Who made the entire world from nothing. There’s an interesting incident related in the Talmud concerning the principle of the techum. Due to a particularly traumatic experience, R. Elisha b. Abuyah lost his faith and became the heretic known as Acheir (“the other”). The Talmud in Chagiga (15a) tells us that one Shabbos, Rabbi Meir was walking and talking to Acheir, his former teacher, who was riding a horse. When they reached a certain spot, Acheir told Rabbi Meir to turn back, as they had reached the boundary of the techum Shabbos. (It’s noteworthy that, even though he had strayed, Acheir did not want Rabbi Meir to violate this important halacha.) Rabbi Meir told Acheir that he, too, should turn back – by returning to God! (Sadly, Acheir was convinced that he was too far gone and his repentance would not be accepted.) Nevertheless, Rabbi Meir was able to derive a lesson in teshuva (repentance) from the Shabbos boundary.
This prohibition applies to both men and women, at all times and in all places. It is #321 of the 365 negative mitzvos in the Rambam’s Sefer HaMitzvos and #7 of the 194 negative mitzvos that can be fulfilled today as listed in the Chofetz Chaim’s Sefer HaMitzvos HaKatzar. The Ramban (Nachmanides), however, considers the law of techum to be rabbinic in origin and does not count it among the 613 mitzvos. It is discussed in the Talmudic tractates of Shabbos and Eruvin, notably in Eruvin 17, 35-36, 51, and 58-59. It is codified in the Shulchan Aruch in Orach Chaim 396-416.