CAIRO -- Reaching the heavily sandbagged entrance to the sprawling protest camp in the northeast of this city requires navigating past makeshift brick walls and stepping around circles of stone marking the places where "martyrs" shot by the government fell dead.
Once there, visitors must submit to ID checks and pat-downs by bearded men with orange vests, hard hats and clubs. Signs on a towering new tent read "Children against the coup."
And then, stretching into the distance is the camp, where tens of thousands of people have built what amounts to a well-equipped community in what was once a traffic-clogged intersection. There are tents with electricity, televisions and Internet access, some of them two stories tall. There are a hospital, communal kitchens, latrines and showers.
This and a smaller camp across town are the front lines in Egypt's dangerous political stalemate between a military-installed government and the Muslim Brotherhood and its Islamist allies who support the ousted president, Mohamed Morsi. The new government accuses them of gathering weapons and says they must leave or it will evict them by force.
But breaking up the camps will be difficult because of the crowds they have amassed, the infrastructure they have built, and the religious fervor the protesters bring to the fight. The military and the police have already killed dozens of people, and human rights groups have reported cases in which Mr. Morsi's supporters have detained and tortured opponents. But instead of scaring the protesters into going home, the crackdowns have reinforced their conviction to stay.
"Everyone who comes here knows that he might not go back," said Mahmoud Arafa, a gray-haired veterinarian who took up residence on a patch of sidewalk here with a few dozen friends a month ago.
Now, Mr. Arafa and his friends sleep on soft blankets in the shade of tarps nailed to a wooden frame. Electricity strung in from a nearby building powers fans, cellphones, a refrigerator and a big-screen television. They make coffee and tea on a gas stove.
"We're here to stay," Mr. Arafa said.
Cairo's camps evolved from the competing demonstrations for and against Mr. Morsi that marked the final months of his year in power. While most of the millions who turned out against him in Tahrir Square and elsewhere have gone home, his supporters have remained, transforming intersections into complex microsocieties.
The main camp and the smaller one outside Cairo University reflect the organizational skill of the Muslim Brotherhood and the ability of Egyptians to make do with what's at hand.
The walls that block the road to the main protest around the Rabaa al-Adawiya mosque were built of paving stones torn from the sidewalks and bear paintings of the "martyrs" of July 27, when security forces killed at least 72 supporters of Mr. Morsi.
Inside, it felt a bit like an Islamic Woodstock, as residents celebrated the four-day holiday at the end of Ramadan. Men, women and children packed the streets, browsing stands selling Egyptian flags, grilled chicken and face masks of Mr. Morsi, who has been detained by the military since his ouster on July 3. They joined spontaneous marches chanting "Down with military rule" or "One, two, where is Morsi?"
Islamic anthems blared from speakers hung from lampposts, and drumming songs lauding Mr. Morsi and insulting the military commander, Gen. Abdul-Fattah el-Sisi, resonated from the tents.
Countless tents packed the sidewalks and traffic islands of the main roads and spilled into nearby side streets and gardens, often leaving only narrow lanes for pedestrians. While some tents were no more than sheets hung from tree branches, many had strong wooden or metal frames. Long lines separated by gender formed outside communal kitchens serving up free meals of rice, lentils and tomato sauce. On one street, men played table tennis.
The camp was decorated with banners declaring "Engineers for Morsi," "Women for Morsi" and "Pharmacists against the coup." One popular sign depicted President Obama as an ancient Egyptian pharaoh holding the leashes of two dogs with the faces of General Sisi and Mohamed ElBaradei, the new vice president. Its text read, "Getting played once again by the tyranny of democracy."
Giggling passers-by snapped photos of a dozen baby ducks near one tent under a sign reading "Ducks against the coup."
"The duck comes out of an egg and cannot go back in, just as we got our freedom and will not go back," said their owner, Ahmed Abdel-Rahman, 49.
Like many of the tents, his had electricity pirated from a lamppost. Men from his camp took turns filling large jugs with water trucked in from outside for drinking, cooking, laundry and ablutions. Each group was expected to keep its area clean, he said, and cleaning crews passed by twice a day to collect trash.
The camp evolved organically and has no overarching authority. Its population fluctuates, from the tens of thousands during the day, when many people go to work, to more than 100,000 at night and during big events.
A few miles away, outside Cairo University, another camp took shape, though smaller and less festive. All entrances to the sit-in at Nahda Square are fortified with multiple walls of bricks, tires, metal barricades and sandbags. There are surveillance cameras on lampposts, huge mounds of baseball-size stones and smaller piles scattered throughout, ready to be thrown. Protesters have used firearms in past clashes with security forces and anti-Morsi marchers, although it is unclear whether the camps now have weapons, and how many.
The smaller camp's population fluctuates, dipping into the low thousands during the day and multiplying at night. It has built its own infrastructure to handle the crowds, with a well-equipped field hospital, communal bathrooms and a bank of spigots for ablutions. On a recent day, women handed out fresh-baked cookies.
Under a patio umbrella in the camp's center sits Mahmoud Ragab's green barber chair. For weeks, he has cut hair, trimmed beards and given face masks and back rubs with an electric massager -- all free, though he accepts donations.
Mr. Ragab, 29, divorced his wife two years ago for what he called disobedience and said the camp was a good place to look for "observant women."
While holding out for a new bride, he slept in the tent near his barber chair, returning home every five days to do laundry.
Like many others, he said he would defend the camp if the police came.
"If I am going to die, I have to take down a few of them with me," he said, adding that all he had to fight with were stones.
"If there were anything else, I would use it," he said.
Mayy El Sheikh contributed reporting.
This article originally appeared in The New York Times.