The main difference between the two is whose fault that error is. A 4xx code indicates an error caused by the user, whereas 5xx codes tell the client that they did everything correctly and it’s the server itself who caused the problem.
When should we return 4xx or 5xx status codes to the client?
4xx codes are used to tell the client that a fault has taken place on THEIR side. They should not retransmit the same request again, but fix the error first.
5xx codes tell the client something happened on the server and their request by itself was perfectly valid. The client can continue and try again with the request without modification.
difference error server