Republicans have wanted to repeal Obamacare for years -- but they've wanted to overhaul Medicaid for far longer.

They are now getting their chance.

The health care legislation working its way through Congress would do much more than its stated purpose of repealing and replacing Obamacare. It would make the most far-reaching changes and deepest cuts to Medicaid in the program's 52-year history.

"Medicaid: Sending it back to the states. Capping its growth rate. We've been dreaming of this since I've been around, since you and I were drinking at a keg," House Speaker Paul Ryan said in March at an event hosted by the conservative National Review magazine.

Senators are still hashing out the details of their bill, which differs somewhat from the one that passed the House last month.

But the general thrust of both chambers' plans is clear: Lawmakers would effectively end Obamacare's expansion of Medicaid to low-income adults and would dramatically curtail federal support for the overall program, which covers more than 70 million low-income Americans. They would give states more control and flexibility in administering the program, but also require governors and legislators to foot much more of the bill.

President Trump is committed to making sure that no one currently receiving Medicaid "would be affected in any way," White House Press Secretary Sean Spicer said Friday. The president feels the Senate bill reflects this and "he's pleased with that," Spicer added.

It's hard to see how these changes would have no impact, however. The overhaul laid out in the House bill would reduce federal spending on Medicaid by nearly a quarter by 2026, compared to current law, according to a Congressional Budget Office assessment. Some 14 million fewer people would be covered by the program at that time.

The CBO is expected to release its score of the Senate plan early this week.

Related: Medicaid covers a lot more people than you might think

Medicaid is the nation's largest single health insurer, covering nearly one-fifth of all Americans. It insures two in five children and the same share of the disabled, as well as three in five nursing home residents. It pays for nearly half of all births and spending on long-term care in the U.S.

The majority of Americans, regardless of political party, have a favorable view of Medicaid and say it works well for most low-income people in the program, according to a new Kaiser Family Foundation poll.

Republican lawmakers, however, have long blasted Medicaid as inefficient and bloated. Many stress that one-third of doctors don't see Medicaid patients and say the program provides poor-quality health care.

Enrollment shot up to 54.5 million people in the decade before the Affordable Care Act was passed, and total spending nearly doubled to $402 billion, in part because of the Great Recession.

Also, many Republicans say that the program's current open-ended funding design encourages states to "game the system." The federal government matches between half and three-quarters of what states shell out on enrollees, providing the biggest injection of federal funds into state budgets. So states have an incentive to spend more to get a larger federal match.

"Medicaid has been a real winner for states," said Joe Antos, a scholar at the American Enterprise Institute, a conservative think tank. "States find ways to get their Medicaid billing up."

Medicaid expansion under Obamacare, which began in 2014, irked many conservatives even more. It has added 11 million newly eligible adults to the rolls and requires the federal government to cover at least 90% of the tab. Many of these adults are able bodied, but the Obama administration did not permit states to impose work requirements on them.

Republicans want to rein in Medicaid by jettisoning the expansion program, sending a fixed amount of money to the states each year for the overall program and reducing the growth rate of that funding. They would also let states require some adult enrollees to work.

Related: Who gets hurt and who gets helped by the Senate health care bill

"The bill is framed as repealing and replacing the ACA, but for Medicaid, the changes are much broader," said Robin Rudowitz, an associate director at the Kaiser Family Foundation. The legislation "would really change the basic core and financing of the program."

Under the Senate plan, the enhanced funding for Medicaid expansion would end by 2024, after which states would receive the same match for low-income adults as they do for other enrollees. This is four years later than the House bill and serves as a concession to moderate Republicans who don't want to swiftly turn off the federal spigot. Governors such as John Kasich of Ohio and Brian Sandoval of Nevada, as well as senators from expansion states, have defended the program as critical to helping those affected by the opioid epidemic.

But it's unlikely that most states could afford to continue covering low-income adults at the reduced match rate, so they would likely have to end their expansions.

Related: Senate GOP health plan may not protect millions on Medicaid expansion

When it comes to the overall program, both chambers would convert it into a per capita cap system, which would send a set amount of money each year based on a state's enrollment, starting in 2020. The cap would differ for each group covered by Medicaid -- expansion adults, children, pregnant women and parents, disabled adults and the elderly -- based on the state's historical spending for that population.

States could also opt to receive a lump sum, known as a block grant, but only to cover pregnant women and parents. (The House bill would allow states to receive funding for children as a block grant, too.)

In addition, the Senate and the House would slow the growth rate of Medicaid spending by pegging the annual funding increases to an inflation index.

Under the current system, Medicaid is expected to grow at a 4.4% average annual rate over the next decade. The House would tie the growth to the medical inflation rate, estimated by CBO to be 3.7%, on average, over the next decade, while the Senate would tighten it even more by pegging it to the standard inflation rate, which is projected to grow at an average 2.4% rate. The Senate's inflation provision would take effect in 2025.

All these funding changes would have a huge impact on the Medicaid program, experts say. The House bill would reduce spending by $834 billion over 10 years, compared to current law, according to the CBO analysis.

The cuts might be even more dramatic under the Senate bill, though the CBO analysis might not show it since many of the changes would take place near the end of the 10-year budget window that CBO studies.

Related: Trump called House bill 'mean'; critics say Senate could go further

Still, looking longer term, switching the growth rate to a standard inflation index more than doubles the magnitude of the cuts resulting from turning Medicaid into a block grant or per capita cap program, according to calculations done by Manatt Health, a consulting firm. That could mean hundreds of billions of dollars of deeper cuts for some states under the Senate bill.

"States will face intense fiscal pressure to reduce benefits, cut provider rates and keep higher-cost people off Medicaid," said Jocelyn Guyer, managing director at Manatt.