A sentence is "illegal" if it is "inherently illegal", as opposed to "procedurally illegal". A "procedurally illegal" sentence arises from a flaw in the procedure of your trial; i.e., a factually inconsistent verdict and double jeopardy. An "inherently illegal" sentence inheres in the sentence itself, and includes sentences that
a. The maximum sentence permitted by law, or
b. If you pled guilty, the maximum sentence permitted by the language of the plea bargain or agreement of the parties and court.
2. Imposed as a penalty for a crime(s) that you were not convicted of,
3. Are ambiguous (this is rare), or
4. The Honorable Charles E. Moylan, Jr., says are illegal (just kidding).
If your sentence is inherently illegal, you can file a motion, as Maryland Rule 4-345(a) states, "at any time", in the court where you were sentenced. Thus, you don't have to object to the sentence when it is imposed to make the motion later. In fact, the motion can even be filed after both your appeal and post-conviction petition are denied, and you are entitled an appeal on the motion to the Appellate Court of Maryland (formerly the Court of Special Appeals) if it is denied. But, most importantly: