Throughout the various editions of the game, the cosmology of the D&D settings has changed here and there. For example, the cosmology for the Forgotten Realms setting got completely rebooted in the 3rd edition of the game, and was rather different from the one that you will read below. It was a much more simplified cosmology with the Outer Planes likened to a metaphysical tree whose branches mostly comprised the realms of the deities.
However, since the original tag for the question is "lore", I will describe the "Great Wheel Cosmology". This cosmology is the one referenced most often throughout the history of the game going as far back as 1987, when the original Manual of the Planes was published for AD&D 1e. The 5th edition material published so far also describes most of the components below, with the exception of crystal spheres and phlogiston (though their existence in 5e is implied by Mike Mearls in this tweet).
World: Forgotten Realms setting takes place on a continent called Faerûn on the planet Toril. There are many kingdoms, city-states, etc. on this continent, such as Corymr, Sembia, Amn. Toril is the third planet on a star system.
Crystal Sphere: Toril's star system is located within a "crystal sphere" called Realmspace. Much like how various ancient cultures envisioned it, the stars are actually points of light (possibly gates to the elemental plane of fire) that are embedded inside a solid spherical shell that surrounds the star system.
Phlogiston: Crystal spheres are embedded in some material called phlogiston. Travel through the phlogiston is possible through spelljamming ships. Other D&D worlds, such as Oerth (planet for the Greyhawk setting) or Krynn (planet for the Dragonlance setting) are embedded in their own crystal spheres (Greyspace, Krynnspace, etc.).
Prime Material Plane: All the crystal spheres together make up the prime material plane. For an average commoner, her own crystal sphere is her universe (for example, even the deities she worships can be single-sphere powers); while an informed sage could consider the entire prime material plane as "the universe". Everything in the prime material can be considered to be composed of two kinds of essential components: matter and soul/belief.
Inner planes: Fire, earth, water and air are the four basic elements (fundamental building blocks) of matter. Along with the positive (life) and negative (undeath) energies, these elements are the substance of everything in the material universe. Each of these elements and energies can be found abundantly in "pure" forms in so-called inner planes. These are essentially locations outside of our "normal universe" with an infinite supply of their respective stuff. Inner planes are connected to the prime material plane through a conduit plane called the Ethereal plane.
Extradimensional spaces: These are pockets of space (empty or filled with matter) of various sizes that are embedded in the Ethereal Plane. For a magical item that has a much larger inside volume than seen from the outside, like a bag of holding, the extra volume is quite often such an extradimensional space.
Dimension: If you likened the prime material plane to a 2-dimensional sheet of paper, the Ethereal Plane would be like a block resting on that sheet, with one face touching the prime's every location. Within that block, the regions that are closest to the prime are called the 'border ethereal'. Quite often the features of the border ethereal resemble the locations in the prime material that they are in contact with; it is even possible to have entire realms extending deeper into the ethereal, looking just like distorted/modified reflections of the prime. Examples of such "dimensions", are the Feywild (Plane of Faerie) and Shadowfell (Plane of Shadow). In earlier versions of D&D, all these locations would generally be called 'demiplanes', in 5e the word demiplane seems to refer to somewhat smaller domains in the Ethereal Plane. (For example, the Demiplane of Dread, ie. the location for the setting Ravenloft, is accessible from the remote reaches of Shadowfell.)
Outer planes: All of the "belief", stuff that we generally associate with whatever lies beyond matter, such as good/evil, chaos/law, and many of the realms of the deities, etc., get some sort of concrete existence as the 17 outer planes. There is one outer plane for each alignment (LG to CE), as well as one plane between any non-neutral alignments (for example between LG and NG). Various planar beings that the embodiments of their respective alignments (like demons and angels, etc.), as well as the petitioners ('souls' that depart the prime material plane when people die), can be found in these outer planes. When you cast a Raise Dead spell, you are effectively bringing a petitioner back into her prime material body. Outer planes are connected to the prime material plane through a medium called the astral plane.
Multiverse: All the above listed planes of existence make up the multiverse. Except for the prime material plane, all the other planes have their own rules for (meta)physics. Travel between the planes is possible only through magic (magic portals, gates, or powerful spells like Planeshift).
PS: You can watch Mike Mearls describe some of the topics described above in a video here on D&D Beyond. (Thanks to @DavidCoffron for the pointer.) Further details can be found in the second chapter of the Dungeon Master's Guide.
Regarding the definition of realm, it is used as a generic word in many different contexts, describing a dominion or a sphere of influence or a country. For instance we can talk about the elven realms in Evermeet, deity Mystra's realm in the outer plane of Elysium, etc. You can even hear people refer to entire planes or crystal spheres as realms. Some of Toril's inhabitants call their world "The Realms", while we additionally use the adjective "forgotten" in the name of the setting to indicate that we (those of us living on Earth) used to have regular contacts with Toril in the past, but mostly forgot about their existence later.
Far Realm: Introduced in The Gates of Firestorm Peak, a 2e module published in 1996, the Far Realm is another multiverse, completely alien to our minds. Some creatures of type 'abberration' such as aboleths and beholders are said to originate from or get influenced by the Far Realm.