Atoms, the building blocks which make up our universe, are made up of 3 important elements: the proton, the neutron and the electron. You may have recognize this image from the Big bang Theory.
The protons are the particles in red and have a positive electric charge, the neutrons in blue and have no charge. Together they comprise the nucleus. The grey particles are the electrons, which have negative charge, and attracted to the protons, much like the moon is attracted to the Earth. They execute an orbital motion around the nucleus.
When a very high energy ray of light comes near an atom, it has a chance to spontaneously disappear and leave behind an electron and a positron (the antimatter counterpart of the electron. Like an electron, except with a positive charge). This is called pair production. At first glance, this is a very strange prospect, that a ray of light can spontaneously turn into matter and antimatter. But this process obeys all of the laws of physics (obviously, because it happens), i.e. conservation of momentum, conservation of charge and conservation of energy. Conservation of energy is achieved when you take into account the rest energy of the proton and the electron.
Einstein figured out that matter is a form of bundled up energy, which is described by the famous equation E = m, which says that the energy from an electron or a positron existing is equal to its mass multiplied by the speed of light squared. So if the energy of the light ray is more than twice m, with m being the mass of the electron or positron (both have the same mass), then conservation of energy is satisfied.
The figure above shows the light ray coming from the left near the atom, and transforming into the electron positron pair on the right. So it obeys the laws of physics, but why does it happen? And why does it have to happen near an atom?
Well it has to happen near an atom due to a subtle interaction between the atom and the light ray. Every atom produces electromagnetic fields, which the ray interacts with. The result of this interaction is probabilistic, the probability is determined by taking into account the total number of possible outcomes. It turns out, through the study of a field called quantum electrodynamics, that the probability that pair production occurs depends on the energy of the light ray, the higher the energy the more likely, and with the square of the number of protons in the nucleus, again, the more there are, the more likely. This interaction with the atom through its electromagnetic field includes it in the equation for the conservation of energy and momentum, which is why it is seen in the figure to have an extra momentum after the interaction.
Pair production is also a process which can happen backwards, in a process called pair annihilation. If you imagine running the process in the graph above backwards in time, i.e. the electron and the positron run into each other near an atom and annihilate each other to create a gamma ray, with all of the various conservation laws being obeyed.
Image 1: Big bang theory: Why Leonard & Sheldon Spent exactly 139.5 hours rebuilding the model, https://screenrant.com/big-bang-theory-leonard-sheldon-139-hours-model-why/ , Accessed May 2020
Image 2: Conversion of energy into mass, https://www.jick.net/~jess/hr/skept/EMC2/node9.html , accessed May 2020