Let me just begin with saying that noble peerage is amazingly complex and varies from culture to culture.

Put simply, a noble is a governor with military responsibility. They are given a piece of land over which they are responsible for keeping the peace and the law, in return they are given permission to tax these lands. These taxes are then supposed to be divided between supporting the noble and his soldiers, paying tithe to their liege and taking care of their lands.

The feudal ladder works in a way that nobles swear fealty to their liege, which means they promise to serve as part of that noble's armed forces but in return that noble promises to protect them.

So a count will have a number of barons under him, these barons have sworn oaths to assist the count when he calls for them but he is responsible for protecting them and their rights. This goes all the way through the ladder up to the king (or emperor).

Put crudely, the ladder goes:
Lower Nobility
Free men and women, Burgers

But as mentioned, this is a crude approximation. It is almost infinitely more complex system. But the basics of the system is that it's about delegating responisibility.
Villages will have knights (lesser nobles) protecting them, these knights are banded together under the lowest tier of high nobility (baron, freiherr, friherre, etc.).
These nobles are banded together under the mid tier (counts, graf, greve, etc.) whom in effect rule small nations with a force of several hundreds of men.
These in turn band together under the highest tier (duke, fürst, hertig, herzog, prince, jarl) whom in essence run small countries. The mightiest of dukes (or more correctly, the duke with the most might backing him) is essentially "chosen" to be the king.

Then there's all the special titles. Like Marquis (marquess, marcher lord, markis), which is a count entrusted to protect the civilised lands ("the empire") from barbarians and thus granted extra military authority.
Or emperor: "The king of kings".
Or baronet... which seems to be a lesser baron.

As mentioned above, each culture has it's own titles, responsibilites and laws regarding this. Souther France was different from Northern France. Saxon England different from Norman England. China and the Byzantine empire for instance were much more bureaucratic in it's approach. With titles being more offices of the imperial authority than inhereted warlord titles. In pre-Vasa Sweden, a lot of titles were elected. Hungary and Croatia was apparently running their own things.

Basically... if you don't want to make it too complex. Set up three tiers of nobility (and royalty above them). Give them names you find appropriate and set up a basic pyramid. Each level derives their power from the total number of men under them. There you go.

As for your second question.
A castle is a military fortification. They are always built to protect something. A river crossing. An important settlement. A safe harbour. A narrow valley. A trade route.
If a lot of trade mover through the castle, then a town will sooner or later emerge. Once it grows big enough, sooner or later someone will want to build a wall to be able to toll the goods moving in and out.

Simply put.

And yes, a baron can absolutely hold something that important for the king. The king could easily have established himself as the count of that area (it's perfectly possible to hold multiple titles).
In fact, it's probably more likely for a baron to hold that rather than a duke. Because a baron would never hold enough territory to challange the king on his own.