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.

Rosie Batty, 52, from Tyabb, a small town in Victoria, began her work after her son Luke, 11, was stabbed to death.
She received the award from Australian Prime Minister Tony Abbott at a ceremony at Parliament House, Canberra.
The award winners are selected from public nominations and announced ahead of Australia Day, on 26 January.
The 2015 Young Australian of the Year is 21-year-old West Australian Drisana Levitzke-Gray, a young deaf woman who advocates for other deaf people.
Senior Australian of the Year is 61-year-old Jackie French from New South Wales, a children's author and advocate for children with learning difficulties, and the Australian Local Hero is 41-year-old Juliette Wright from Queensland, who established an online platform to get goods and services to vulnerable and marginalised people.
This year was the first time in the 55-year history of the awards that women have secured the top honour in all four categories.
The recipients were great Australians and great role models, said chairman of the National Australia Day Council, Ben Roberts-Smith.
"It is a great moment in the 55-year history of these awards to honour four women.
"Rosie, Jackie, Drisana and Juliette remind us of the many ways in which women contribute to our nation; that women are a force for change, a voice for rights, influencers, educators and the heart of our communities," he said.
After her son's death, UK-born Ms Batty emerged as an articulate and powerful advocate for the rights of women and children living in violent relationships, giving new force to efforts to prevent family violence across Australia.
Family violence activists say Ms Batty's ability to explain to the public why so many women struggle to protect their children from violent partners helped make the issue of family violence a key campaign issue for all political parties in last November's Victoria state election.
Greg Anderson, 54, killed Luke Batty in front of shocked onlookers at a cricket oval in Tyabb.
The father and son had been playing together during an access visit in February 2014 when Anderson suddenly struck his son with a cricket bat and stabbed him.
Anderson was shot by police after threatening them with a knife when they tried to detain him. He died later in hospital.
Ms Batty was at the cricket ground when the attack happened.
The public killing shocked Australians in a way that many other acts of family violence committed every week in the country have not.

The pedestrian was pronounced dead at the scene of the crash, which happened at 01:35 BST on High Road, at the junction with Seven Sisters, in Tottenham.
His next of kin have been told, the Met said.
A 36-year-old man has been arrested on suspicion of failing to stop at the scene and causing death by dangerous driving.
He is in custody for questioning.
Road closures are in place and parts of the pavement between the High Road and Stonebridge Estate are also closed.
Two-time Tour de France champion Alberto Contador is to retire from professional cycling after the Vuelta a Espana, which starts on 19 August.
[NEXT_CONCEPT]
A woman who became a campaigner against domestic violence after her son was killed by his father last February has been named Australian of the Year.
[NEXT_CONCEPT]
A 70-year-old man has died in an apparent hit-and-run in north London.