When standing in front of a scene you’d like to capture photographically an early decision that needs to be made is how to frame the image.
If you’re using a fixed lens (single focal length) you have to move your physical position relative to the subject in order to adjust the framing of the composition. This is kind of a human-zoom; you walk forward to zoom in or backward to zoom out.
When using a camera that has a zoom lens you have the capability to adjust the framing of the scene without physically moving yourself. This series of images illustrates the effect of zooming in on a subject.
(Published by Nikon in Understanding Focal Length, https://www.nikonusa.com/en/learn-and-explore/a/tips-and-techniques/understanding-focal-length.html)
Optical vs Digital
Digital cameras use a image sensor to capture the viewed image. Light from the subject passes through the lens and falls upon the sensor which interprets the light and captures the image. The sensor is comprised of thousands of pixels, each capable capturing a single point of light and color to be used in the rendered image. The size and density of the pixels on the sensor have a direct effect on the quality of the resultant image.
Many lower-end cameras offer two types of zooming: optical and/or digital. Optical zooming alters the resultant image using the physical capabilities of the lens to optically alter the view area to be captured. If the camera is capable of taking a 12 megapixel (MP) image, all images captured using the optical zoom will be 12 MP in size.
Digital zoom is different. If you use digital zooming the result is a smaller number of captured pixels and therefore a smaller image, perhaps only 10 or 8 MP. The camera accomplishes digital zoom by excluding pixels on the edge of the sensor and only capturing information from the pixels in the center. The end result of using digital zoom is as if you took a full sensor image and cropped the result later using image processing software (e.g. Lightroom).
Some cameras include software that will automatically expand a digitally zoomed image to match the pixel count of a full-size image (in the case discussed here: 12MP). The full-sized image is built off the reduced set of pixels from the center of the sensor and can only provide the resolution/detail available in those pixels. Again, the same results can be achieved post-capture using a full-sized image and image processing software.