K-9 was created by Professor Marius of the Bi-Al Foundation who had to leave his own dog on Earth as a result of the weight penalty. As a substitute, he built a robotic dog which could also be his own personal databank. When the Swarm attempted to take over the Foundation, K-9 was instrumental in fighting it, and he also helped the Doctor and Leela to destroy the Nucleus on Titan. With Marius soon returning to Earth, he could not take K-9 back with him, and Leela was able to cajole the Doctor into keeping him.
K-9's memory cores hold a vast amount of information, which he can also print out on a ticker-tape reel in his "mouth". His head also contains rotating ear sensors (with which he can triangulate distances and locate people; they whirr as he performs calculations); red eyelights which blink; an extendable eye-sensor, with which he can communicate with other computers (including the TARDIS), locate people, take energy readings, and diagnose the status of either humans or machines; and, most vitally, an extendable nose laser. The laser has four levels of intensity, including kill, polarize and stun (mark 7 seems to be a stun level with long-lasting effects). K-9 can fire the laser at any angle without having to incline his head to adjust it. The laser is powerful enough to vaporize rock, and K-9 can sweep it to hit multiple targets. While the red laser is used for killing and stunning, a blue beam is used to re-fuse metal. The rest of K-9's body is covered with a kind of armored plating that shields him from blasters and has a high resistance to pressure.
Aside from his nose laser, one of K-9's most valuable features is his sensors. He has the ability to determine the location of individuals and how to reach them (if the people in question possess psychokinetic powers, and apparently Time Lords do, he can track them by following their psychospoor), he can distinguish people by their heartbeats, and he can analyze an individual's brainwave patterns to determine their emotions or intentions. In his databanks are recorded the scent, blood and tissue types and alpha wave patterns of individuals, which also enables him to track them.
K-9 claims that he has only memory and awareness circuits, not emotion circuits - but he is a very emotional being. K-9 likes nothing more than being praised by his Master or Mistress, and when he is shouted at, or left behind, he often gets his feelings hurt (at which point his head and tail dip sadly). And, of course, he is highly loyal to his Master and Mistress, and will protect them even at his own peril. He can be ordered to attack with the command "kaylaylee!"
K-9 is accustomed to taking orders and carrying them out; he does not generally take the initiative himself, although he may suggest solutions to the problem at hand. In the TARDIS, he frequently gives status reports, and when outside it, he will often alert the Doctor to approaching humanoids or alarming changes in the surrounding environment. He sometimes refers to people as "units".
As a machine, K-9 has a certain affinity with other machines. He can often communicate with them, and he can also link himself up to ships and control them. K-9 can even operate the TARDIS remotely, at least to the point of making the doors open and close. But as a sentient creature, K-9 is susceptible to being taken over by alien entities.
The Doctor usually carries a dog whistle with which he can call K-9, whose remarkable hearing allows him to hear the Doctor's summons even from inside the TARDIS. K-9 will sometimes automatically regard strangers as potential hostiles, and can be instructed to memorize them as "friend" if they are, in fact, non-hostile. When introduced to friends, K-9 sniffs them and wags his tail.
One of K-9's main weaknesses is that he frequently breaks down - his casing is not waterproof, he can get a form of laryngitis, and his energy reserves are not unlimited, causing him to need to recharge periodically. When he is sufficiently powered up, he can transfer power to other machines through leads attached to his ear sensors.
When Leela parts company with the Doctor to stay on Gallifrey, K-9 decides to stay there with her. The Doctor, however, has K-9 mark 2 packed away in a box in the TARDIS; after assembling it, he and K-9 travel together for some time before Romana joins them in the quest for the Key to Time. K-9 mark 2 is damaged by time winds in E-Space, causing all his circuits to corrode, but he is healed and undamaged on the other side of the Tharils' mirror, where he has to stay. Fortunately, Romana chooses to stay too, so K-9 aids her in her fight against injustice. Finally, the Doctor sends K-9 mark 3 as a gift to Sarah Jane Smith, and K-9 helps her foil a black-magic coven in rural England.