NEW YORK — Thinking about backyard chickens as egg prices soar? Think hard, especially in light of the bird flu outbreak.

Keeping home chickens as a pastime has continued to grow since the pandemic. But if eggs are the goal, remember that it takes planning and investment to raise the chickens and protect against bird flu. Costs might go well beyond the nationwide average of $4.15 a dozen that commercial eggs sold for in December.

“Anyone who’s done an ounce of research will very quickly understand that there are no free eggs, there are no inexpensive eggs in keeping chickens,” said Kathy Shea Mormino, a home chicken blogger and author who has about 50 of the birds at her Suffield, Connecticut, home.

“You’re going to pay more, particularly in your first several years, in your setup and in your birds. And there’s a huge learning curve on how to care for animals that are really unusual pets,” said Mormino, who has kept chickens for 15 years and calls herself the Chicken Chick.

Costs vary wildly, from $200 to $2,000 for a coop. Feeders and waterers range from $8 to $50 or more, depending on the size and type.

Bird flu has forced farmers to slaughter millions of chickens a month, contributing (along with inflation) to the steep price of commercial eggs and resulting in some scantily stocked stores around the country. The scarcity and high prices are causing some to look for a backyard alternative.

Kate Perz, the animal science coordinator for Cornell Cooperative Extension of Suffolk County, New York, said that unlike other pandemic pastimes, raising home chickens has only grown.

“It’s not always cost-effective,” she said. “You have to really look at how many eggs you’re eating and what the cost of those are versus what you would be spending.”

Mormino, who wrote “The Chicken Chick’s Guide to Backyard Chickens,” said the first thing to consider is whether chickens are right for you.

After that, don’t assume your county, town or city will allow it.

Look up zoning and building codes. Otherwise, consult an attorney who specializes in municipal law in your area. Don’t rely on word of mouth or even a town worker to know the ins and outs.

Mormino lives in a farming town and had a neighbor who kept three horses and a small flock of chickens, so she assumed they were legal. They weren’t. She called the town clerk’s office to ask whether a building permit was required to build a coop and was told it wasn’t. It was.

In the end, she successfully defended a lawsuit against her (she’s an attorney) and prevailed in a battle to amend the law, legalizing backyard chickens in her town.

There is also the matter of bird flu, which is contagious. It spreads mostly by migrating waterfowl in their droppings. Chickens are far from immune if they spend any time free ranging or in a run without protection from wild fowl droppings.

Don’t bring sick birds into the house for care. That raises the risk of transmission to humans. Once the virus is confirmed, the entire flock needs to be euthanized, she and Perz said.

“The biggest mistake backyard chickeneers make is to bring new chickens into their flock that have lived someplace else. That’s the fastest way to bring disease into your chicken yard,” Mormino said.