President Trump has said he wants to deport two to three million criminal undocumented immigrants. While it's unclear where he got that figure from, achieving his goal won't come cheap.

Immigration and Customs Enforcement is one of two agencies within the Department of Homeland Security that's already playing a pivotal role in enacting Trump's mission. One of ICE's main jobs is to apprehend undocumented immigrants who have received their final deportation orders or who have failed to report to the agency as instructed.

During fiscal 2016, ICE spent $3.2 billion to identify, arrest, detain and remove undocumented immigrants, according to the Department of Homeland Security. ICE handled some 240,000 of the roughly 450,000 total deportations that took place last year. (Customs and Border Patrol was responsible for the rest. It also arrests and deports undocumented immigrants, but mainly as they try to enter the U.S.)

Each deportation conducted by ICE cost taxpayers an average of $10,854 in fiscal 2016, an official from the agency told CNNMoney. This amount includes everything from housing and feeding a detainee to transporting him back to his home country.

Related: New York to provide lawyers for immigrants facing deportation

Here's how the experts break down the costs:

Apprehension

Last year, the majority of ICE's removals -- 175,000 -- happened at the border or a port of entry. The remaining deportations occurred either because ICE agents conducted their own investigation or they relied heavily on local police forces. In 2016, ICE spent $129.4 million to identify and apprehend what the agency refers to as immigration fugitives.

Many city, county, and state law enforcement agencies coordinate the release of undocumented immigrants with ICE after arresting them for other offenses like traffic violations. This helps bring costs down dramatically, said Doris Meissner, director of the U.S. immigration policy program at the Migration Policy Institute and a former commissioner of the U.S. Immigration and Naturalization Service.

Related: Blocking funds from sanctuary cities easier said than done

"Typically, ICE officers are in county jails where they easily take criminal immigrants into custody once they've served their sentences," she said.

ICE's Fugitive Operations, which conducts its own investigations and raids, was responsible for a smaller number of arrests last year. According to TRAC, a database of information on the staffing, spending and enforcement activities of the federal government run by Syracuse University, about 15,000 arrests were made this way.

This is costly, however, because ICE will send "a team of six to 12 officers to a person's house and bang on the door all day," said Tanya Golash-Boza, a professor at the University of California, Merced, who specializes in deportation research. "And it's not just the raid itself, they had to spend hours preparing, investigating, stakeouts. It all adds up."

Detention

Detaining undocumented immigrants is the most expensive part of the deportation process because it entails providing food, shelter, medical treatment and other necessities.

According to DHS, ICE operates 112 of its own detention facilities in the U.S. It also works with roughly 500 other state and local jails, as well as private prisons, to detain deportees, reports TRAC.

In 2014, the average cost to hold one deportee in a federal detention center was $5,633, according to the Center for American Progress, a left leaning think tank. The average stay: 31 days.

And some costs have been on the rise. Last year, ICE spent an additional $345 million to accommodate "the surge in families with children crossing the U.S. southern border illegally," according to the DHS. Families in detention require specialized services, including education for school-aged children.

Related: Without immigrants, U.S. workforce would shrink dramatically

While some undocumented immigrants are detained for a matter of days, others can wait months -- or even years -- before they go before a judge or get sent back to their home country.

One reason: there isn't enough staff to handle the caseload, said Golash-Boza.

On Tuesday, U.S. Attorney General Jeff Sessions told a group of Customs and Border Protection personnel in Nogales, Arizona, that the Department of Justice will add 50 more immigration judges this year and 75 the following year. He also plans to streamline hiring, to reduce immigration court backlogs.

Legal processing

Between ICE and the CBP, about 450,000 undocumented immigrants were returned to their home countries in 2016, but only about 15% of them ever went before a judge, said Greg Chen, an advocacy director at the American Immigration Lawyers Association.

Undocumented immigrants with prior orders for removal or who have overstayed a visa waiver can be removed without a chance to argue their case in court, Chen said. But there are some cases in which they can ask for a court hearing, such as a request for asylum or an adjustment of their immigration status based on a family member's U.S. citizenship, said Golash-Boza.

They can hire their own lawyer. But unlike U.S. citizens, the government won't pay for one if they can't afford it, she said.

Related: Muslim immigrants say Trump is slamming door on our American Dream

Estimated costs for the government's legal proceedings vary from roughly $1,200 to $1,500 per case, according to research reports from the Center for American Progress and the American Action Forum.

Among cases that take the longest are asylum cases. On average, these can take about two years to resolve, Golash-Boza said.

Transportation

Mexicans caught illegally crossing the border for the first time are returned almost immediately because of proximity. Those who are from places other than Mexico wait in detention until transportation is arranged to take them back to their home country.

In addition to chartered and commercial buses, detainees are also transported by ICE Air Operations. These chartered planes can hold up to 135 deportees and most flights travel to the Caribbean and Central and South America.

"For Dominicans and Jamaicans there's one flight a month," Golash-Boza said. "Chinese deportees must travel on an American carrier and be accompanied by two marshals, who then must return, driving up the cost."

Some undocumented immigrants may come from countries that don't cooperate with U.S. immigration officials, meaning they may end up stranded in detention for months or years, Golash-Boza said.

ICE said it cost an average of $1,978 in fiscal 2016 to transport each deportee to their home country. It would not provide any further detail.