The fourth wall is a theatre term referring to the audience. This originates in the idea that there are three walls on a stage: one on the back, one to the left, and one to the right, as well as an imaginary fourth wall in front that contains the players within their play. To "break the fourth wall" means to show awareness of the audience or other things outside of it.
The fourth wall was famously broken in the seventh episode of The Daleks' Master Plan, "The Feast of Steven", in which the First Doctor wishes the viewers a "happy Christmas": "Oh, and incidentally, a happy Christmas to all of you at home." This is the only case in the series proper in which a character explicitly displays knowledge of being on TV; all other cases of fourth wall breaking involve the characters seeming to talk to or perform for the camera, but nothing that cannot be explained by another character or a mirror being in the position the camera is occupying or a character talking to themselves, and nothing which displays knowledge of being a TV character.
In The Web Planet, the First Doctor struggles to answer a question asked by Ian Chesterton (in reality William Hartnell failing to remember a line). After the Doctor finishes his less than coherent reply, Ian gives a bewildered expression to the camera.
In part one of The Face of Evil, on emerging from the TARDIS, the Fourth Doctor talks to the camera, saying that he doesn't think he is in Hyde Park, putting his landing down to a "nexial discontinuity" and reminding himself to "overhaul those tracers" before walking off into the jungle.
In part four of Image of the Fendahl, the Fourth Doctor says "Time's running out!" directly to the camera.
In part three of Underworld, having managed to successfully expel all the fumigation gas from the tunnels, the now recovered Fourth Doctor says to the camera "I wonder where it all went?"
In part two of The Invasion of Time, the Fourth Doctor breaks the fourth wall by looking at the camera and quipping, "Even the sonic screwdriver's not going to get me out of this one!" At the end of the same serial, he grins mischievously to the camera.
A running joke throughout most televised stories with Peri Brown during the Sixth Doctor's era would be for Peri to at some point note confusion in her location because of the similar looking passage ways ("All these corridors look the same to me" being the most common, but this could change in different scenarios.) This was a reference to the numerous complains that the BBC production crew would build few sets for corridors and tunnels and could simply change small things about the sets and camera angels to attempt to give the illustration of a larger construct. The added gag was suggested by Nicola Bryant, and has since become a piece of fan lore — notably used in both The Curse of Fatal Death and The Gunpowder Plot.
In Remembrance of the Daleks part two, as Ace walks out of the B&B, the television announces, "A new sci-fi series, called Do..." before cutting to the next scene. In the cliffhanger of part three, after the Dalek ship lands outside Coal Hill School, despite the Doctor's prediction, the Doctor turns to camera and says "I think I might have miscalculated" to the viewer. Unlike other cliffhangers of the classic series, the line is not repeated in the reprise at the start of part three.
The best thing about books is that you can always tell when you're getting to the end. No matter how tricky the situation the hero's in, you hold the book to your hand and think, "Hang on, I'm two hundred and twenty-nine pages in, with only another fifty-one to go."...
In Bang-Bang-a-Boom! part four, the theme music starts and then cuts out when Mel points out that the supposed resolution was "too easy."
In Night Terrors, Alex notes to the Doctor that their son is scared of shows on the television and that he considers turning it off, the Doctor snaps "Don't do that!" This is a reference to the controversy that Doctor Who had gained over the years for being frightening to children. In the same story, the Doctor mentions a Gallifreyan tale called Snow White and the Seven Keys to Doomsday. Whilst since connected to a short story portraying the tale, the title itself is a reference to Doctor Who and the Daleks in Seven Keys to Doomsday.
In The Night of the Doctor, the Eighth Doctor claims, "I'm a Doctor... but probably not the one you're expecting", looking at the camera for the latter part of the line. In context, he is replying to Cass' conversation with a computer about doctors; however, the line also alludes to the incarnation's unexpected appearance in the story.
In Deep Breath, after the Half-Face Man has fallen from his "escape pod" and been skewered on a spike on the top of the Elizabeth Tower, the Twelfth Doctor looks directly into the camera as the question is posed: "Did the robot self-destruct or is the Doctor a murderer?"
The beginning of Before the Flood features a lengthy segment where the Twelfth Doctor talks directly to the audience and explains the "bootstrap paradox", telling the viewer to Google it. He uses an analogy of how a theoretical time traveler went back in time to meet his hero Ludwig van Beethoven, only to find out he didn't exist, so the time traveler copies down all of Beethoven's music based on his future knowledge, and then publishes them under Beethoven's name. However this means the time traveler was inspired by Beethoven, who was inspired by the time traveler. The Doctor then leaves the viewer with the question "who composed Beethoven's fifth?" before he takes out an electric guitar and plays the Fifth Symphony which transitions to the Doctor Who theme.
In Heaven Sent, the Twelfth Doctor breaks the fourth wall by saying he is nothing without an audience while looking directly at the screen.