Ainley was born in Stanmore, Middlesex the son of the actor Henry Ainley on 20 August 1932 although his birth was not registered until January 1938 at around the time that he was admitted to the actors' orphanage. The birth certificates of Anthony and his brother Timothy identify their mother as Clarice Holmes and it is under this surname that they are recorded in the Official Register. Although no father is named on the birth certificates Timothy's marriage certificate identifies Henry Ainley as his father.
Under the name of Anthony Holmes, Ainley attended Cranleigh School from 1947-50. His first job was as an insurance clerk which was followed by a period at RADA. His half-brother, Richard Ainley, was also an actor.
Ainley's swarthy appearance tended to get him parts as villains, though an early regular role on British television was as Det. Sgt Hunter, sidekick to William Mervyn's Chief Inspector Rose in the second series of It's Dark Outside in 1966. Other notable roles include a subaltern in the 1969 film version of Oh! What a Lovely War, Dietz in the 1975 film version of The Land That Time Forgot, Reverend Fallowfield in the Tigon film The Blood on Satan's Claw (1971), Henry Sidney in Elizabeth R (1971), Clive Hawksworth in Spyder's Web (1972), Rev. Emilius in the BBC's adaptation of The Pallisers (1974), Johnson in the first episode of the BBC programme Secret Army (1977), and Sunley in The Avengers episode "Noon Doomsday" (1968). He was also one of the Hong Kong policemen who discover James Bond's supposed corpse in the opening sequence of You Only Live Twice (1967). Ainley played the role of the wealthy young peer Lord Charles Gilmour in the ITV series Upstairs, Downstairs (1973).
Reportedly, it was his performance as Rev. Emilius (in The Pallisers) that led to him being offered the role of the Master by John Nathan-Turner, who had worked on The Pallisers seven years before becoming producer of Doctor Who. Ainley first portrayed the Master in the 1981 serial The Keeper of Traken and appeared in almost every season up until the cancellation of the original series in 1989, including its final serial, Survival.
Ainley's Doctor Who appearances included: The Keeper of Traken 1981, Logopolis 1981, Castrovalva 1982, Time Flight 1982, The King’s Demons 1983, The Five Doctors 1983, Planet of Fire 1984, The Caves of Androzani 1984, The Mark of the Rani 1985, The Ultimate Foe 1986, and Survival 1989.
He later reprised the role for the 1997 BBC computer game Destiny of the Doctors.
Ainley's great love of the role is often cited in documentaries and DVD commentaries. Script Editor Eric Saward claimed that he introduced himself over the phone by saying "This is the Master" and then would laugh. In the commentary and documentary for The Mark of the Rani, both Colin Baker and Kate O'Mara say that "He only ever wanted to play the Master." Colin Baker remarked that he could afford this luxury because he had built up a private income by the mid-1980s and had inherited a considerable sum of money from his father.
Ainley remained unmarried throughout his life. He joked on the DVD commentary for The Keeper of Traken (which was recorded shortly before his death) that he didn't like the three rings of marriage: the engagement ring, the wedding ring and the bickering.
Ainley was a keen sportsman. Initially he was a rugby player, he played at fly half for the Old Cranleighans, Richmond and Middlesex. Later he turned his attentions to cricket - even abruptly citing Sophie Aldred (who played Ace) as his friend once he learned that she played the game. He appeared on many occasions for the Stage and London Theatres C.C. mainly as an opening batsman.
Ainley died at the age of 71 on 3 May 2004. The Times' obituary for him listed his cause of death as cancer. Ainley was known to be very private, and remained out of the public eye for most of his life after Doctor Who ended in 1989.