Breaking Bad creator Vince Gilligan said that when he first started visualizing the series he wanted it to be about "the protagonist turning into the antagonist". Later on he would describe Walter White's character development as changing him from Mr. Chips to Scarface. All of those ideas indicate that, unlike most American TV series, this would be a story with a definite beginning and an end. In July 2011, Gilligan announced that the fifth season would be the show's finale. Relevant quotes from the linked article:
"I actively wanted to create a TV show in which the main character
transformed from who he used to be into what he eventually will
become. That’s not how TV series are usually designed. The idea is to
have your character remain pretty much who they are, sometimes for
decades on end. I wasn’t interested in doing that.”
And this one:
“This was never intended to be an open-ended show,” he said. “As
creators of the show, we have to see it through to the end, to finish
what we started.”
However, that doesn't mean that the whole story from beginning to end was written before the show started. The show's writers changed many planned story elements as they went along. For instance, Jesse Pinkman was supposed to be killed off at the end of the first season. But thanks to Aaron Paul's amazing performance and on screen chemistry with Brian Cranston (Walter), the decision was made to keep him as a character. Another prominent change was making Gus Fringe the main villain instead of Hector Salamanca, again due to the excellent performance of the character's actor Giancarlo Esposito.