You get feats when you reach level 4, 8, 12, or 19 in any class in 5e. Fighters can also get feats at 6th- and 14th-level, and Rogues can also get feats at 10th-level.

The important point is that whenever you reach a class level that gives you an Ability Score Improvement, you can forgo at that option and choose to get a feat instead.

Some feats also have prerequisites, like a minimum ability score or the ability to cast spells.

For multiclassers, it’s also important to remember that Ability Score Improvements (and therefore feats) are based on class level, not character level.

For example, if you are a Paladin 2/Fighter 2, you do not have access to any feats, even though your character level is 4. That’s because you have not earned level 4 in one particular class, so you don’t have access to any Ability Score Improvements, and therefore feats, yet.

Player’s Handbook, page 163-5

Here’s a table of when each class gains access to feats:

4th-level 6th-level 8th-level 10th-level 12th-level 14th-level 16th-level 19th-level
Artificer
Barbarian
Bard
Cleric
Druid
Fighter
Monk
Paladin
Ranger
Rogue
Sorcerer
Warlock
Wizard

1st-Level Feats

Variant Humans can choose a feat at 1st-level and increase two different ability scores by 1 each (PHB 31).

If your table uses the Custom Lineage optional rule from Tasha’s Cauldron of Everything, you can choose a feat at 1st-level in addition to increasing one ability score by 2 (TCoE 7).

Racial Feats

Many races have Racial Feats listed in Xanathar’s Guide to Everything. These aren’t gained at a particular level, but rather when a “transformational” moment happens that brings a character closer to their character’s lineage (XGtE 73).

dungeons and dragons orcs vs party minis