Kathleen McKinnon always planned to start a family, but it proved to be harder than she imagined.

But her company, like many others in the Bay Area tech community, subsidizes costly assisted-reproduction techniques, including in vitro fertilization (IVF), for families like McKinnon's. In 2017, after two failed attempts, she was thrilled to learn that the procedure was successful, and she had six healthy embryos.

After the procedure, McKinnon's doctors performed an extra screening step that has become increasingly popular in recent years to look for health issues and other factors. During that process, she learned the sex of the embryos based on their chromosomal makeup — XX for female, XY for male. The doctors asked her if she wanted to select a baby with a particular gender.

After some consideration, she and her husband asked their doctors to transfer the one that had the best chance of creating a successful pregnancy. It turned out to be a girl, and their daughter was born in June.

McKinnon knows she has five healthy embryos left: Three males and two females. Next time, she is planning for a boy.

While McKinnon underwent IVF only after failing to get pregnant in other ways, some people are using the technique specifically to try for a baby of one gender.

Fertility clinics are popping up across the country that advertise gender selection, and are charging up to $20,000. CNBC visited one of these clinics, the Fertility Institutes in Encino, California, to meet with well-known IVF specialist Dr. Jeffrey Steinberg.

About 85 percent of Steinberg's patients come to him so they can choose the sex of their baby, he said. It is among the better-known clinics in the world for a gender selection technique, known as preimplantation genetic diagnosis (PGD), the additional screening that is offered with IVF.

Some families are coming to him because they already have multiple children of the same gender. That's known in some circles as "family balancing." But that's not always the case. Some families want only one child with a specific gender, or have an order in mind. Others have medical reasons for wanting a boy or a girl, like a genetic disease that only affects one sex and not the other.

"The bulk of the patients that we see are doing in vitro fertilization only to choose the gender," he said. "We do not require people to have a first baby in order to request the gender on the second baby."

For those who can't afford Steinberg's prices, some clinics offer a cheaper option known as as "sperm sorting", where female and male sperm are separated before insemination. This process sorts the dense X-sperm from the lighter Y-sperm.

Steinberg says in his experience, the accuracy for sperm sorting is about 78 to 80 percent for females and 55 percent to 60 percent for males. His approach might be more expensive, but it is also a lot more accurate.