A knight on d2 has six squares: b1, b3, c4, e4, f3 and f1. Two of them, b1 and f1, are behind it, back towards White’s own first rank, and both are perfectly ordinary legal moves.
g The L works in all eight directions with no preference for any of them. From a central square like e4 the knight has four squares in front (c5, d6, f6, g5) and four behind (c3, d2, f2, g3), an exact split. Left and right work too, though every knight move changes rank as well as file, so there is no such thing as a purely sideways hop along a rank.
Going backwards on purpose
New players treat a retreat as an admission of failure. Strong players do it all the time, and the most famous example is a knight that goes backwards twice.
In the Ruy Lopez, White plays Nb1-d2, then Nd2-f1, and only then Nf1-g3. Two of those three moves head towards White’s own back rank, and the point is the destination: from g3 the knight supports f5 and h5 and joins the kingside, work it could never do from b1. Three tempi spent on one piece, deliberately, in one of the most respected openings there is.
The same instinct shows up in tactics. When a puzzle looks stuck, the answer is often a piece stepping back rather than forward, which is exactly what quiet move puzzles are built from.
The piece that cannot do this
Every piece on the board can retreat except one. Kings, queens, rooks and bishops all go backwards without a second thought, and so does the knight. The pawn cannot, which is the reason a knight on the rim is a problem you can fix in two moves and a hole in your pawn structure is a problem you live with.
So when your knight lands somewhere and gets kicked by a pawn, do not force it forward into a worse square. Count the squares behind it. Half of a knight’s options are back the way it came.