“If your eggs won’t work, you won’t find out until you’re 39,” Dr. Caplan said.

A Pentagon spokesman declined to comment on the legal and ethical questions, saying that details were being worked out. The Defense Department is expected to outline the program in a memo from Mr. Carter in the coming weeks. The program, which applies only to active-duty service members, will be re-evaluated in two years, and could ultimately be made permanent.

“As many families know all too well, these treatments are very expensive and often require multiple attempts,” the spokesman, Matthew Allen, said. “We know that providing this benefit across the board would result in a significant cost for the department. In addition to cost, we want to better understand the importance of this to our force, as well as its impact on recruiting and retention. In addition to hormone therapies and egg and sperm freezing, we are going to continue looking at ways to provide additional support for these types of treatments in the future.”

The Pentagon estimates that the program could cost about $150 million over five years. It will be offered through Tricare, the military’s health care plan.

During the height of the wars in Iraq and Afghanistan, several cryogenic firms offered to cover the cost for troops to have their reproductive cells frozen. It is not clear whether any soldiers ultimately used those materials to have children. In recent years, some fertility advocates have lobbied the Defense Department to cover the cost.

Mr. Carter mentioned the program in a speech last week at the Pentagon. Outlining the Defense Department’s efforts to improve the lives of service members, he focused on longer maternity leaves, improved child care and the creation of lactation rooms at military facilities. He touched briefly on freezing sperm and eggs.

“This investment will also provide greater flexibility for our troops who want to start a family, but find it difficult because of where they find themselves in their careers,” Mr. Carter said.

“Particularly for women who are midgrade officers and enlisted personnel, this benefit will demonstrate that we understand the demands upon them and want to help them balance commitments to force and commitments to family,” Mr. Carter said. “We want to retain them in our military.”