A zigzag stitch is variant geometry of the lockstitch. It is a back-and-forth stitch used where a straight stitch will not suffice, such as in reinforcing buttonholes, in stitching stretchable fabrics, and in temporarily joining two work pieces edge-to-edge.
When creating a zigzag stitch, the back-and-forth motion of the sewing machine's needle is controlled by a cam. As the cam rotates, a fingerlike follower, connected to the needle bar, rides along the cam and tracks its indentations. As the follower moves in and out, the needle bar is moved from side to side. Sewing machines made before the mid 1960s mostly lack this hardware and so cannot natively produce a zigzag stitch, but there are often shank-driven attachments available which enable them to do so.
Older sewing machines which only sew a straight stitch can be adapted to sew a zigzag by means of an attachment. The attachment replaces the machine's presser foot with its own, and draws mechanical power from the machine's needle clamp (which requires the needle clamp to have a side-facing thumbscrew). It creates a zigzag by mechanically moving the fabric side to side as the machine runs.