McKellen was born on 25 May 1939 in Burnley, Lancashire, the son of Margery Lois (née Sutcliffe) and Denis Murray McKellen, a civil engineer. He was their second child, with a sister, Jean, five years his senior. Shortly before the outbreak of the Second World War in September 1939, his family moved to Wigan. They lived there until Ian was twelve years old, before relocating to Bolton in 1951, after his father had been promoted. The experience of living through the war as a young child had a lasting impact on him, and he later said that "only after peace resumed ... did I realise that war wasn't normal." When an interviewer remarked that he seemed quite calm in the aftermath of 11 September attacks, McKellen said: "Well, darling, you forget—I slept under a steel plate until I was four years old.".
McKellen's father was a civil engineer and lay preacher, and was of Protestant Irish and Scottish descent. Both of McKellen's grandfathers were preachers, and his great-great-grandfather, James McKellen, was a "strict, evangelical Protestant minister" in Ballymena, County Antrim. His home environment was strongly Christian, but non-orthodox. "My upbringing was of low nonconformist Christians who felt that you led the Christian life in part by behaving in a Christian manner to everybody you met." When he was 12, his mother died of breast cancer; his father died when he was 24. After his coming out as gay to his stepmother, Gladys McKellen, who was a member of the Religious Society of Friends, he said, "Not only was she not fazed, but as a member of a society which declared its indifference to people's sexuality years back, I think she was just glad for my sake that I wasn't lying anymore." His great-great-grandfather Robert J. Lowes was an activist and campaigner in the ultimately successful campaign for a Saturday half-holiday in Manchester, the forerunner to the modern five-day work week, thus making Lowes a "grandfather of the modern weekend".
McKellen attended Bolton School (Boys' Division), of which he is still a supporter, attending regularly to talk to pupils. McKellen's acting career started at Bolton Little Theatre, of which he is now the patron. An early fascination with the theatre was encouraged by his parents, who took him on a family outing to Peter Pan at the Opera House in Manchester when he was three. When he was nine, his main Christmas present was a fold-away wood and bakelite Victorian theatre from Pollocks Toy Theatres, with cardboard scenery and wires to push on the cut-outs of Cinderella and of Laurence Olivier's Hamlet.
His sister took him to his first Shakespeare play, Twelfth Night, by the amateurs of Wigan's Little Theatre, shortly followed by their Macbeth and Wigan High School for Girls' production of A Midsummer Night's Dream, with music by Mendelssohn, with the role of Bottom played by Jean McKellen, who continued to act, direct, and produce amateur theatre until her death.
In 1958, McKellen, at the age of 18, won a scholarship to St Catharine's College, Cambridge, where he read English literature. He has since been made an Honorary Fellow of the College. While at Cambridge, McKellen was a member of the Marlowe Society, where he appeared in 23 plays over the course of 3 years. At that young age he was already giving performances that have since become legendary such as his Justice Shallow in Henry IV alongside Trevor Nunn and Derek Jacobi (March 1959), Cymbeline (as Posthumus, opposite Margaret Drabble as Imogen) and Doctor Faustus. During this period McKellen had already been directed by Peter Hall, John Barton and Dadie Rylands, all of whom would have a huge impact on McKellen's future career.