The passive voice is used to show interest in the person or object that experiences an action rather than the person or object that performs the action. In other words, the most important thing or person becomes the subject of the sentence. Eg: The house was built in 1654. (= we are interested in the house, not in who built it.)
Sometimes we use the passive voice because we don’t know or do not want to express who performed the action. Eg: I noticed that a window had been left open.
The passive voice is often used in formal texts. Switching to the active voice will make your writing clearer and easier to read. Eg: Our planet is wrapped in a mass of gases.
If we want to say who or what performs the action while using the passive voice, we use the preposition by. When we know who performed the action and are interested in him, it is always better to switch to the active voice instead. Eg: “A Hard Day’s Night” was written by the Beatles.