The Spaniard, 34, won the Tour de France in 2007 and 2009, but he was stripped of the 2010 title for doping.
He is one of only six riders to have won all three Grand Tours - the Tour de France, Vuelta and Giro d'Italia.
"I don't think there is a better farewell than the home race in my home country," he said on Instragram.
Contador, who turned professional in 2003, added: "I'm saying this happy, I'm not saying it with sadness. It's a decision I've thought about very well."
He was banned for testing positive for clenbuterol - a powerful drug used to treat asthma, but which can also help build up lean muscle mass and burn off fat - at the 2010 Tour de France.
Contador blamed his positive test on eating contaminated steak.
The Court of Arbitration for Sport (Cas) banned Contador in February 2012, but backdated the ban to 25 January 2011.
Having served five months and 19 days of a provisional suspension in 2010-11, he returned to cycling in August 2012.
Contador won seven Grand Tour titles and was awarded the prestigious Velo d'Or, voted for by journalists, a record four times.
Only Eddy Merckx, Bernard Hinault, Jacques Anquetil, Felice Gimondi and Vincenzo Nibali have also won all three Grand Tours.
Two-time Tour de France champion Alberto Contador is to retire from professional cycling after the Vuelta a Espana, which starts on 19 August.