The Kalman filter is a tool designed primarily to estimate the values of the 'state' of a dynamic system in time. There are two main equations. These are the state equation, which describes the behaviour of the state over time, and the measurement equation, which describes at what times and in what manner the state is observed. For the discrete Kalman filter, discussed in this paper, the state equation is a stochastic difference equation that incorporates a random component for noise in the system and that may include external forcing. The measurement equation is defined such that it can handle indirect measurements, gaps in the sequence of measurements and measurement errors. The Kalman filter operates recursively to predict forwards one step at a time the state of the system from the previously predicted state and the next measurement. Its predictions are optimal in the sense that they have minimum variance among all unbiased predictors, and in this respect the filter behaves like kriging. The equations can also be applied in reverse order to estimate the state variable at all time points from a complete series of measurements, including past, present and future measurements. This process is known as smoothing. This paper describes the 'predictor-corrector' algorithm for the Kalman filter and smoother with all the equations in full, and it illustrates the method with examples on the dynamics of groundwater level in the soil. The height of the water table at any one time depends partly on the height at previous times and partly on the precipitation excess. Measurements of the height of water table and their errors are incorporated into the measurement equation to improve prediction. Results show how diminishing the measurement error increases the accuracy of the predictions, and estimates achieved with the Kalman smoother are even more accurate.