What came first? Was it the chicken, the egg, or the municipal code requiring residents to maintain a 20-foot setback if they want to keep five or fewer poultry on a property zoned R-A1?

City zoning regulations, often labyrinthine in nature, are something many people have never had to think about, but for a growing group of backyard chicken enthusiasts, staying on the right side of the rules can mean the difference between having egg-laying cluckers or not.

Two weeks ago, Grego Carrasco, 46, of San Dimas learned that lesson the hard way. The Inland Valley Humane Society told her she had run afoul of the San Dimas Municipal Code. The eight chickens she had in the backyard of her 1909 home had to go, they said.

Luckily for the flock of hens, Carrasco found a friend willing to take them for her. Still, she said it was disappointing to give up chickens she raised for nearly a year.

"It makes me sad when I think they're not with me," Carrasco said. "They were part of my family"

Carrasco said when she bought the chickens as tiny chicks from the San Dimas Grain Company on Bonita Avenue, she had no idea she would run into any problems. She figured if they were being sold in San Dimas, which has long embraced its Old-West past, it must be OK to keep them there.

And in some parts of the city, it is. But not where Carrasco lives. Ken Duran, assistant San Dimas city manager, said chickens are allowed in areas zoned as residential-agricultural when the property is 11,000 or more square feet in size and the lot is at least 80 feet wide.

Rules like these are surprisingly inconsistent from city to city. Glendora allows residents anywhere in the city to keep two barnyard fowl, whether they're chickens, ducks, turkeys or peacocks. Azusa allows up to five chickens to be kept outdoors, so long as they are kept 20 feet from any property line, 50 feet from any residence, and 100 feet from any school, park or hospital, said Assistant Community Development Director Conal McNamara.

"You would probably rule out most of the properties in the city unless you had a larger lot," McNamara said.

Strangely enough, McNamara said the city code would allow someone to keep up to five chickens inside their home, if they so chose, without all the setback requirements.

In Whittier, a completely different type of regulation exists, said Sonya Lui, principal planner for the city. Lui said a resident who wants to keep chickens would have to apply for a minor conditional use permit. City staff would review the request, examine the property, and then decide whether to grant the request.

Because of the wildly varying rules, it's best to check with city hall before buying chickens to raise, said Wes Alcott, general manager of Kruse Feed & Supply in La Habra.

"When they ask, we tell them every city is different," Alcott said.

Even with those hurdles, Alcott said backyard chickens are now more popular than he's ever seen. He said Kruse Feed used to sell about 1,000 chicks per year. This past year, it sold nearly 4,000.

Alcott said most people who buy chickens are doing it for the eggs - even though it's not cheaper than buying eggs at the supermarket.

KT LaBadie, who runs urbanchickens.org from her home in Iowa, said the attraction to producing eggs at home is knowing exactly what went into them. She said people are taking notice of food contamination and meat recalls and are looking for a safer alternative.

"People are more aware of `Where is this food coming from and how is it being raised?"' LaBadie said.

Plus LaBadie said homegrown eggs taste fresher, have a better texture, and are brighter in color.

"The eggs are definitely different," she said.

Yolanda Mendoza, a cashier at San Dimas Grain Company, who's something of a chicken expert, agreed, saying eggs from home taste better and that backyard chickens are free of hormones and chemicals.

But she added that many people also keep chickens for sentimental reasons. She personally keeps four chickens at her home in Chino.

"I think for everyone, it makes you feel like a kid," Mendoza said. "Some people say it's addicting to have the chickens."

But LaBadie of urbanchickens.com said before someone rushes out to buy chickens, they need to carefully consider a few things, such as why they want the chickens, how many eggs they want or need, and how having chickens might affect their neighbors.

"It's a nice courtesy to let your neighbors know what you're doing," LaBadie said. "Then they might actually want to do the same thing. I think it's a really good way to meet your neighbors too."

Following that approach might have saved Carrasco, the San Dimas resident who had to give up her chickens, some heartbreak. She said most of her neighbors were fine with her chickens and happy to accept the free eggs. One neighbor complained though, she said, drawing the attention of city officials.

Carrasco's not giving up though. She said her chickens helped teach responsibility to her children, and they were just fun to have around.

She said she and a couple of friends hope to convince San Dimas to change the municipal code to allow chickens in residential areas.

LaBadie said many other cities have chosen to go down that path. Even New York City now allows people to keep chickens at home," she said.

"If they can do it, a lot of the smaller cities can as well," she said,