Trump vowed that he would build a "big lovely wall" across the US-Mexico border, which is 2,000 miles long.
When Spanish diplomats told Trump building a wall across the Sahara desert would be no easy feat the president said, "The Sahara border can't be bigger than our border with Mexico".
Spain's politicians have agreed a solution needs to be found to deal with the migration crisis, with Africa's population set to double in the next 20 years.
The US president is said to have made the suggestion during a meeting with Josep Borrel, Spain's foreign minister.
But Mexico has flatly told the president that it won't spend a dime on his wall, and Congress has refused to cough up much cash for it. Most estimates for the Sahara put it at about 3,000 miles long from east to west.More news: Marvel May Have Loki and Scarlet Witch Series For Disney Streaming Service
Although he declined further comments on the issue, a spokesman for the Spanish Foreign Ministry confirmed Borrell's comments to CNN.
The minister offered no further details about when the conversation might have taken place but it is believed to have been in June when he travelled to Washington for the White House visit of Spain's king and queen.
The Sahara desert is roughly 5,000km long.
Building a wall along the US-Mexico border - and getting Mexico to pay for it - was one of the key policies of Trump's presidential campaign. Shanksville. And I was there. "They have a series of walls, I'm saying, 'It's like flawless.' So, so, we are pushing very hard".
Central American migrants sit on the US-Mexico border wall at its westernmost point, Tijuana, Mexico.