How Do Machine Learning Models Work and Remember?
ML algorithms all learn a set of numbers associated with whatever model you're training. For a neural network, it's the weights on the network links. For regression, it's the coefficients. And so on. These numbers you can store and use later (most ML libraries have utilities for doing this). You use the coefficients to make predictions on data on which you have NOT trained the model.

The ML algorithm uses some sort of optimization for learning the coefficients. It might be gradient descent, or stochastic gradient descent, or xgboost, or any of a number of optimization algorithms. These are typically used to minimize a cost function. The definition of that cost function is model-dependent.