What happens when you break the rules while flying?
When you break the rules while flying, it falls into one of two categories:


Only you know about it
The FAA knows about it


In either case, the very first thing you do is file a NASA ASRS form.  You might ask, why does NASA care about airplanes?  They are acting as an uninterested 3rd party to your actions, and collate statistics from this information.  If the FAA becomes aware of your actions, the presence of an ASRS form in many cases limits the action the FAA can take against you.  It is always worth filling out and I have filled out a few myself.

In the case the FAA knows about it, how do they know about it?  This typically happens when you are in radar control and do something wrong or are on the ground and do something wrong.

Some examples of this are:


Flight plan in the FMS is incorrect and you make a turn off of your cleared course.  The controller will see this.
You taxi incorrectly 
Runway incursion 
Climb / descend through your cleared altitude


In most of these cases, the controller will just correct you.  In cases that result in a loss of separation or a runway incursion, you may get a phone number from the controller to call when you land.

Less commonly, something you do may be witnessed by an FAA inspector -- you buzzed the tower when he was on the ramp watching you.  Or perhaps he watched you get into a plane and fly off without performing a pre-flight inspection.  Perhaps you were ramp checked and something wasn't right with you or the airplane.

In all of the above cases, if you are able to file an ASRS form, do it.  If you do something that may be severe and are a member of AOPA, call their legal team and discuss the situation. 

If the FAA responds to something they know about, it can range from a controller talking to you over the phone up to certificate action (suspension, revoked) to the infamous "709 ride", in which the FSDO administers a checkride and decides which, if any, ratings you keep and which you lose.