The word mantra is said to come from a root meaning “that which protects the mind.” In Buddhist meditation, many things can be used as objects of concentration — as “mind protectors.”
The breath is used in anapanasati, or mindfulness of breathing meditation. The sensations of walking are used in walking meditation. The emotions are used as a focus in metta bhavana (development of lovingkindness). And visual images are used in visualization. Mantras are sounds — words or phrases — that are used as an object of concentration.
The sounds may be chanted out loud, or may be heard internally. When the mantra is chanted internally, it is the “inner sound” of the thought that is used as an object of focus in meditation.
Mantras can be associated with particular historical or archetypal figures, or may have no such associations. For example, there are mantras associated with the historical Buddha (Om muni muni maha muni Shakyamuni svaha), and the mythical figure Avalokiteshvara (Om mani padme hum).
And so, when mantras are chanted, the figure associated with the mantra may be visualized, or simply borne in mind. Some of these visualization practices are very complex and detailed.
When the mantra is chanted out loud, the sound of the mantra is a focus for attention, although we may also focus on the vibrations in the body, and the movements of the body — the breathing, the lips, tongue, etc.
Mantra chanting can be a solitary or group activity. It may be done as a formal meditation practice, where we sit specifically to recite the mantra, or it may be combined with our daily activities, and be chanted while we’re walking, or driving, or cooking dinner.
Not all mantras are associated with specific figures. The Prajnaparamita mantra (Gate gate paragate parasamgate bodhi svaha) is associated not with an enlightened figure, but with a body of texts known as the Perfection of Wisdom (Prajnaparamita) sutras.
The mantra Om shanti shanti shanti (Om peace peace peace) is not, as far as I’m aware, associated with any figure, and the Pali phrase Sabbe Satta Sukhi Hontu (May All Beings Be Happy) is chanted as a mantra, again without being associated with any deity.