Ashvamedha Yagnya in Hinduism is a great ritual of the Vedas, primarily the Yajur Veda though it also draws from the Rig and Sama Vedas. The main ritual instructions are found in one whole dedicated Kanda of the Shatapatha Brahmana of Shukla Yajur Veda. However, some important descriptions of the Yagnya in practice are found in the Mahabharata. It was performed to establish the regional sovereignty of a Raja and increase the Raja’s power and glory. Secondary goals included increasing prosperity in the Rajya, to cleanse the Raja of past sins, and to bring about the birth of a child to the Raja and Rani.
Notably, while there is a Wikipedia article on Ashvamedha that gives a fairly detailed description of the Yagnya, this description has some inaccuracies when compared with the scriptures.
The basic format of an Ashvamedha Yagnya is that a stallion is released to wander freely for one full year. If anyone captures or kills the stallion during this year, then they have successfully defeated the Raja’s authority and do not come under it, and the Ashvamedha Yagnya has failed, which is far worse for the authority of the Raja than if he had never attempted it. The Raja’s followers are not allowed to restrict the free wandering of the stallion, but they are allowed to guard him, so the Raja sends an army with orders to follow the wandering stallion around for a year and prevent anyone from capturing or killing him. If the stallion wanders freely for one year, then the Raja’s men guide him back to the capital, where he is sacrificed, completing the triumphant Yagnya, and by Vaidik authority the Raja is declared the undisputed sovereign over all the lands through which the stallion wandered. It essentially amounts to a ritualized, symbolic form of conquest which greatly reduces the bloodshed and destruction involved. Usually the fights which occur, when friendly relations cannot be immediately established, are duels which are not to the death. It is a ritual combat. The Rajas and other great warriors of the “defeated” lands are invited to the great Yagnya at the end, and they all exchange gifts both ways. This was seen as a way of settling scores, resolving differences in respectful combat, and then making peace and coming to an accord.
Getting more into the extremely elaborate details of how Ashvamedha Yagnya is performed:
A special Yagnya house must be constructed.
A fire altar must be constructed.
Notably, the Wikipedia article claims that the stallion must be white with black spots. This is incorrect; an entirely or mostly black stallion is considered excellent. Various horse-experts select the stallion after careful examination.
The day before the stallion begins his wanderings there is a ceremony in the Yagnya house, at a moment precisely calculated by astrologers. The Raja gives four thousand cows and four hundred gold coins to the priests to compensate them for their invaluable services.
That night, the Raja and Rani sleep together but must not have sex, to build up the energy of his Brahmacharya for the following day.
The next day, a Diksha ceremony is held in which the Ritvija priests initiate the Raja into the Yagnya. He seats at the Yagnya altar wearing a black deerskin for his upper garment and a silk cloth below, holding a staff and wearing a gold necklace. This is the same as the priests’ outfit; the Raja is made one of the priests for this ritual. The stallion is ritually transformed into a solar god. Among the consecration rituals, the stallion is sprinkled with water from a southward-flowing river, the Adhvaryu (priest of the Yajur Veda) and the Raja both whisper Mantras into the stallion’s ear, a certain type of black dog is killed with a club made of sidhraka wood, the dead dog is passed under the stallion, then dragged to the river and put into the river to flow downstream. The energies of death and life are blended all throughout the Ashvamedha Yagnya, producing a ritual of enormous power.
Then the stallion is set loose toward the northeast (the auspicious direction of Ishana Deva) to start with, and thus his free wanderings begin. The stallion represents the blazing solar glory of the Raja roaming freely over the lands in sovereignty and splendor. The stallion is accompanied by a herd of one hundred geldings, representing the Raja’s servants. The army who guards the stallion must consist of either one hundred or four hundred men, all of them nobles or at least sons of high court officials. They must not impede the stallion, drive him in a certain direction, or otherwise interfere with his free natural choice of direction in his wanderings. They are also supposed to prevent the stallion from mating with any mare, though this is a secondary objective; if the stallion has sex, that is bad but not a total failure of the Yagnya.
If the stallion has sex with a mare (the army having failed to prevent it), an oblation of milk must be made to Vayu to atone for this failure.
If the stallion becomes injured, an oblation of porridge is made to Pushan, protector of animals.
If the stallion becomes ill (but not injured), then a cake is offered to Agni Vaishvanara, the fire of robust health.
If the stallion gets an eye diseases specifically, an oblation is made to Surya, Deva of the eyes.
If the stallion drowns, an oblation is made to Varuna, Deva of water.
If the stallion dies (not through being killed by enemies), then another stallion is selected and consecrated to replace him.
If the stallion is lost and not regained, then the Yagnya has failed. There is an expiatory process involving offerings of many dishes and substances to Dyaus, Prithvi, Vayu, and Surya.
Meanwhile, every day of the year of the stallion’s wanderings, ceremonies are near-constantly performed in the Raja’s palace. Every day, the priests conduct three Savitreshti rites. Every evening they perform a Dhriti Homa. After the Dhriti Homa every evening, four bards and lutists - two of them brahmins and two kshatriyas - praise the Raja’s generosity and then tell stories on certain subjects. There is a specific sequence of ten subjects. Each night a story is told on one of those subjects, cycling through the list of ten (so on the eleventh night, it returns to the first subject and a second story on that subject is told, and so on). The Raja, Rani, and a whole audience attend these stories according to their free availability on each given evening (they are not required to attend every night).
If the stallion is successfully returned to the capital in triumph at the end of a year, then a new, final sequence of rituals commences, spanning twenty-seven or twenty-eight days (depending on if a one-day optional ritual is included).
Actually, preparations for the grand festivities begin when the stallion’s return appears likely imminent. Large special Yagnya grounds must be measured and laid out by experts and temporary buildings constructed, forming a whole compound. The ground must be level, accommodations must be prepared for a large number of royal guests (all the neighboring Rajas and their retinues) and for many brahmins and vaishyas as well, and so on.
After the stallion’s return, for the first twelve days of the final sequence, on each day, an oblation is made, then the Raja bathes, dresses in the skin of a black antelope and a head covering, and sits on a skin mat in a hut in front of a fire, fasting in silence. For these twelve nights the Raja sleeps on the ground. These are ascetic preparations for the great Yagnya to come.
On the thirteenth through twenty-fourth days, Soma plants are gathered, Soma Deva is ceremonially welcomed, various structures are prepared for the greater rituals to come (many of them gilded and otherwise lavish and enormously expensive), and on the twenty-fourth day a goat is sacrificed. During this period is when all the guests are invited to arrive.
On the morning of the twenty-fifth day, which is timed to be the full moon day of the month of Chaitra, the Raja undergoes a Diksha ceremony for performance of the main part of the Ashvamedha Yagnya. Certain Mantras are chanted declaring the intention of what is about to be performed. Then the priests perform the Dharma Pravargya rite, a special preliminary rite. Then an Agnishtoma Yagnya is performed in three sessions: morning, noon, and evening. In the morning session, Soma juice is pressed from the plants (this is its own ritual, called the Abhishava rite, in which the Soma plant is first consecrated with Mantras), and many different offerings are made to the Devas with five Saman and five Rik Mantras, Soma is offered to Devas in the Savana rite and also drunk by the priests, many more oblations are made, and a goat is sacrificed to Agni. At noon there is a second Soma pressing and offering, this one to Indra, and the Raja gifts a multitude of cows to the priests. In the evening there is a third Soma pressing and offering, with two Saman and two Rik Mantras, followed by two more oblations with certain Vaidik Mantras. Then an antelope skin (considered a sacred and pure item) is put into a body of water, and then the Raja, Rani, and the priests ritually bathe in it. Then there is an animal sacrifice, either of a sterile cow or, as a substitute, of eleven other animals.
Throughout the entire twenty-fifth night, from nightfall till dawn, an Anna Homa goes on constantly, with offerings of ghee and fried grains including rice and barley. Some of this offered grain is saved to be fed to the stallion the next day.
On the twenty-sixth day the Raja undergoes a ritual purification. The stallion is yoked to a gilded chariot together with three other horses, to the accompaniment of certain Mantras from Rig Veda and Yajur Veda, to bless the Raja’s chariots. Then the stallion is removed from the chariot, taken into water and bathed. Then the Rani and two other royal women (though these roles were far less consistent than Wikipedia makes them out to be) anoint the stallion’s whole body with ghee, and adorn his head, neck, and tail with golden ornaments and either 101 or 109 pearls.
Then an absolutely gigantic, elaborate animal sacrifice ensues. At least 300 animals (including the stallion) are gathered and arranged in a field, each tied to a Yupa (sacred post) to place them in specific positions forming a gigantic ritual diagram, essentially a giant Yantra made of living animals. These include many different kinds of animals, including birds, aquatic animals, wild predators, etc. In fact, there are hundreds of optional animals; the full count, if all the optional ones are included, is 609. The Yupas are themselves ritual objects; each of them is made of a specific type of wood, and upon being planted firmly in the ground is dedicated with certain Mantras. Many of the animals are attached with ropes to the central stallion, connecting them in a ritual sense. Each animal is dedicated to a specific Deva. There is a male goat dedicated to Agni connected to the stallion’s chest, a ewe dedicated to Sarasvati attached to just under the stallion’s mouth, two black-bellied male goats dedicated to the Ashvins attached to the stallion’s front legs, a dark grey male goat dedicated to Soma and Pushan attached to the stallion’s underbelly, a black goat dedicated to Surya attached to one side of the stallion, a white goat dedicated to Yama attached to the other side of the stallion, a white goat dedicated to Vayu attached to the stallion’s tail, and so on. There are two goats with shaggy thighs dedicated to Tvashtar, a pregnant cow about to give birth dedicated to Indra, a dwarfish cow dedicated to Vishnu, etc. There are bulls of certain specifications and so on. They represent all the living creatures of the Earth.
Once all the animals are in position, the Raja feeds the remain’s of last night’s offered grain to the stallion.
Then all of the animals except for the stallion are simultaneously ritually killed and burned, though some of their blood is saved for impending oblations. This huge and profound mass sacrifice is explicitly very literal in the Shastras, though in some modern interpretations/modifications it is done symbolically and not literally, in keeping with more modern sentiments.
Then the stallion is suffocated to death. The reason for this particular mode of killing is to keep the body perfectly intact for the next part. In general, the animal sacrifice here is what frees the stallion from his animal body and lets him become a solar god in full truth, releasing all the energies of the yearlong Yagnya to bless the Rajya and bring it into tune with the solar cosmos. The deaths of all the other animals tie this blessing to all the creatures of the Earth, yoking them in a mystical sense to the authority of the Raja, which is synonymous with the power of the Divine Sun and the united will and harmony of all the Devas. It is a profoundly sophisticated expert spiritual operation requiring the coordination of hundreds of specialized professional ritualists, no mere primitive thing.
The subsequent rituals involving the Rani and the stallion have attracted much attention. Wikipedia gives them great detail as if they are a major part of the ritual. I notice the other main answer to this question here on Quora, by an infamous anti-Hindu, makes them out to be the primary part of the whole Ashvamedha Yagnya. But this is quite inaccurate to the scriptures. Indeed, even in ancient times this portion was sometimes omitted entirely; it was certainly not the essential central part. Yet, I also do not find it shameful or objectionable.
The optional section is this: The Rani performs some rituals blessing the stallion. She and any fellow queens circumambulate the stallion reciting Mantras, some of them quite explicitly sexual. The Rani then lies down beside the stallion in a position mimicking sexual intercourse, and spends the whole night there. Then on the morning of the twenty-seventh day, the priests come and move the Rani back from the stallion. The symbolism here is profound. The Rani represents the fertility of the Earth, corresponding with the Raja as the Solar fertility. The Solar fertility having been Mantrically embodied in the form of the stallion, the Rani symbolically sexually unites with him to bring about the fertile union of Sun and Earth, and bless the entire realm to flourish. This is an ancient and powerful rite, not some perverse corruption.
Either after that, or immediately after killing the stallion if that part is to be omitted, one priest cuts the stallion’s body into pieces in certain ritual patterns, while the other priests chant Vaidik Mantras to secure a joyful new heavenly body for the stallion. Then the Rani is brought back to sit near the dismembered stallion. The Rani must herself know certain requisite Mantras. Certain parts of the stallion’s body are offered to the Devas in an oblation along with Soma. An oblation is made of the blood of all the sacrificed animals, including the stallion. The priests burn the stallion’s marrow, and the Raja smells the smoke, which is said to be capable of cleansing one from every sin, for in it was concentrated the living godhood of the consecrated animal. A full team of sixteen priests - the complete Vaidik complement of the Hotri (priest of the Rig Veda) and his three assistants, the Adhvaryu (priest of the Yajur Veda) and his three assistants, the Udgatri (priest of the Sama Veda) and his three assistants, and the Brahmana (priest of the Atharva Veda) and his three assistants - offers all the remaining parts of the stallion into the fire.
On the next day (either the twenty-seventh or twenty-eighth day), an Atiratra is performed: a nighttime Soma pressing and drinking session. This is followed by an Avabhritha ritual.
Then the Raja takes a final bath. This bath is said to be highly cleansing of all sins and productive of the highest Punyam. After the Raja, everyone else bathes too, even criminals and the lowliest of society, for it is seen as purifying all of their sinful natures and giving everyone a fresh start.
After the final bathing, Wikipedia cites French Indologist Louis Renou for the claim: “Afterwards twenty-one sterile cows are sacrificed, and the dakshina was distributed to the priests. The main dakshina forms either the four wives of the king or their four hundred attendants.” I’m not sure what Louis Renou’s source for this was, but it is explicitly contradicted by Shastras which clearly and in extensive detail state that the dakshina was paid in gold coins, and make no mention of another animal sacrifice at this point in the proceedings.
The stallion’s yearly wandering, triumphant return, death and Divine resurrection in Heaven represent, among other things, the yearly course of the Sun, and bring the entire Rajya (kingdom) in tune with the beneficent power of Nature and harmony. The stallion is also identified with Prajapati-Agni, the Progenitor Fire, which is one with the Sun, the cosmic Flame which is the source of life. He is also identified with the Purusha, and with Varuna.