[Dusts off TNG Technical Manual]
Right then, let’s get into this.
A Replicator does not convert energy directly into matter. This is a misconception. Rather, a replicator uses technology similar to that of a transporter to materialise a source of matter into one of a number of pre-programmed forms on a molecular level. This does require a considerable amount of energy (not to mention processing power), so to conserve power, replicators draw from specific matter sources depending on what is being replicated.
Aboard a starship, this creates two categories of replicator: tool replicators which produce inorganic objects like tools, spare parts, etc., and food replicators which can produce organic materials such as food. Food replication is the more complex of the two, with replicator patterns for food containing a variety of complex molecules to synthesise and arrange. Most sickbays are equipped with a medical replicator as well, which is essentially a modified food replicator equipped to produce commonly-used medicines.
The power and storage requirements of a replicator are, however, orders of magnitude less than the logistical problems of carrying large amounts of things required on a routine basis, and especially the energy and storage cost of large amounts of perishable food and potable water. A Galaxy-class vessel’s food replicators can produce 4,500 types of food, while requiring only about 0.5% as much storage and power as that variety of food would require to carry.
Technically speaking, the replicators seen on-screen are just local terminals connecting to a wider network - a ship will have central matter sources that feed the entire replicator network (so you can get plates, cups, and cutlery with your food). However, a small food replicator is about the size of a fridge, and probably forms a core of a home kitchen for many people (once hooked up to the power supply), so long as you keep the matter source supplied. For tools, the matter source is going to be similar to Omni-gel in Mass Effect - a mass of plastic, metal, and ceramic compounds in suspension which can be assembled as required into a variety of configurations. For food, a sterilised slurry of proteins and other organic compounds is used instead. In either case, the matter source is designed to require the bare minimum of molecular manipulation in order to turn it into the end product. This is normally resupplied at a starbase, but reclamation and recycling of waste is part of the normal process to make the supply last longer. A replicator can use other matter sources, but the power cost is higher.
Pattern complexity is the next concern.
Transporters can operate at two resolutions: molecular, and quantum. Quantum resolution scans, dematerialises, and rematerialises you down to the subatomic level, and is safe for transport of living creatures, but it requires at least an order of magnitude more energy and computing power to process, and the complexity of a transporter pattern at that resolution is too vast to store away (so they’re deleted shortly after use). Molecular resolution transport is used for cargo and other things where minor subatomic variances are not of consequence, because it’s faster, less resource-intensive, and allows more to be transported at once - the scan doesn’t need to be as detailed, which makes everything easier (this is also why transporters were used for cargo for years before they were approved for personnel transport).
When a replicator materialises something, it’s operating at molecular resolution. But there are also processing tricks and methods of data compression so that replicator patterns are as small as possible - a molecular “averaging” conceptually similar to how a jpeg image doesn’t record a colour for every single pixel individually, but groups areas together and says “these are all blue”. This reduces the ‘file size’ further, allowing for a wider variety of patterns to be stored. Starfleet also modifies food patterns to improve nutritional balance. So, that bacon cheesburger you replicated is assembled from a sterile organic slurry according to an averaged, nutritionally-balanced pattern stored in the computer.
And in practice, the difference between that and the real thing is so small as to be virtually undetectable. Some people say they can taste the difference, but that might partly be snobbery.
Some substances, however, cannot be replicated - they require precision that a replicator is not equipped to produce. In some cases, this is obvious - a replicator cannot produce a living thing (only a dead version of that thing), so you find fewer replicators on Klingon ships because they prefer live food (replicated gagh just sits there in the bowl, the real stuff wriggles and squirms down your throat), including bringing along livestock like Targs to butcher. In others, there are risks - some Altarian spices become mildly toxic if replicated, presumably because of some subatomic variation. In others still, like latinum or dilithium, the material composition is too specific to be replicated effectively - a replicated version can easily be determined to be fake, or simply won’t work as needed.
(Though, on the subject of living tissue, by at least 2371, it was at least theoretically possible to use a specialised replicator to clone living organs, but this would require having the subject there to scan, it takes a lot of energy and computer power, and is extremely complex in general, as it’d be a quantum resolution creation; we see this in Voyager, where it’s considered as a possibility to replace Neelix’s stolen lungs, but dismissed due to their relative lack of familiarity with Talaxian physiology)
Similarly, some items may be too complex to replicate. It may be possible to replicate components separately and assemble them by hand, but this obviously takes time and skill.
Additionally, some objects cannot be replicated because they’re disallowed - a replicator is not permitted to create poisons or weapons, for example.
As an aside, a starship has the means to produce antideuterium (the form of antimatter used as fuel) out of deuterium, but the process is inefficient and normally only used when fuel reserves are critically low and there’s no available tanker or other refuelling facility.