The top-floor hallway of a historic townhouse in Harlem has three doors. Behind one is a bathroom. Another, a closet. The third leads to a one-room apartment inhabited by Brooke Thomas. With no room to spare, everything in the 39-year-old executive assistant’s tiny home is lovingly organized.

“This is more closet space than I think I’ve ever had in a Manhattan apartment,” she says, laughing, even though the closet is located about a foot from the door of her room. “Home is a place to recharge,” Thomas adds, so it doesn’t bother her that the West 113th Street apartment, which she found through an online listing, can only fit a fold-out couch (on which she sleeps), a mini fridge, a hot plate and a TV. The $1,100-a-month rent includes electricity and allows her to continue living in the city, just a quick commute from her Midtown office.

Thomas’ quirky pad is a rare single-room occupancy — known by its abbreviation, SRO. The official definition, according to the Department of Buildings (DOB), is a unit with “one or two rooms [that] either lacks a complete kitchen and/or bathroom or shares them with other units.”

Prevalent in upper Manhattan — with a smattering in the Village, the South Bronx and parts of central Brooklyn — it’s a dying breed of low- and middle-income housing. Between 1955 and 1995, New York went from having an estimated 200,000 SRO units to 40,000, according to City Limits. It was a shift reflective of a series of city administrations’ hostility toward SROs because of their squalid reputation as well as a national trend toward private homeownership and away from more communal housing types.

Anywhere from one to 10 people may share a bathroom, and those profiled here pay rents from Thomas’ $1,100 to $1,450 per month for a unit around 100 square feet. The average price for a Manhattan one-bedroom was $3,502 in June, per the Elliman Report.

The history of the SRO is long and fraught, but in a nutshell: Smaller spaces mean lower rents, so during the Great Depression in the 1930s through recovery in the 1940s, it was most lucrative for landlords to subdivide their properties and cater to low-income workers. Larger units were beyond the budget of most renters. Like “tenements,” which are virtually synonymous with “apartment buildings” but imply cramped walkups with railroad layouts, the SRO has come to be stigmatized and implicative of impoverished conditions. In reality, SROs are a versatile kind of affordable housing not so different from luxury “micro-apartments” built today.

While it has been illegal to create a new SRO in New York since 1955, existing ones are effectively grandfathered in. Landlords must gain a certificate of no harassment from the DOB before converting an SRO to regular, market-rate apartments. The requirement is intended to prevent low-paying tenants from being bullied out of their homes and makes it much more difficult to modernize or renovate SRO-designated buildings. In a notorious 1985 incident, a real estate company demolished four Times Square buildings two days before the destruction of SROs was officially banned.

The Upper West Side’s Imperial Court Hotel, though, has survived. The 227-room building at 307 W. 79th St. is mostly vacant, according to Jose Medina, who estimates he has lived there for about 35 years and that there are only 50 or so full-time tenants left. Rooms had previously been used for short-term renters who shared the halls with the permanent residents — the reason why such buildings are often called “hotels” — until a 2016 ruling that its rooms couldn’t be rented for less than a month. The court decision had broad implications for the city’s remaining SRO buildings, which numbered 300 at the time, as their more transient residents are now deemed illegal.

“It’s OK,” Medina says, smiling, of life in the building, sitting in front of a bunk bed he has for when family stays over. He got lucky with his compact room, which — in addition to fitting the bed, a bookshelf, a small bench and a tiny kitchen — has its own bathroom as well as a small closet, amenities not all the Imperial Court holdouts enjoy. Rents in the building are reportedly as low as $99 a week, and many apartments are less than 200 square feet. Inside, the building’s hallways are silent and wallpapered, each floor identical to the ones above and below. The diversity of residents mirrors the city itself, as does their jadedness: Many spoke wearily of legal struggles, and expressed a desire to be left alone.

At the far more luxurious Hotel Belleclaire at 250 W. 77th St., SROs are embedded among legal short-term units. It is an active hotel in the traditional sense, and it took digging to confirm there are still permanent residents inside.

On West 117th Street in Harlem, Beto Resende, 24, shares his SRO with two roommates, Juan Albors, 21, and Maria Varona, 25. He and Varona, who are partners, share the bed, and an air mattress is stored under a table for Albors. The three pay a total of $1,200 a month, including internet, for the unit, which Resende found on Craigslist. While it may seem extreme to live in such close quarters, Resende reports he prefers it to his old apartment, in an attic above an East Village art gallery. Despite the limited space, the roommates have friends over, and are in a band together, called Morirsoñando.

For Vincent Tacetta, a 25-year-old full-time student, the decision to lease an SRO was political. “I’m here because of gentrification,” he says, adding that he’d prefer to live in Harlem but opted instead for a tiny unit on West 70th Street, where he does not believe he is contributing to the displacement of longtime residents. Besides, he says, “I don’t need a lot of space.”

His pad only has room for a couch, desk, fridge, stove, sink, cabinets and a closet. The bed is lofted. “When I’m laying there, you can see across Broadway,” Tacetta says. When he moves out, he says he won’t pass down the unit to “anyone but a native New Yorker or an immigrant. That’s who NYC is for.”

What clinched it for Tacetta, who was told about the apartment by a friend, is what he refers to as his “backyard” — an extension on the floor below his which juts out directly beneath his sole window and has enough space for a lounge chair. There’s an unguarded, four-story drop from three sides, but the unobstructed Manhattan views make up for the risks of a fence-free makeshift terrace.

Dawn Nicole Lee, 38, lives in an adjacent unit with her two cats, Smittens de Mittens and Snoogers de Boogers, who frequently wander onto the terrace to bask in the sunlight. Lee often joins them, sitting on the ledge of her single window with her feet on the patch of outdoor space. A makeup artist, Lee also has a loft, but due to back problems she bunks on a velvet sofa and plans on turning the would-be sleeping quarters into her “creative space.” The apartment, which she found on StreetEasy in February, costs her $1,450 a month. Tacetta pays $1,300.

Lee and Tacetta’s floor’s shared bathroom is squeaky clean, with a clawfoot tub and skylight to boot. There is a schedule for buying toilet paper, and the residents even leave Post-it notes for each other with reminders, invitations, greetings and even alerts about nearby sales. Lee was welcomed with such a letter when she moved in.

“There’s so much energy in the city you can’t replace,” says Lee, looking out of her cozy home at a view of the backs of century-old buildings and the sky above. “This is perfect for me.”