Mr. Moua lives with five roommates. And in New York, home to some of the nations highest rents and more than eight million people, many of them single, it is illegal for more than three unrelated people to live in an apartment or a house.

Eric Bederman, a spokesman for the housing department, said the code was devised for residents safety. People with multiple roommates might put locks on their doors or erect barriers, he said, making rescue or escape attempts during emergencies hazardous, even deadly.

But Jerilyn Perine, a former city housing commissioner, said the roommates rule came about to address another concern. It dates to the 1950s, she said, when the city balked at the number of sketchy single-room-occupancy buildings and their often equally sketchy inhabitants, and wanted boarding house brownstones to be converted back to family homes.

Ms. Perine, the executive director of the nonprofit Citizens Housing and Planning Council, said the law, which can be amended only by the City Council, should be changed. It puts people living in such accommodations at risk, she said, by driving this type of occupancy underground. Often, not every roommate is on the lease. Fire regulations might be ignored.

Ms. Perine said occupancy laws should be determined not by whether people were related, but by whether a unit was safely inhabited, whether by four people or more.

Sarah Watson, a policy analyst who works with Ms. Perine, said the law had another unintended effect. It put a crimp on innovative construction that might otherwise house larger numbers of single adults, she said.

Read more in New York Times.