When we hear the word Brahmacharya, the idea that comes in our mind is that whoever practices Brahmacharya is the person who does not engage in any kind of sexual activity. We are also told that everyone should practice Brahmacharya until they attain the age of 25 years. Especially if one is a student who is right now receiving knowledge.
So the fundamental idea behind the concept of Brahmacharya is celibacy and it is understood that by practicing it one receives spiritual merit and becomes successful in life. However, in reality the idea of Brahmacharya is not just limited to celibacy, it is more complicated. The association of Brahmacharya with celibacy is something that developed later on in time. If you go further back in time, you realize that Brahmacharya is more than just celibacy.
If you look at the word Brahmacharya, you can break it down into Brahma(ब्रह्म)+Charya(चर्य). Here Brahma (ब्रह्म, Actually Brahman if you use the IAST standard for transliteration) is the absolute God head in Hinduism which is manifesting as this entire creation. NOTE: Do not confuse it with Brahmā (ब्रह्मा), the deity who is part of the Hindu trinity as creator of this universe. And Charya(चर्य) means routine, or how you conduct yourself in life. So the word Brahmacharya means the conduct in life which is consistent understanding Brahman.
This word is similar to the word Dincharya, which means the routine one follows during a day (Din(day)+charya(routine)). Just as we are prescribed a good routine for our day, where we are recommended to get up early in the morning, meditate for sometime, then clean yourself, then eat breakfast, then go to work and on and on. Similarly following Brahmacharya means how one should conduct in life to attain Brahman. Therefore, whenever someone lives his/her life in a manner which takes him/her closer to Brahman then he/she is actually practicing Brahmacharya. It is only later that Brahmacharya specifically started meaning complete abstention from any kind of sexual activity.
If you read the Chandogya Upanishad, there this has been explained quite specifically. In the fifth section of the eighth chapter of Chandogya Upanishad, the very first shlok clearly defines Brahmacharya as “यद्यज्ञ इत्यचक्षते ब्रह्मचर्यमेव” which means “Trying to perform Yagya(Sacrifice) is told to be Brahmacharya itself”. Now, we know that Chandogya Upanishad is one of the oldest Upanishads and therefore the idea present in Chandogya Upanishad is the most original idea of Brahmacharya. So from this it is clear that originally Brahmacharya was peerforming Yagya itself.
Yagya here is not just limited to performing fire sacrifice or Havan. Yagya over here means the complete conduct of a human being to strive to be pure in life, free from imperfections. If you read the Chandogya Upanishad further, it mentions that attaining self knowledge is also Brahmacharya. There are many different kinds of Yagya been mentioned subsequently in Chandogya Upanishad, which are also told to be Brahmacharya. All of this makes it clear that originally Brahmacharya meant the practice of complete routine which makes one pure and near to God.
Since sexual activity can distract you from your path therefore in later times Brahmacharya got associated with celibacy. This is especially important for those students who are reaching puberty. At that age hormonal changes in ones body makes them especially susceptible to this. The sexual energy can take control of a youth at this age and he/she might end up taking a misstep. In order to prevent such a thing from happening, it is natural that they were told to abstain from any sexual activity and therefore told to practice Brahmacharya. Once the youth passed that age and gains maturity then they were allowed to enter Grahast Ashram (domestic life) and raise a family. As now they have a good understanding of things and can choose the right kind of life partner. When a person has good life partner, he/she lives a happy life and moves closer to God.
When one enters Grahast Ashram, the main aim is to raise a family and therefore to create offspring one has to have a sexual intercourse. However as long as the person only has the sexual intercourse with his/her life partner then also it is considered Brahmacharya. So overall what we must understand is that any activity that we perform to get near to God is Brahmacharya, be it Karma Yoga, Bhakti Yoga, Raj Yoga or Jnana Yoga. It is only much later in time that the idea of Brahmacharya was just limited to Celibacy. Of course practicing Celibacy is a major part of the practice of Brahmacharya, as it purifies our mind, however originally Brahmacharya was a much wider idea with a bigger scope then what it currently entails.