What is the ruling of giving salam?
Alhamdulillah, praise and gratitude to Allah SWT for His countless blessings for us all. Praise and salutations to our beloved Prophet Muhammad PBUH, his family, companions, and all those who follow his footsteps until the Final day.
Salam is a greeting of peace and harmony to acknowledge other Muslims. The usual phrase is assalamualaikum, salam and other greetings. Allah SWT states:
وَإِذَا حُيِّيتُم بِتَحِيَّةٍ فَحَيُّوا بِأَحْسَنَ مِنْهَا أَوْ رُدُّوهَا ۗ إِنَّ اللَّـهَ كَانَ عَلَىٰ كُلِّ شَيْءٍ حَسِيبًا
“And when you are greeted with a greeting, greet [in return] with one better than it or [at least] return it [in a like manner]. Indeed, Allah is ever, over all things, an Accountant.” 
In interpreting this verse, Syeikh al-Sa’di stated in his book: A greeting is a phrase uttered and answered by a person in honouring and supplicating goodness for him. 
Maliki scholars stated the majority of Muslims are of the opinion that giving salam is sunnah while answering it is obligatory according to this verse.
Ibn al-Arabi cited the opinion of one of the Maliki scholars, Abdul Wahhab who said: Giving and answering salam is fardu kifayah if one is in a part of a group. Thus, giving salam is obligatory towards a person one knows and sunnah if the other person is someone he doesn’t know. The reason is if the other person is someone he knows if he doesn’t give salam to him this might hurt the other person’s feelings. The discussion regarding giving salam by a person who is standing to a person who is sitting, a person who is walking to someone stationery, fewer people giving salam towards a crowd, a younger person towards an older person and other situations are explained in the hadiths of the Prophet PBUH. 
Among the hadiths of the Prophet PBUH that narrate the advantages of “salam” and its commandment in spreading it is a narration from Abdullah bin Amr bin al-Ash RA, he said:
أنَّ رجلًا سأَل النبيَّ صلَّى اللهُ عليه وسلَّم : أيُّ الإسلامِ خيرٌ ؟ قال : تُطعِمُ الطعامَ، وتَقرَأُ السلامَ، على مَن عرَفتَ، وعلى مَن لم تَعرِفْ
A man asked the Prophet, “What Islamic traits are the best?” The Prophet said, “Feed the people, and greet those whom you know and those whom you do not know.” 
Originally, the ruling of giving salam is sunnah and this is the opinion in madhhab Maliki, Syafie and Hanbali. While answering salam is obligatory and if the salam is given to a group of people then it is fardu kifayah on them. 
Furthermore, Imam al-Nawawi stated in his book: The ruling of greeting with salam, is sunnah muakkad. As for answering salam, it is obligatory according to ijma’. If a person gives salam to another person, the other person is obligated to answer it for it is fardu ain for him. Whereas, if the salam is given to a group of people, answering it is fardu kifayah. 
To close, let us all maintain and continue this sunnah of giving salam for it is encouraged in this religion. May Allah SWT give us strength in practising the sunnah of the Prophet PBUH and protect us from the attributes that are disliked by Allah SWT and Rasullullah PBUH. Amin.