Today there are a bewildering array of different breeds of dogs, some tiny (so-called teacup poodles almost would fit in a teacup), some enormous (think Newfoundland dogs that could easily pass as friendly bears). There was also a great variety of dogs in the Middle Ages, if not quite so many kinds.
Dogs' chief purpose then, as throughout human history, was to hunt or guard or herd. Every hunting party was accompanied by hounds, to sniff out the game and to chase it down. Every castle had a master of hounds whose responsibility was to train the hounds and make sure they were properly fed and treated. Bigger dogs would be used if one were hunting bear or boar than hunting deer or rabbits. It was expected that the hounds would get to eat part of whatever game they helped catch.
Mastiffs stood guard in castles, and villages would be guarded (sort of) by village dogs. Peasants would probably not have pet dogs, but every village would have at least a couple of dogs roaming around, eating whatever they could find. They would certainly start barking if anyone or anything strange entered the village. In Africa today, many villages have village dogs, that may not belong to any individual but who live next to the villagers, and medieval villages would have been the same.
Armies also might have dogs to bring down opponents. The Vikings most notably brought dogs on their raids. A ninth-century prayer went, "God preserve us from the Northmen and their terrible dogs." The Vikings' dogs were the ancestors of the modern Great Dane. Think about a Great Dane, enormous but sort of clumsy and goofy. Now imagine it fierce and focused rather than clumsy and goofy. Now the prayer makes more sense.
Dogs have been used in herding since humans first domesticated sheep, far back in antiquity. Shepherd dogs as a group are very intelligent, able to follow commands and use their own initiative to round up flocks and keep the straying in line. All medieval human shepherds would have had dogs to assist them.
And then there were the pet dogs. These were only possible for the wealthy, because a dog needs at least some meat, and a dog that isn't helping catch its own food has to be fed with meat that otherwise would go into a human's mouth. (Kibbles were centuries in the future.)
Elegant ladies often had small fluffy dogs, like modern King Charles spaniels or pugs, that they would carry around. Dogs were symbols of faithfulness and devotion, so a puppy made an appropriate gift between lovers. In the late Middle Ages, a tomb carved with the image of a noble lady would often show a faithful little dog at her feet.
Click here for more about medieval domestic animals.