As the name suggests, the ritual is essentially to confer Raksha ' safety ' on the person you love.
In ancient India, people used to seek divine protection before commencing on any thing major - e.g. a long journey, business venture, a long ritual/sacrifice, battle etc. Raksha sought at these times was specific for the task ahead and usually, the protection was sought for specified length of time only (till the end of the yagna / battle etc). As a visible token of this, a sacred thread was usually tied on the right hand of the person seeking divine protection.
Raksha Bandhan is a festival where the sister seeks an all encompassing "divine protection" for her brother till she meets him again. Its more like a general insurance policy rather than specific insurance policies for each item / event in your life !
As with any ancient tale, there are multiple sources to the origin of Rakhi / Raksha Bandhan. One of the earliest tales to be linked to this festival is that of goddess Lakshmi and King Bali.
Bali, grandson of Prahalada, was a great rakshash king. He managed to defeat the Devas by his valor and virtue. His physical strength and devotion to God were such that Indra could not defeat him in the battlefield or in the yagna-shalas. Eventually, Lord Vishnu had to come as Vamana to rescue Indra from his plight and thrust Bali into the nether world without a fight.
God is never cruel. He may appear to be so, but, like a kindly parent, He is sometimes cruel to be kind. Indra, though the undisputed Lord of Amaravati, is constantly in fear of losing his grip on power. Bali, Lord of Patala, though stuck in the nether regions, is secure in his mind that the Lord will take care of Him !
Having consigned Bali to Patal, the Lord promised him divine protection and immortality till the next aeon, when he will be crowned Indra. Till that time, the Lord Himself decided to protect him in person ! As the Vaikuntha was bereft of Vishnu, Lakshmiji became restless and came seeking her Lord. Finding Him as a door keeper of Bali, the great goddess decided to regain her Lord by befriending Bali.
Disguised as a brahmin woman, she came to Bali and said, "O generous king, please offer me protection in your mighty palace, as my husband has gone away on some long errand. I have no other relatives here and I need somewhere to live."
The king was happy to oblige and welcomed her into his palace and indeed, make her feel very much a part of the family. Happiness, wealth, harvest, all things auspicious had multiplied in his kingdom since the arrival of this mysterious brahmin woman into Bali's house. Bali was happy to have her stay in his home and treated her as his own sister.
Lakshmiji was sad though. Everytime she went past the main gates, she saw her Lord guarding Bali even from Yama ! Lord of the Gods, Sustainer of the Universe, now a mere guardian of Bali ! She was desperate to have Him come home, but the Lord would not abandon His devotee and refused to leave Patala.
One day, during the Purnima celebrations, Lakshmiji tied a thread of colored cotton on Bali's hand and prayed with a pure heart for his protection. Touched by her sincerity, Bali said, "Sister, you have always been very good to me. I am humbled by your love for me and my family. Your arrival has spelled good times for us here in the Patala. However, I see that pinning for your husband still grieves you and makes you sad. I want to see you smile sister. Today, ask for anything you want and it shall be yours. All I want to do is see you happy."
Sensing her chance, Lakshmiji said, "Only one thing can make me happy brother ' your brother-in-law. Please ask Him to come home with me." Confused, Bali asked how he can make this happen. Overcome by shyness, Lakshmiji pointed at the gatekeeper of Patala and said, "Your guardian is my Lord and husband, He who is the Lord of the Universe and source of all things auspicious." Confused, Bali asked how a mere guardian can be the husband of such a virtuous lady !
It was then that Lakshmiji revealed herself as the Goddess Shri and the guardian as the Lord Vishnu himself ! Overcome by awe, Bali bowed and asked the Lord to reveal Himself. The Lord told him how He loved His devotees so much, He was willing to give up Vaikuntha and Shri for them !
Bali requested the Lord to go with Lakshmiji, but return later to be near him again. Hence, each year the Lord spends about 4 months of the monsoon season in the Patala with Bali, from Vaikuntha Ekadashi to Prabodhini Ekadashi ' beginning of the monsoon season till beginning of winter.
From that day on, each year, during the monsoon, at Purnima, brothers invite their sisters to come home and have a meal with them. The sister prays for his long life, health and prosperity. As a token of this, she ties a rakhi on his wrist. The sister returns the compliment at Divali when she invites him to dine with her at Bhai Bij.