Loss functions is a method of evaluating how well specific algorithm models the given data. If predictions deviates too much from actual results, loss function will compute a large positive number. Gradually, with the help of some optimization function, the model will make better predictions and reduce overall loss.
The cost function is the average of the losses. You first calculate the loss, one for each data point, based on your prediction and your ground truth label. Then, you average these losses which corresponds to your cost.