I always thought the SGD was a loss function then I read this on a notebook

```
model.compile(loss="sparse_categorical_crossentropy", optimizer=keras.optimizers.SGD(lr=1e-3), metrics=["accuracy"])

```

now I am confused what's the difference between loss and optimizer ? are they both used at the output layer to calculate the loss?
or is the optimizer something used in each layer?