The main component of the cell membrane is a phospholipid bi-layer or sandwich. The heads (the phospho part) are polar while the tails (the lipid part) are non-polar. The heads, which form the outer and inner linings, are "hydrophilic" (water loving) while the tails that face the interior of the cell membrane are "hydrophobic" (water fearing). Water is attracted to the outsides (red) of the membrane but is prevented from going through the non-polar interior (yellow) layer.
The membranes of the cell are semi-permeable. That means that while most things are effectively kept in (or out), some can pass through directly. So how do cells move things in and out? There are three methods.
1. Diffusion: If a molecule is very small, such as oxygen or carbon dioxide, diffusion does the trick. When the concentration of O2 outside the cell is higher than inside, O2 molecules diffuse in, passing through the membrane like it isn't even there. Similarly, when the concentration of the waste gas CO2 builds up inside the cell, it escapes naturally to the outside where the concentration is lower. Diffusion requires no expenditure of energy by the cell. It happens passively. While nature figured this out a long time ago, we now make fabrics and medical devices that copy this process. Gore Industries, one of the big employers in Flagstaff, makes a fabric called "Gore-Tex" which repels large water droplets but allows smaller air molecules to pass through, making the fabric "breathable."
The catch: While diffusion works well for the tiny single cell, it does not, by itself, get the job done in a multi-cellular organism where the tissues are buried deep inside the body. Imagine your bicep muscle while you are lifting weights. The tissue, comprised of millions of cells, will quickly run out of oxygen and build up carbon dioxide. Diffusion through the skin could not keep up. This is where the circulatory system helps out. The smallest blood vessels, the capillaries, run though these tissues. The blood from the lungs releases oxygen to the cells (because O2 is at lower concentration in the tissues), and picks up carbon dioxide (because CO2 is at higher concentration in the tissues) and carries it back to the lungs to be exhaled. This does require energy. It also explains why your breathing rate increases when you exert yourself, and is one of the costs of being multi-cellular.
2. Active Transport: Sometimes diffusion doesn't happen fast enough for the cell's needs, and there are times when nutrients need to be stockpiled or excreted at a higher concentration than would occur naturally by diffusion. In this case, the cell uses energy to pump good things in, and bad things out, through protein channels or gates. This process is called active transport.
3. Endocytosis: Sometimes, a large object needs to be moved in or out of the cell, but it's too big for the door. Think about moving a couch into your apartment and you will get the idea. But you can't just cut a hole in the cell membrane or all the good stuff inside would leak out, so how do you get something in without letting your interior be exposed to the exterior? The cell has a special trick that probably dates back to the days when all life was single celled, and this was how cells ate. The single celled Amoeba still consumes its food this way. It's called endocytosis, and it works like this. Note in particular that the engulfed food item is gradually enclosed in an "inside-out" section of the double-layered membrane, Pac-Man style! Once the food particle is completely surrounded, the exterior membranes fuse and the interior vacuole pinches off. By this method, the interior of the cell is never directly exposed to the exterior environment. The one side effect of this trick is that the membrane is now inside out, and that's interesting because it gives us a clue about the origins of the cellular organelles.
Note that the vacuole has its membranes reversed! (Black outer and red inner)