un is the indefinite article, meaning “a cake.” You use it when you’re introducing something new or unspecified.
le is the definite article, “the cake,” used when the cake is already known to the listener:
• Je prépare le gâteau que tu as commandé. (“I’m preparing the cake you ordered.”)