A spit is connected to the shore on one end, and the other end is in the ocean. A sandbar is close to the shore, but it's not connected to the shore. They can be underwater or poking out of the surface.
Here are some images to help you get the idea:
Spit-
Sandbar-
sandbar
a tombolo is a spit that joins the mainland to an island
A spit is formed by deposition. A spit is a long, narrow sandbar that extends from the shoreline into open water, created by the deposition of sediment carried by longshore drift.
The difference is that a spit is that one end of a spit is connected to the shore, and the other end is in the ocean. A sand bar is close to the shore, but is not attached to it. Sandbars can be underwater or poking out of the surface of the ocean. Below are some links for images to help you get the idea.
An elongated strip of sand is called a sandbar or a spit. Sandbars typically form offshore parallel to the coast, while spits are landforms that extend into open water from a shore.
beach, spit, sandbar, barrier beach, headland, wave-cut cliff, sea arch, sea cave, and sea stack.
A sandbar is a deposition of sand.
A "sand spit" is an elongated line of sand (or sandbar) that usually extends parallel to the shore, connected to the mainland. If it grows high enough to survive tides, it can become a peninsula. If it is separated from the land after forming, it can become an offshore barrier island.
There was a sandbar on the side of a lake
This is the definition of a "barrier spit". (A tombolo is a sandbar that connects the mainland to an island, forming a permanent or temporary isthmus, and the island can be known as a "tied island".)
Sandbar Sinister was created in 1934.
Sandbar Fight happened in 1827.