Background Accurate needle placement is crucial during minimally invasive procedures such as biopsies, regional anesthesia, and fluid aspiration. 2D Ultrasound is widely used for needle guidance during such procedures, however, it has a limited field-of-view and poor needle visibility for steep insertion angles. Methods In this work, we propose a novel machine learning (ML)-based method for real-time needle segmentation in handheld 2D ultrasound systems. The proposed method involves a fast and simple annotation technique allowing for the labeling of large datasets. It then utilizes the U-Net architecture which is modified to allow for easy integration into a handheld ultrasound system. Two datasets were used in this work, one consisting of B-mode ultrasound videos obtained from human tissue and the other consisting of videos and frames from chicken, porcine and bovine tissue. The model is trained on 1262 frames and evaluated on 209 frames. Results This approach achieves an Intersection Over Union (IoU) of 0.75 and a dice coefficient of 0.851 on frames obtained from human tissue. The model is integrated into the processing pipeline of a portable ultrasound system and achieves an overall processing speed of about 8 frames per second. The proposed approach outperforms state-of-the-art methods for needle segmentation while achieving real-time integration. This work is a step forward towards real-time needle guidance using machine learning-based algorithms in handheld ultrasound systems.